aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTschaen, Brendan <ctschaen@att.com>2018-11-01 15:28:02 -0400
committerTschaen, Brendan <ctschaen@att.com>2018-11-01 15:28:35 -0400
commit33f539c97f75232926009312dee888fc09a45bd0 (patch)
tree7ff63af5cc0c4090578d3c612276f11876cb1842
parentc941a0b3edcaee5d3379de87457bbca8a3b3c097 (diff)
Fix property loading in jar
Change-Id: Idbadcf1d1ae6203b97f50b6659a929595cb53b20 Issue-ID: MUSIC-148 Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java10
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java29
2 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index 6b32fc53..d7c5bcec 100644
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ b/src/main/java/org/onap/music/main/MusicCore.java
@@ -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());
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index c11b4c7e..1cfd5fbf 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -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"));
+ }
+
}