aboutsummaryrefslogtreecommitdiffstats
path: root/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
diff options
context:
space:
mode:
authorRyan Goulding <ryandgoulding@gmail.com>2017-08-17 16:15:39 -0400
committerRyan Goulding <ryandgoulding@gmail.com>2017-09-06 09:05:17 -0400
commitaf22e3dbddd5b372e815970ff43cc73e29135218 (patch)
treeb437d5a2853cab8d0682256e518b9c204cf1b7db /dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
parentb6ad62d01b1045ff03c03aa05ee1beeaabc633c7 (diff)
Fix service registration for SDNC
Addresses the inherit race conditions associated with the BundleActivator abstraction. From lessons learned in OpenDaylight project, dependency injection and service injection via Aries Blueprint is faster, more deterministic, and has better error messaging than using BundleActivator(s). This change addresses several aspects: 1) DBLIBResourceActivator is changed to DBLIBResourceProvider. This was done in order to imply that this is no longer an Activator or subclass of an Activator. The class is a POJO. 2) DBLIBResourceProvider is split from a single monolithic method into several more manageable and better documented methods. 3) Documentation surrounding the resolution of the DB properties is added so that a developer can more easily identify the strategy (priority) used for resolving properties. 4) dblib-blueprint.xml is added. This is used to register the configuration bean (DBLIBResourceProvider), and pass it as an argument to the actual Service (DBLIBResourceManager). 5) Tests are added to test the functionality and resolution of the properties file loading. Issue-Id: SDNC-54 Change-Id: Ie9d5fb423ae7a67e9aec026c78321537399cc308 Signed-off-by: Ryan Goulding <ryandgoulding@gmail.com>
Diffstat (limited to 'dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java')
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java83
1 files changed, 41 insertions, 42 deletions
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
index 78b970bf..46c003a5 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
@@ -105,67 +105,72 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
protected final long expectedCompletionTime;
protected final long unprocessedFailoverThreshold;
- public DBResourceManager(Properties props){
- this.configProps = props;
+ public DBResourceManager(final DBLIBResourceProvider configuration) {
+ this(configuration.getProperties());
+ }
+
+ public DBResourceManager(final Properties properties) {
+ this.configProps = properties;
// get retry interval value
- retryInterval = getLongFromProperties(props, "org.onap.dblib.connection.retry", 10000L);
+ retryInterval = getLongFromProperties(properties, "org.onap.dblib.connection.retry", 10000L);
// get recovery mode flag
- recoveryMode = getBooleanFromProperties(props, "org.onap.dblib.connection.recovery", true);
+ recoveryMode = getBooleanFromProperties(properties, "org.onap.dblib.connection.recovery", true);
if(!recoveryMode)
{
recoveryMode = false;
LOGGER.info("Recovery Mode disabled");
}
// get time out value for thread cleanup
- terminationTimeOut = getLongFromProperties(props, "org.onap.dblib.termination.timeout", 300000L);
+ terminationTimeOut = getLongFromProperties(properties, "org.onap.dblib.termination.timeout", 300000L);
// get properties for monitoring
- monitorDbResponse = getBooleanFromProperties(props, "org.onap.dblib.connection.monitor", false);
- monitoringInterval = getLongFromProperties(props, "org.onap.dblib.connection.monitor.interval", 1000L);
- monitoringInitialDelay = getLongFromProperties(props, "org.onap.dblib.connection.monitor.startdelay", 5000L);
- expectedCompletionTime = getLongFromProperties(props, "org.onap.dblib.connection.monitor.expectedcompletiontime", 5000L);
- unprocessedFailoverThreshold = getLongFromProperties(props, "org.onap.dblib.connection.monitor.unprocessedfailoverthreshold", 3L);
+ monitorDbResponse = getBooleanFromProperties(properties, "org.onap.dblib.connection.monitor", false);
+ monitoringInterval = getLongFromProperties(properties, "org.onap.dblib.connection.monitor.interval", 1000L);
+ monitoringInitialDelay = getLongFromProperties(properties, "org.onap.dblib.connection.monitor.startdelay", 5000L);
+ expectedCompletionTime = getLongFromProperties(properties, "org.onap.dblib.connection.monitor.expectedcompletiontime", 5000L);
+ unprocessedFailoverThreshold = getLongFromProperties(properties, "org.onap.dblib.connection.monitor.unprocessedfailoverthreshold", 3L);
// initialize performance monitor
- PollingWorker.createInistance(props);
+ PollingWorker.createInistance(properties);
// initialize recovery thread
worker = new RecoveryMgr();
worker.setName("DBResourcemanagerWatchThread");
worker.setDaemon(true);
worker.start();
+
+ try {
+ this.config(properties);
+ } catch (final Exception e) {
+ // TODO: config throws <code>Exception</code> which is poor practice. Eliminate this in a separate patch.
+ LOGGER.error("Fatal Exception encountered while configuring DBResourceManager", e);
+ }
}
- private void config(Properties ctx) throws Exception {
+ private void config(Properties configProps) throws Exception {
- DbConfigPool dbConfig = DBConfigFactory.createConfig(this.configProps);
+ final DbConfigPool dbConfig = DBConfigFactory.createConfig(configProps);
+ final AbstractResourceManagerFactory factory =
+ AbstractDBResourceManagerFactory.getFactory(dbConfig.getType());
+ LOGGER.info("Default DB config is : {}", dbConfig.getType());
+ LOGGER.info("Using factory : {}", factory.getClass().getName());
- try {
- AbstractResourceManagerFactory factory = AbstractDBResourceManagerFactory.getFactory(dbConfig.getType());
- if(LOGGER.isInfoEnabled()){
- LOGGER.info("Default DB config is : " + dbConfig.getType());
- LOGGER.info("Using factory : " + factory.getClass().getName());
- }
- CachedDataSource[] cachedDS = factory.initDBResourceManager(dbConfig, this);
- if(cachedDS == null || cachedDS.length == 0) {
- LOGGER.error("Initialization of CachedDataSources failed. No instance was created.");
- throw new Exception("Failed to initialize DB Library. No data source was created.");
- }
+ final CachedDataSource[] cachedDS = factory.initDBResourceManager(dbConfig, this);
+ if (cachedDS == null || cachedDS.length == 0) {
+ LOGGER.error("Initialization of CachedDataSources failed. No instance was created.");
+ throw new Exception("Failed to initialize DB Library. No data source was created.");
+ }
- for(int i=0; i<cachedDS.length; i++){
- if(cachedDS[i] != null && cachedDS[i].isInitialized()){
- setDataSource(cachedDS[i]);
- cachedDS[i].setInterval(monitoringInterval);
- cachedDS[i].setInitialDelay(monitoringInitialDelay);
- cachedDS[i].setExpectedCompletionTime(expectedCompletionTime);
- cachedDS[i].setUnprocessedFailoverThreshold(unprocessedFailoverThreshold);
- cachedDS[i].addObserver(this);
- }
+ for (final CachedDataSource ds : cachedDS) {
+ if(ds != null && ds.isInitialized()){
+ setDataSource(ds);
+ ds.setInterval(monitoringInterval);
+ ds.setInitialDelay(monitoringInitialDelay);
+ ds.setExpectedCompletionTime(expectedCompletionTime);
+ ds.setUnprocessedFailoverThreshold(unprocessedFailoverThreshold);
+ ds.addObserver(this);
}
-
- } catch(Exception exc){
- throw exc;
}
}
@@ -664,12 +669,6 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
}
}
- public static DBResourceManager create(Properties props) throws Exception {
- DBResourceManager dbmanager = new DBResourceManager(props);
- dbmanager.config(props);
- return dbmanager;
- }
-
public PrintWriter getLogWriter() throws SQLException {
return ((CachedDataSource)this.dsQueue.peek()).getLogWriter();
}