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=48ae0f39d9d03cc1ec976762e6f7400447ace0a4;hp=86fd5562735405a826c9990a70ce104cdc42ef07;hpb=9fb9f6e4fe8eb9425d848ae576c0e755dfca22df;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 86fd5562..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 @@ -20,120 +20,136 @@ package org.oransc.policyagent.configuration; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.Properties; -import java.util.Vector; 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.Autowired; +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; + + @Value("${server.ssl.key-store-type}") + private String sslKeyStoreType = ""; + + @Value("${server.ssl.key-store-password}") + private String sslKeyStorePassword = ""; + + @Value("${server.ssl.key-store}") + private String sslKeyStore = ""; + + @Value("${server.ssl.key-password}") + private String sslKeyPassword = ""; + + @Value("${app.webclient.trust-store-used}") + private boolean sslTrustStoreUsed = false; + + @Value("${app.webclient.trust-store-password}") + private String sslTrustStorePassword = ""; + + @Value("${app.webclient.trust-store}") + private String sslTrustStore = ""; - private Collection observers = new Vector<>(); private Map ricConfigs = new HashMap<>(); + @Getter - private Properties dmaapPublisherConfig; - @Getter - private Properties dmaapConsumerConfig; + private String dmaapConsumerTopicUrl; - @Autowired - public ApplicationConfig() { - } + @Getter + private String dmaapProducerTopicUrl; - public String getLocalConfigurationFilePath() { - return this.filepath; - } - - /* - * Do not remove, used by framework! - */ - public synchronized void setFilepath(String filepath) { - this.filepath = filepath; - } + private Map controllerConfigs = new HashMap<>(); public synchronized Collection getRicConfigs() { return this.ricConfigs.values(); } - public RicConfig getRic(String ricName) throws ServiceException { - for (RicConfig ricConfig : getRicConfigs()) { - if (ricConfig.name().equals(ricName)) { - return ricConfig; - } - } - throw new ServiceException("Could not find ric: " + ricName); + 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 static enum RicConfigUpdate { - ADDED, CHANGED, REMOVED + 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 interface Observer { - void onRicConfigUpdate(RicConfig ric, RicConfigUpdate event); + 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); + } + return ricConfig; } - public void addObserver(Observer o) { - this.observers.add(o); - } + public static class RicConfigUpdate { + public enum Type { + ADDED, CHANGED, REMOVED + } - private class Notification { - final RicConfig ric; - final RicConfigUpdate event; + @Getter + private final RicConfig ricConfig; + @Getter + private final Type type; - Notification(RicConfig ric, RicConfigUpdate event) { - this.ric = ric; - this.event = event; + RicConfigUpdate(RicConfig ric, Type event) { + this.ricConfig = ric; + this.type = event; } } - public void setConfiguration(@NotNull Collection ricConfigs, Properties dmaapPublisherConfig, - Properties dmaapConsumerConfig) { - Collection notifications = new Vector<>(); - synchronized (this) { - Map newRicConfigs = new HashMap<>(); - for (RicConfig newConfig : ricConfigs) { - RicConfig oldConfig = this.ricConfigs.get(newConfig.name()); - if (oldConfig == null) { - newRicConfigs.put(newConfig.name(), newConfig); - notifications.add(new Notification(newConfig, RicConfigUpdate.ADDED)); - this.ricConfigs.remove(newConfig.name()); - } else if (!newConfig.equals(newConfig)) { - notifications.add(new Notification(newConfig, RicConfigUpdate.CHANGED)); - newRicConfigs.put(newConfig.name(), newConfig); - this.ricConfigs.remove(newConfig.name()); - } else { - newRicConfigs.put(oldConfig.name(), oldConfig); - } + public synchronized Flux setConfiguration( + ApplicationConfigParser.ConfigParserResult parserResult) { + + Collection modifications = new ArrayList<>(); + this.controllerConfigs = parserResult.controllerConfigs(); + + this.dmaapConsumerTopicUrl = parserResult.dmaapConsumerTopicUrl(); + this.dmaapProducerTopicUrl = parserResult.dmaapProducerTopicUrl(); + + Map newRicConfigs = new HashMap<>(); + 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)); + } else if (!newConfig.equals(oldConfig)) { + modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED)); + newRicConfigs.put(newConfig.name(), newConfig); + } else { + newRicConfigs.put(oldConfig.name(), oldConfig); } - for (RicConfig deletedConfig : this.ricConfigs.values()) { - notifications.add(new Notification(deletedConfig, RicConfigUpdate.REMOVED)); - } - this.ricConfigs = newRicConfigs; } - notifyObservers(notifications); - - this.dmaapPublisherConfig = dmaapPublisherConfig; - this.dmaapConsumerConfig = dmaapConsumerConfig; - } - - private void notifyObservers(Collection notifications) { - for (Observer observer : this.observers) { - for (Notification notif : notifications) { - observer.onRicConfigUpdate(notif.ric, notif.event); - } + for (RicConfig deletedConfig : this.ricConfigs.values()) { + modifications.add(new RicConfigUpdate(deletedConfig, RicConfigUpdate.Type.REMOVED)); } + this.ricConfigs = newRicConfigs; + + return Flux.fromIterable(modifications); } }