Use dblib.properties for dblib service 49/20549/1
authorDan Timoney <dtimoney@att.com>
Wed, 25 Oct 2017 13:04:40 +0000 (09:04 -0400)
committerDan Timoney <dtimoney@att.com>
Wed, 25 Oct 2017 13:04:40 +0000 (09:04 -0400)
If dblib service cannot be resolved via OSGi, the fallback logic
that creates a new instance of DBResourceManager should
pass the contents of /opt/sdnc/data/properties/dblib.properties
as properties to the DBResourceManager constructor instead
of just passing System.getProperties().

Change-Id: Ia6ac8a4bb229026cabdf07463ca25619f923e3f3
Issue-ID: CCSDK-126
Signed-off-by: Dan Timoney <dtimoney@att.com>
sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java

index 45e5ad2..b2b77b5 100644 (file)
@@ -21,6 +21,8 @@
 
 package org.onap.ccsdk.sli.adaptors.resource.sql;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -29,6 +31,7 @@ import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Properties;
 
 import javax.sql.rowset.CachedRowSet;
 
@@ -349,8 +352,31 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
                        // Must not be running in an OSGI container. See if you can load it
                        // as a
                        // a POJO then.
+
+                       // If $SDNC_CONFIG_DIR/dblib.properties exists, that should
+                       // be the properties passed to DBResourceManager constructor.
+                       // If not, as default just use system properties.
+                       Properties dblibProps = System.getProperties();
+                       String cfgDir = System.getenv("SDNC_CONFIG_DIR");
+
+                       if ((cfgDir == null) || (cfgDir.length() == 0)) {
+                               cfgDir = "/opt/sdnc/data/properties";
+                       }
+
+                       File dblibPropFile = new File(cfgDir + "/dblib.properties");
+                       if (dblibPropFile.exists()) {
+                               try {
+                                       dblibProps = new Properties();
+                                       dblibProps.load(new FileInputStream(dblibPropFile));
+                               } catch (Exception e) {
+                                       LOG.warn("Could not load properties file " + dblibPropFile.getAbsolutePath(), e);
+
+                                       dblibProps = System.getProperties();
+                               }
+                       }
+
                        try {
-                               dblibSvc = new DBResourceManager(System.getProperties());
+                               dblibSvc = new DBResourceManager(dblibProps);
                        } catch (Exception e) {
                                LOG.error("Caught exception trying to create dblib service", e);
                        }