Enhancements for the aai-common library
[aai/aai-common.git] / aai-els-onap-logging / src / main / java / org / onap / aai / util / AAIConfig.java
 
 package org.onap.aai.util;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
+import org.eclipse.jetty.util.security.Password;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.logging.ErrorLogHelper;
 
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetAddress;
 import java.util.Properties;
-import java.util.UUID;
-
-import org.eclipse.jetty.util.security.Password;
-import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.logging.ErrorLogHelper;
-import org.onap.aai.logging.LoggingContext;
-import org.onap.aai.logging.LoggingContext.StatusCode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class AAIConfig {
 
-    private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIConfig.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(AAIConfig.class);
     private static final String GLOBAL_PROP_FILE_NAME = AAIConstants.AAI_CONFIG_FILENAME;
     private static Properties serverProps;
     private static boolean propsInitialized = false;
@@ -58,15 +53,6 @@ public class AAIConfig {
      */
     public synchronized static void init() throws AAIException {
 
-        LoggingContext.save();
-        LoggingContext.component("config");
-        LoggingContext.partnerName("NA");
-        LoggingContext.targetEntity("AAI");
-        LoggingContext.requestId(UUID.randomUUID().toString());
-        LoggingContext.serviceName("AAI");
-        LoggingContext.targetServiceName("init");
-        LoggingContext.statusCode(StatusCode.COMPLETE);
-
         LOGGER.info("Initializing AAIConfig");
 
         AAIConfig.getConfigFile();
@@ -77,7 +63,6 @@ public class AAIConfig {
         } else {
             LOGGER.info("A&AI Server Node Name = " + AAIConstants.AAI_NODENAME);
         }
-        LoggingContext.restore();
     }
 
     /**
@@ -95,19 +80,28 @@ public class AAIConfig {
     public synchronized static void reloadConfig() {
 
         String propFileName = GLOBAL_PROP_FILE_NAME;
-        Properties newServerProps = null;
+        Properties newServerProps = new Properties();
 
         LOGGER.debug("Reloading config from " + propFileName);
 
         try (InputStream is = new FileInputStream(propFileName)) {
-            newServerProps = new Properties();
+            LOGGER.info("Found the aaiconfig.properties in the following location: {}", GLOBAL_PROP_FILE_NAME);
             newServerProps.load(is);
             propsInitialized = true;
             serverProps = newServerProps;
-        } catch (FileNotFoundException fnfe) {
-            ErrorLogHelper.logError("AAI_4001", " " + propFileName + ". Exception: " + fnfe.getMessage());
-        } catch (IOException e) {
-            ErrorLogHelper.logError("AAI_4002", " " + propFileName + ". IOException: " + e.getMessage());
+        } catch (Exception fnfe) {
+            final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("aaiconfig.properties");
+            LOGGER.info("Unable to find the aaiconfig.properties from filesystem so using file in jar");
+            if (is != null) {
+                try {
+                    newServerProps.load(is);
+                    serverProps = newServerProps;
+                } catch (IOException e) {
+                    LOGGER.warn("Encountered IO Exception during loading of aaiconfig props from inputstream", e);
+                }
+            } else {
+                LOGGER.error("Expected to find the error.properties in the jar but unable to find it");
+            }
         }
     }