Expand env variables in frankfurt properties 98/104498/2
authorJim Hahn <jrh3@att.com>
Thu, 26 Mar 2020 13:53:53 +0000 (09:53 -0400)
committerJim Hahn <jrh3@att.com>
Thu, 26 Mar 2020 14:20:33 +0000 (10:20 -0400)
Issue-ID: POLICY-2434
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I1109a053e46dc8201ff9676da0c9ff93d8b631d5
Signed-off-by: Jim Hahn <jrh3@att.com>
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/EventManagerServices.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java

index 69cbe78..05563ca 100644 (file)
@@ -75,7 +75,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
     private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager2.class);
     private static final long serialVersionUID = -1216568161322872641L;
 
-    private static final String EVENT_MANAGER_SERVICE_CONFIG = "config/event-manager.properties";
+    private static final String EVENT_MANAGER_SERVICE_CONFIG = "event-manager";
     public static final String PROV_STATUS_ACTIVE = "ACTIVE";
     private static final String VM_NAME = "VM_NAME";
     private static final String VNF_NAME = "VNF_NAME";
index 3fbedcb..8ce3cb1 100644 (file)
 
 package org.onap.policy.controlloop.eventmanager;
 
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.Map;
 import java.util.Properties;
 import lombok.Getter;
 import org.onap.policy.common.parameters.ValidationResult;
 import org.onap.policy.common.utils.properties.PropertyObjectUtils;
-import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.controlloop.actor.guard.GuardActorServiceProvider;
 import org.onap.policy.controlloop.actor.guard.GuardConfig;
 import org.onap.policy.controlloop.actor.guard.GuardOperation;
@@ -39,6 +35,7 @@ import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
 import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerImpl;
 import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerParams;
 import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerStub;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -82,9 +79,8 @@ public class EventManagerServices {
      * @return the properties that were loaded from the configuration file
      */
     public Properties startActorService(String configFileName) {
-        try (InputStream inpstr = openConfigFile(configFileName)) {
-            Properties props = new Properties();
-            props.load(inpstr);
+        try {
+            Properties props = SystemPersistenceConstants.getManager().getProperties(configFileName);
 
             Map<String, Object> parameters = PropertyObjectUtils.toObject(props, ACTOR_SERVICE_PROPERTIES);
             PropertyObjectUtils.compressLists(parameters);
@@ -94,28 +90,12 @@ public class EventManagerServices {
 
             return props;
 
-        } catch (RuntimeException | IOException e) {
+        } catch (RuntimeException e) {
             logger.error("cannot configure/start actor service");
             throw new IllegalStateException(e);
         }
     }
 
-    /**
-     * Opens the config file.
-     *
-     * @param configFileName configuration file name
-     * @return the file's input stream
-     * @throws FileNotFoundException if the file cannot be found
-     */
-    private InputStream openConfigFile(String configFileName) throws FileNotFoundException {
-        InputStream inpstr = ResourceUtils.getResourceAsStream(configFileName);
-        if (inpstr == null) {
-            throw new FileNotFoundException(configFileName);
-        }
-
-        return inpstr;
-    }
-
     /**
      * Determines if guards are enabled.
      *
index b32fb44..ea3fff3 100644 (file)
@@ -37,7 +37,7 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.controlloop.actorserviceprovider.ActorService;
 import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerImpl;
 import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerStub;
-import org.onap.policy.drools.utils.PropertyUtil;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
 
 public class EventManagerServicesTest {
     private static final String FILEPFX = "eventService/";
@@ -54,8 +54,9 @@ public class EventManagerServicesTest {
         // start with a clean slate
         HttpClientFactoryInstance.getClientFactory().destroy();
 
-        Properties props =
-                        PropertyUtil.getProperties("src/test/resources/eventService/event-svc-http-client.properties");
+        SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources");
+
+        Properties props = SystemPersistenceConstants.getManager().getProperties("eventService/event-svc-http-client");
         HttpClientFactoryInstance.getClientFactory().build(props);
     }
 
@@ -72,12 +73,12 @@ public class EventManagerServicesTest {
     @Test
     public void testEventManagerServices_testGetActorService() {
         // try with guard disabled - should use DB stub
-        services = new EventManagerServices(FILEPFX + "event-svc-guard-disabled.properties");
+        services = new EventManagerServices(FILEPFX + "event-svc-guard-disabled");
         assertTrue(services.getDataManager() instanceof OperationHistoryDataManagerStub);
         assertNotNull(services.getActorService());
 
         // try with guard enabled - should create a DB connection
-        services = new EventManagerServices(FILEPFX + "event-svc-with-db.properties");
+        services = new EventManagerServices(FILEPFX + "event-svc-with-db");
         assertTrue(services.getDataManager() instanceof OperationHistoryDataManagerImpl);
         assertNotNull(services.getActorService());
     }
@@ -91,11 +92,11 @@ public class EventManagerServicesTest {
     @Test
     public void testIsGuardEnabled() {
         // cannot check guard
-        services = new EventManagerServices(FILEPFX + "event-svc-no-guard-actor.properties");
+        services = new EventManagerServices(FILEPFX + "event-svc-no-guard-actor");
         assertTrue(services.getDataManager() instanceof OperationHistoryDataManagerStub);
 
         // force exception when checking for guard operator
-        services = new EventManagerServices(FILEPFX + "event-svc-with-db.properties") {
+        services = new EventManagerServices(FILEPFX + "event-svc-with-db") {
             @Override
             public ActorService getActorService() {
                 ActorService svc = mock(ActorService.class);
@@ -108,7 +109,7 @@ public class EventManagerServicesTest {
 
     @Test
     public void testMakeDataManager() {
-        assertThatThrownBy(() -> new EventManagerServices(FILEPFX + "event-svc-invalid-db.properties"));
+        assertThatThrownBy(() -> new EventManagerServices(FILEPFX + "event-svc-invalid-db"));
     }