Some bug fixes and Minor Chages.
[music.git] / jar / src / main / java / org / onap / music / main / MusicUtil.java
index f18570d..4acc3c5 100755 (executable)
@@ -19,6 +19,7 @@
  * ============LICENSE_END=============================================
  * ====================================================================
  */
+
 package org.onap.music.main;
 
 import java.io.File;
@@ -81,8 +82,9 @@ public class MusicUtil {
             "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url" };
 
     private static String cassName = "cassandra";
-    private static String cassPwd = "cassandra";
+    private static String cassPwd = "";
     private static String aafEndpointUrl = null;
+    private static int cassandraPort = 9042;
 
     private MusicUtil() {
         throw new IllegalStateException("Utility Class");
@@ -340,6 +342,21 @@ public class MusicUtil {
         MusicUtil.defaultMusicIp = defaultMusicIp;
     }
 
+    /**
+    *
+    * @return cassandra port
+    */
+   public static int getCassandraPort() {
+       return cassandraPort;
+   }
+
+   /**
+    * set cassandra port
+    * @param cassandraPort
+    */
+   public static void setCassandraPort(int cassandraPort) {
+       MusicUtil.cassandraPort = cassandraPort;
+   }
     /**
      * 
      * @return
@@ -531,30 +548,43 @@ 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();
-                   }
-               }
-           }
-           // get the property value and return it
-               MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
-               String zkHosts = prop.getProperty("zookeeper.host");
-               MusicUtil.setMyZkHost(zkHosts);
-               MusicUtil.setCassName(prop.getProperty("cassandra.user"));
-               MusicUtil.setCassPwd(prop.getProperty("cassandra.password"));
-       }
+        CipherUtil.readAndSetKeyString();
+        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();
+                }
+            }
+        }
+        String cassPwd = prop.getProperty("cassandra.password");
+        String isEncrypted = prop.getProperty("cassandra.password.isencrypted");
+        if("true".equals(isEncrypted)) {
+            logger.debug(EELFLoggerDelegate.applicationLogger,"Decrypting....");
+            cassPwd = CipherUtil.decryptPKC(cassPwd);
+            logger.debug(EELFLoggerDelegate.applicationLogger,"Password Decrypted");
+            MusicUtil.setCassPwd(cassPwd);
+        } else
+            MusicUtil.setCassPwd(cassPwd);
+        // get the property value and return it
+            MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
+            String zkHosts = prop.getProperty("zookeeper.host");
+            MusicUtil.setMyZkHost(zkHosts);
+            MusicUtil.setCassName(prop.getProperty("cassandra.user"));
+        String cassPort = prop.getProperty("cassandra.port");
+        if(cassPort != null) 
+            MusicUtil.setCassandraPort(Integer.parseInt(cassPort));
+    }
+
     
 }