summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-07-30 13:44:53 -0400
committerDan Timoney <dtimoney@att.com>2020-07-30 13:44:53 -0400
commit3960d5fe8a04c505334714516c3144c327bb98c1 (patch)
tree57ace5e7233bcf11a0cdf18e77fb5a6fc4698386
parent7b790e614732183db8be972a168a60d564a86d60 (diff)
Add error handling for OSGi classes not found
Added error handling to correctly handle case where SqlResource is used outside an OSGi container. Change-Id: I0b5a526b01c151c4a7924f474bf7d21e783ac260 Issue-ID: CCSDK-2625 Signed-off-by: Dan Timoney <dtimoney@att.com>
-rwxr-xr-x.gitignore1
-rwxr-xr-xsql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java48
2 files changed, 30 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 34a96c15..cc576b7b 100755
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@ org.eclipse.core.resources.prefs
maven-eclipse.xml
workspace
.checkstyle
+.vscode
## Compilation Files ##
*.class
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 69965d10..435bc5bb 100755
--- 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
@@ -355,28 +355,36 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
return(dblibSvc);
}
// Try to get dblib as an OSGI service
- BundleContext bctx = null;
- ServiceReference sref = null;
- Bundle bundle = FrameworkUtil.getBundle(SqlResource.class);
-
- if (bundle != null) {
- bctx = bundle.getBundleContext();
- }
-
- if (bctx != null) {
- sref = bctx.getServiceReference(DBLIB_SERVICE);
- }
-
- if (sref == null) {
- LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
- } else {
- dblibSvc = (DbLibService) bctx.getService(sref);
- if (dblibSvc == null) {
+ try {
+ BundleContext bctx = null;
+ ServiceReference sref = null;
+
+
+
+ Bundle bundle = FrameworkUtil.getBundle(SqlResource.class);
+
+ if (bundle != null) {
+ bctx = bundle.getBundleContext();
+ }
+
+ if (bctx != null) {
+ sref = bctx.getServiceReference(DBLIB_SERVICE);
+ }
+
+ if (sref == null) {
LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
+ } else {
+ dblibSvc = (DbLibService) bctx.getService(sref);
+ if (dblibSvc == null) {
+ LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
+ }
}
+ } catch (NoClassDefFoundError ex) {
+ LOG.info("OSGI classes not found - must be running outside an OSGi container");
}
+
if (dblibSvc == null) {
// Must not be running in an OSGI container. See if you can load it
// as a
@@ -386,7 +394,8 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
// 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");
+
+ String cfgDir = dblibProps.getProperty("sdnc.config.dir", System.getenv("SDNC_CONFIG_DIR"));
if ((cfgDir == null) || (cfgDir.length() == 0)) {
cfgDir = "/opt/sdnc/data/properties";
@@ -395,10 +404,11 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
File dblibPropFile = new File(cfgDir + "/dblib.properties");
if (dblibPropFile.exists()) {
try {
+ LOG.debug("Loading dblib properties from {}", dblibPropFile.getAbsolutePath());
dblibProps = new Properties();
dblibProps.load(new FileInputStream(dblibPropFile));
} catch (Exception e) {
- LOG.warn("Could not load properties file " + dblibPropFile.getAbsolutePath(), e);
+ LOG.warn("Could not load properties file {}", dblibPropFile.getAbsolutePath(), e);
dblibProps = System.getProperties();
}