From 19c5fcb7461d0e35896829daef13bfb9290bc4af Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Wed, 25 Oct 2017 09:04:40 -0400 Subject: Use dblib.properties for dblib service 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 --- .../sli/adaptors/resource/sql/SqlResource.java | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java index 45e5ad2b..b2b77b57 100644 --- a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java +++ b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java @@ -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); } -- cgit 1.2.3-korg