summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-10-20 16:26:49 -0400
committerDan Timoney <dtimoney@att.com>2020-10-20 16:26:49 -0400
commit7e33b0ae33ba2c994daae949450386ca30ea7793 (patch)
tree91524e84411e8f85cff07de42b1868419d1d9aae
parent684ff7064739851f66483df77d6578966ee4b6a3 (diff)
Support netbox-client outside OSGi container
Updated netbox-client initialization so that it works properly when initialized outside an OSGi container (e.g springboot) Change-Id: I4a6cb477206745eb4ca21f10a7fb54cc616ef4cd Issue-ID: CCSDK-2923 Signed-off-by: Dan Timoney <dtimoney@att.com>
-rw-r--r--netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImpl.java58
-rw-r--r--netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java14
2 files changed, 63 insertions, 9 deletions
diff --git a/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImpl.java b/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImpl.java
index 4e4761d10..bfb5ee530 100644
--- a/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImpl.java
+++ b/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImpl.java
@@ -17,16 +17,23 @@ package org.onap.ccsdk.sli.adaptors.netbox.impl;
import com.google.common.collect.Lists;
import com.google.gson.JsonSyntaxException;
+
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
+import java.util.Properties;
+
import javax.sql.rowset.CachedRowSet;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.onap.ccsdk.sli.adaptors.netbox.api.NetboxClient;
import org.onap.ccsdk.sli.adaptors.netbox.model.IPAddress;
import org.onap.ccsdk.sli.adaptors.netbox.model.IPStatus;
+import org.onap.ccsdk.sli.adaptors.netbox.property.NetboxProperties;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.onap.ccsdk.sli.core.dblib.DbLibService;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
@@ -73,9 +80,56 @@ public class NetboxClientImpl implements NetboxClient {
private final NetboxHttpClient client;
private final DbLibService dbLibService;
+ public NetboxClientImpl() {
+ this(null, null);
+ }
+
public NetboxClientImpl(final NetboxHttpClient client, final DbLibService dbLibService) {
- this.client = client;
- this.dbLibService = dbLibService;
+ if (client == null) {
+ this.client = new NetboxHttpClient(new NetboxProperties());
+ } else {
+ this.client = client;
+ }
+
+ if (dbLibService == null) {
+ Properties dblibProps = System.getProperties();
+
+ String cfgDir = dblibProps.getProperty("sdnc.config.dir", 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 {
+ 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);
+
+ dblibProps = System.getProperties();
+ }
+ }
+
+ DbLibService dbSvc = null;
+ try {
+ dbSvc = new DBResourceManager(dblibProps);
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to create dblib service", e);
+ }
+
+ try {
+ dbSvc = new DBResourceManager(dblibProps);
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to create dblib service", e);
+ }
+ this.dbLibService = dbSvc;
+
+ } else {
+ this.dbLibService = dbLibService;
+ }
}
@Override
diff --git a/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java b/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java
index 2eecf6e3a..065b07551 100644
--- a/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java
+++ b/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java
@@ -60,15 +60,15 @@ public class NetboxProperties {
properties.load(in);
LOG.info("Loaded {} properties from file {}", properties.size(), ccsdkConfigDir);
} catch (Exception e) {
- // Try to load config from jar
- final Bundle bundle = FrameworkUtil.getBundle(NetboxProperties.class);
- final BundleContext ctx = bundle.getBundleContext();
- final URL url = ctx.getBundle().getResource(NETBOX_PROPERTY_FILE_NAME);
-
- try (InputStream inputStream = url.openStream()) {
+ try {
+ // Try to load config from jar
+ final Bundle bundle = FrameworkUtil.getBundle(NetboxProperties.class);
+ final BundleContext ctx = bundle.getBundleContext();
+ final URL url = ctx.getBundle().getResource(NETBOX_PROPERTY_FILE_NAME);
+ InputStream inputStream = url.openStream();
properties.load(inputStream);
LOG.info("Loaded {} properties from file {}", properties.size(), NETBOX_PROPERTY_FILE_NAME);
- } catch (IOException e1) {
+ } catch (IOException|NoClassDefFoundError e1) {
LOG.error("Failed to load properties for file: {} " + NETBOX_PROPERTY_FILE_NAME, e1);
}
}