Fix property loading in jar 77/71677/1
authorTschaen, Brendan <ctschaen@att.com>
Thu, 1 Nov 2018 19:28:02 +0000 (15:28 -0400)
committerTschaen, Brendan <ctschaen@att.com>
Thu, 1 Nov 2018 19:28:35 +0000 (15:28 -0400)
Change-Id: Idbadcf1d1ae6203b97f50b6659a929595cb53b20
Issue-ID: MUSIC-148
Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
src/main/java/org/onap/music/main/MusicCore.java
src/main/java/org/onap/music/main/MusicUtil.java

index 6b32fc5..d7c5bce 100644 (file)
@@ -105,6 +105,11 @@ public class MusicCore {
         logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
         long start = System.currentTimeMillis();
         if (mDstoreHandle == null) {
+               try {
+                       MusicUtil.loadProperties();
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "No properties file defined. Falling back to default.");
+               }
             mDstoreHandle = new CassaDataStore(remoteIp);
         }
         long end = System.currentTimeMillis();
@@ -122,6 +127,11 @@ public class MusicCore {
         logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
         long start = System.currentTimeMillis();
         if (mDstoreHandle == null) {
+               try {
+                       MusicUtil.loadProperties();
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "No properties file defined. Falling back to default.");
+               }
             // Quick Fix - Best to put this into every call to getDSHandle?
             if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
                 mDstoreHandle = new CassaDataStore(MusicUtil.getMyCassaHost());
index c11b4c7..1cfd5fb 100755 (executable)
@@ -23,12 +23,15 @@ package org.onap.music.main;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Scanner;
 import java.util.StringTokenizer;
 import java.util.UUID;
@@ -334,6 +337,7 @@ public class MusicUtil {
      * @param myCassaHost
      */
     public static void setMyCassaHost(String myCassaHost) {
+       System.out.println("Setting my cassa host: " + myCassaHost);
         MusicUtil.myCassaHost = myCassaHost;
     }
 
@@ -567,4 +571,29 @@ public class MusicUtil {
        
     }
 
+
+               public static void loadProperties() throws Exception {
+               Properties prop = new Properties();
+                   InputStream input = null;
+                   try {
+                       // load the properties file
+                       input = MusicUtil.class.getClassLoader().getResourceAsStream("music.properties");
+                       prop.load(input);
+                   } catch (Exception ex) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "Unable to find properties file.");
+                       throw new Exception();
+                   } finally {
+                       if (input != null) {
+                           try {
+                               input.close();
+                           } catch (IOException e) {
+                               e.printStackTrace();
+                           }
+                       }
+                   }
+                   MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
+                   MusicUtil.setCassName(prop.getProperty("cassandra.user"));          
+                   MusicUtil.setCassPwd(prop.getProperty("cassandra.password"));
+       }
+
 }