Fixed concurrency problems
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / configuration / ApplicationConfig.java
index 1ed3fdb..deacb44 100644 (file)
 
 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.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 
@@ -40,19 +41,38 @@ public class ApplicationConfig {
     @NotEmpty
     private String filepath;
 
-    private Collection<Observer> observers = new Vector<>();
+    @NotEmpty
+    private String a1ControllerBaseUrl;
+
+    @NotEmpty
+    private String a1ControllerUsername;
+
+    @NotEmpty
+    private String a1ControllerPassword;
+
+    private Collection<Observer> observers = new ArrayList<>();
     private Map<String, RicConfig> ricConfigs = new HashMap<>();
+    @Getter
     private Properties dmaapPublisherConfig;
+    @Getter
     private Properties dmaapConsumerConfig;
 
-    @Autowired
-    public ApplicationConfig() {
-    }
-
     public String getLocalConfigurationFilePath() {
         return this.filepath;
     }
 
+    public String getA1ControllerBaseUrl() {
+        return this.a1ControllerBaseUrl;
+    }
+
+    public String getA1ControllerUsername() {
+        return this.a1ControllerUsername;
+    }
+
+    public String getA1ControllerPassword() {
+        return this.a1ControllerPassword;
+    }
+
     /*
      * Do not remove, used by framework!
      */
@@ -60,6 +80,18 @@ public class ApplicationConfig {
         this.filepath = filepath;
     }
 
+    public synchronized void setA1ControllerBaseUrl(String a1ControllerBaseUrl) {
+        this.a1ControllerBaseUrl = a1ControllerBaseUrl;
+    }
+
+    public synchronized void setA1ControllerUsername(String a1ControllerUsername) {
+        this.a1ControllerUsername = a1ControllerUsername;
+    }
+
+    public synchronized void setA1ControllerPassword(String a1ControllerPassword) {
+        this.a1ControllerPassword = a1ControllerPassword;
+    }
+
     public synchronized Collection<RicConfig> getRicConfigs() {
         return this.ricConfigs.values();
     }
@@ -73,15 +105,7 @@ public class ApplicationConfig {
         throw new ServiceException("Could not find ric: " + ricName);
     }
 
-    public Properties getDmaapPublisherConfig() {
-        return dmaapConsumerConfig;
-    }
-
-    public Properties getDmaapConsumerConfig() {
-        return dmaapConsumerConfig;
-    }
-
-    public static enum RicConfigUpdate {
+    public enum RicConfigUpdate {
         ADDED, CHANGED, REMOVED
     }
 
@@ -105,8 +129,12 @@ public class ApplicationConfig {
 
     public void setConfiguration(@NotNull Collection<RicConfig> ricConfigs, Properties dmaapPublisherConfig,
         Properties dmaapConsumerConfig) {
-        Collection<Notification> notifications = new Vector<>();
+
+        Collection<Notification> notifications = new ArrayList<>();
         synchronized (this) {
+            this.dmaapPublisherConfig = dmaapPublisherConfig;
+            this.dmaapConsumerConfig = dmaapConsumerConfig;
+
             Map<String, RicConfig> newRicConfigs = new HashMap<>();
             for (RicConfig newConfig : ricConfigs) {
                 RicConfig oldConfig = this.ricConfigs.get(newConfig.name());
@@ -114,7 +142,7 @@ public class ApplicationConfig {
                     newRicConfigs.put(newConfig.name(), newConfig);
                     notifications.add(new Notification(newConfig, RicConfigUpdate.ADDED));
                     this.ricConfigs.remove(newConfig.name());
-                } else if (!newConfig.equals(newConfig)) {
+                } else if (!newConfig.equals(oldConfig)) {
                     notifications.add(new Notification(newConfig, RicConfigUpdate.CHANGED));
                     newRicConfigs.put(newConfig.name(), newConfig);
                     this.ricConfigs.remove(newConfig.name());
@@ -127,10 +155,8 @@ public class ApplicationConfig {
             }
             this.ricConfigs = newRicConfigs;
         }
-        notifyObservers(notifications);
 
-        this.dmaapPublisherConfig = dmaapPublisherConfig;
-        this.dmaapConsumerConfig = dmaapConsumerConfig;
+        notifyObservers(notifications);
     }
 
     private void notifyObservers(Collection<Notification> notifications) {