aboutsummaryrefslogtreecommitdiffstats
path: root/dblib
diff options
context:
space:
mode:
Diffstat (limited to 'dblib')
-rwxr-xr-x[-rw-r--r--]dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java5
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java10
-rwxr-xr-x[-rw-r--r--]dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java195
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java2
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java4
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java6
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java34
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java10
-rwxr-xr-x[-rw-r--r--]dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java301
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractDBResourceManagerFactory.java39
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractResourceManagerFactory.java103
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/FactoryNotDefinedException.java37
-rwxr-xr-x[-rw-r--r--]dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java46
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDbResourceManagerFactory.java183
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java18
-rw-r--r--dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java (renamed from dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java)0
-rw-r--r--dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java (renamed from dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java)0
-rw-r--r--dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java (renamed from dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java)0
-rw-r--r--dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java (renamed from dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java)0
19 files changed, 421 insertions, 572 deletions
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
index ee8ab2f3..a5902d54 100644..100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
@@ -20,7 +20,6 @@
package org.onap.ccsdk.sli.core.dblib;
-import com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException;
import org.apache.tomcat.jdbc.pool.PoolExhaustedException;
import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration;
import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitor;
@@ -535,7 +534,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
return monitor;
}
- protected boolean isSlave() throws PoolExhaustedException, MySQLNonTransientConnectionException {
+ protected boolean isSlave() throws PoolExhaustedException {
CachedRowSet rs = null;
boolean isSlave = true;
String hostname = "UNDETERMINED";
@@ -547,7 +546,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
hostname = rs.getString(2);
}
isSlave = localSlave;
- } catch(PoolExhaustedException | MySQLNonTransientConnectionException peexc){
+ } catch(PoolExhaustedException peexc){
throw peexc;
} catch (SQLException e) {
LOGGER.error("", e);
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java
index ccef4819..40d1a238 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java
@@ -64,7 +64,8 @@ public class DBLibConnection implements Connection {
public boolean lockTable(String tablename) {
this.tableName = tablename;
- return locked = dataSource.lockTable(connection, tableName);
+ locked = dataSource.lockTable(connection, tableName);
+ return locked;
}
public void resetInactivityTimer() {
@@ -79,12 +80,13 @@ public class DBLibConnection implements Connection {
public boolean unlock() {
dataSource.unlockTable(connection);
- return locked = false;
+ locked = false;
+ return locked;
}
public boolean writeData(String statement, ArrayList<String> arguments) throws SQLException, Throwable
{
- ArrayList<Object> newList=new ArrayList<Object>();
+ ArrayList<Object> newList= new ArrayList<>();
if(arguments != null && !arguments.isEmpty()) {
newList.addAll(arguments);
}
@@ -94,7 +96,7 @@ public class DBLibConnection implements Connection {
public CachedRowSet getData(String statement, ArrayList<String> arguments) throws SQLException, Throwable
{
- ArrayList<Object> newList=new ArrayList<Object>();
+ ArrayList<Object> newList= new ArrayList<>();
if(arguments != null && !arguments.isEmpty()) {
newList.addAll(arguments);
}
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 8e8bdb8a..a2eb0f9c 100644..100755
--- 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,6 +20,16 @@
package org.onap.ccsdk.sli.core.dblib;
+import org.apache.tomcat.jdbc.pool.PoolExhaustedException;
+import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
+import org.onap.ccsdk.sli.core.dblib.factory.DBConfigFactory;
+import org.onap.ccsdk.sli.core.dblib.pm.PollingWorker;
+import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import javax.sql.rowset.CachedRowSet;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLDataException;
@@ -39,6 +49,7 @@ import java.util.Properties;
import java.util.Queue;
import java.util.Set;
import java.util.TimerTask;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.sql.DataSource;
@@ -46,17 +57,14 @@ import javax.sql.rowset.CachedRowSet;
import org.apache.tomcat.jdbc.pool.PoolExhaustedException;
import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
-import org.onap.ccsdk.sli.core.dblib.factory.AbstractDBResourceManagerFactory;
-import org.onap.ccsdk.sli.core.dblib.factory.AbstractResourceManagerFactory;
+import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration;
import org.onap.ccsdk.sli.core.dblib.factory.DBConfigFactory;
import org.onap.ccsdk.sli.core.dblib.pm.PollingWorker;
import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitor;
-import com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* @version $Revision: 1.15 $
* Change Log
@@ -74,23 +82,29 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
protected final AtomicBoolean dsSelector = new AtomicBoolean();
// Queue<CachedDataSource> dsQueue = new ConcurrentLinkedQueue<CachedDataSource>();
- Queue<CachedDataSource> dsQueue = new PriorityQueue<CachedDataSource>(4, new Comparator<CachedDataSource>(){
-
+ Queue<CachedDataSource> dsQueue = new PriorityQueue<CachedDataSource>(4, new Comparator<CachedDataSource>() {
@Override
public int compare(CachedDataSource left, CachedDataSource right) {
try {
- if(!left.isSlave())
- return -1;
- if(!right.isSlave())
+ if(left == null){
return 1;
+ }
+ if(right == null){
+ return -1;
+ }
+ if(!left.isSlave()) {
+ return -1;
+ }
+ if (!right.isSlave()) {
+ return 1;
+ }
} catch (Throwable e) {
LOGGER.warn("", e);
}
return 0;
}
-
- });
+ });
protected final Set<CachedDataSource> broken = Collections.synchronizedSet(new HashSet<CachedDataSource>());
protected final Object monitor = new Object();
protected final Properties configProps;
@@ -147,31 +161,108 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
}
private void config(Properties configProps) throws Exception {
-
+ final ConcurrentLinkedQueue<CachedDataSource> semaphore = new ConcurrentLinkedQueue<CachedDataSource>();
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());
- 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.");
+ long startTime = System.currentTimeMillis();
+
+ try {
+ JDBCConfiguration[] config = dbConfig.getJDBCbSourceArray();
+ CachedDataSource[] cachedDS = new CachedDataSource[config.length];
+ 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 < config.length; i++) {
+ cachedDS[i] = CachedDataSourceFactory.createDataSource(config[i]);
+ if(cachedDS[i] == null)
+ continue;
+ semaphore.add(cachedDS[i]);
+ cachedDS[i].setInterval(monitoringInterval);
+ cachedDS[i].setInitialDelay(monitoringInitialDelay);
+ cachedDS[i].setExpectedCompletionTime(expectedCompletionTime);
+ cachedDS[i].setUnprocessedFailoverThreshold(unprocessedFailoverThreshold);
+ cachedDS[i].addObserver(DBResourceManager.this);
+ }
+
+// CachedDataSource[] cachedDS = factory.initDBResourceManager(dbConfig, DBResourceManager.this, semaphore);
+ DataSourceTester[] tester = new DataSourceTester[config.length];
+
+ for(int i=0; i<tester.length; i++){
+ tester[i] = new DataSourceTester(cachedDS[i], DBResourceManager.this, semaphore);
+ tester[i].start();
+ }
+
+ // the timeout param is set is seconds.
+ long timeout = ((dbConfig.getTimeout() <= 0) ? 60L : dbConfig.getTimeout());
+ LOGGER.debug("Timeout set to " +timeout+" seconds");
+ timeout *= 1000;
+
+
+ synchronized (semaphore) {
+ semaphore.wait(timeout);
+ }
+ } catch(Exception exc){
+ LOGGER.warn("DBResourceManager.initWorker", exc);
+ } finally {
+ startTime = System.currentTimeMillis() - startTime;
+ LOGGER.info("Completed wait with "+ dsQueue.size() + " active datasource(s) in " + startTime + " ms");
+ }
+ }
+
+
+ class DataSourceTester extends Thread {
+
+ private final CachedDataSource ds;
+ private final DBResourceManager manager;
+ private final ConcurrentLinkedQueue<CachedDataSource> semaphoreQ;
+
+ public DataSourceTester(CachedDataSource ds, DBResourceManager manager, ConcurrentLinkedQueue<CachedDataSource> semaphore) {
+ this.ds = ds;
+ this.manager = manager;
+ this.semaphoreQ = semaphore;
}
- 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);
+ @Override
+ public void run() {
+ manager.setDataSource(ds);
+ boolean slave = true;
+ if(ds != null) {
+ try {
+ slave = ds.isSlave();
+ } catch (Exception exc) {
+ LOGGER.warn("", exc);
+ }
+ }
+ if(!slave) {
+ LOGGER.info(String.format("Adding MASTER (%s) to active queue", ds.getDbConnectionName()));
+ try {
+ synchronized (semaphoreQ) {
+ semaphoreQ.notifyAll();
+ }
+ } catch(Exception exc) {
+ LOGGER.warn("", exc);
+ }
+ }
+ try {
+ synchronized (semaphoreQ) {
+ semaphoreQ.remove(ds);
+ }
+ if(semaphoreQ.isEmpty()) {
+ synchronized (semaphoreQ) {
+ semaphoreQ.notifyAll();
+ }
+ }
+ } catch(Exception exc) {
+ LOGGER.warn("", exc);
}
+ LOGGER.info(String.format("Thread DataSourceTester terminated %s for %s", this.getName(), ds.getDbConnectionName()));
}
+
}
+
private long getLongFromProperties(Properties props, String property, long defaultValue)
{
String value = null;
@@ -238,6 +329,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
class RecoveryMgr extends Thread {
+ @Override
public void run() {
while(!terminating)
{
@@ -293,7 +385,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
*/
@Override
public CachedRowSet getData(String statement, ArrayList<String> arguments, String preferredDS) throws SQLException {
- ArrayList<Object> newList=new ArrayList<Object>();
+ ArrayList<Object> newList= new ArrayList<>();
if(arguments != null && !arguments.isEmpty()) {
newList.addAll(arguments);
}
@@ -334,11 +426,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
}
sources.remove(active);
return active.getData(statement, arguments);
- } catch(SQLDataException exc){
- throw exc;
- } catch(SQLSyntaxErrorException exc){
- throw exc;
- } catch(SQLIntegrityConstraintViolationException exc){
+ } catch(SQLDataException | SQLSyntaxErrorException | SQLIntegrityConstraintViolationException exc){
throw exc;
} catch(Throwable exc){
lastException = exc;
@@ -354,7 +442,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
handleGetConnectionException(active, exc);
} finally {
if(LOGGER.isDebugEnabled()){
- time = (System.currentTimeMillis() - time);
+ time = System.currentTimeMillis() - time;
LOGGER.debug("getData processing time : "+ active.getDbConnectionName()+" "+time+" miliseconds.");
}
}
@@ -408,7 +496,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
}
} finally {
if(LOGGER.isDebugEnabled()){
- time = (System.currentTimeMillis() - time);
+ time = System.currentTimeMillis() - time;
LOGGER.debug(">> getData : "+ active.getDbConnectionName()+" "+time+" miliseconds.");
}
}
@@ -421,7 +509,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
@Override
public boolean writeData(String statement, ArrayList<String> arguments, String preferredDS) throws SQLException
{
- ArrayList<Object> newList=new ArrayList<Object>();
+ ArrayList<Object> newList= new ArrayList<>();
if(arguments != null && !arguments.isEmpty()) {
newList.addAll(arguments);
}
@@ -429,8 +517,8 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
return writeDataNoRecovery(statement, newList, preferredDS);
}
- CachedDataSource findMaster() throws PoolExhaustedException, MySQLNonTransientConnectionException {
- CachedDataSource master = null;
+ CachedDataSource findMaster() throws PoolExhaustedException {
+ CachedDataSource master = null;
CachedDataSource[] dss = this.dsQueue.toArray(new CachedDataSource[0]);
for(int i=0; i<dss.length; i++) {
if(!dss[i].isSlave()) {
@@ -442,10 +530,8 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
return master;
}
}
- if(master == null) {
- LOGGER.warn("MASTER not found.");
- }
- return master;
+ LOGGER.warn("MASTER not found.");
+ return null;
}
@@ -496,7 +582,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
}
} finally {
if(LOGGER.isDebugEnabled()){
- time = (System.currentTimeMillis() - time);
+ time = System.currentTimeMillis() - time;
LOGGER.debug("writeData processing time : "+ active.getDbConnectionName()+" "+time+" miliseconds.");
}
}
@@ -504,7 +590,12 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
return true;
}
- private void setDataSource(CachedDataSource dataSource) {
+ public void setDataSource(CachedDataSource dataSource) {
+ if(this.dsQueue.contains(dataSource))
+ return;
+ if(this.broken.contains(dataSource))
+ return;
+
if(dataSource.testConnection(true)){
this.dsQueue.add(dataSource);
} else {
@@ -533,16 +624,12 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
lastException = exc;
} catch(PoolExhaustedException exc) {
throw new NoAvailableConnectionsException(exc);
- } catch(MySQLNonTransientConnectionException exc){
- throw new NoAvailableConnectionsException(exc);
} catch(Exception exc){
lastException = exc;
if(recoveryMode){
handleGetConnectionException(active, exc);
} else {
- if(exc instanceof MySQLNonTransientConnectionException) {
- throw new NoAvailableConnectionsException(exc);
- } if(exc instanceof SQLException) {
+ if(exc instanceof SQLException) {
throw (SQLException)exc;
} else {
DBLibException excptn = new DBLibException(exc.getMessage());
@@ -857,4 +944,8 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
ds.getPoolInfo(false);
}
}
+
+ public int poolSize() {
+ return dsQueue.size();
+ }
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java
index 2e1a6e95..f30212dc 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java
@@ -23,5 +23,5 @@ package org.onap.ccsdk.sli.core.dblib;
import java.util.Observer;
public interface DBResourceObserver extends Observer {
- public boolean isMonitorDbResponse();
+ boolean isMonitorDbResponse();
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java
index 7921fa5c..fdfb47bc 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java
@@ -27,7 +27,7 @@ import javax.sql.rowset.CachedRowSet;
public interface DataAccessor {
- public abstract CachedRowSet getData(String statement, ArrayList<String> arguments, String preferredDS)
- throws SQLException;
+ CachedRowSet getData(String statement, ArrayList<String> arguments, String preferredDS)
+ throws SQLException;
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java
index bc14fb8b..4cfcc731 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java
@@ -24,10 +24,10 @@ import java.util.Comparator;
public interface DataSourceComparator extends Comparator <CachedDataSource>{
- public abstract CachedDataSource getLastUsed();
+ CachedDataSource getLastUsed();
- public abstract void setLastUsed(CachedDataSource lastUsed);
+ void setLastUsed(CachedDataSource lastUsed);
- public abstract int compare(CachedDataSource ds1, CachedDataSource ds2);
+ int compare(CachedDataSource ds1, CachedDataSource ds2);
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java
index 0dea664d..b31de354 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java
@@ -28,22 +28,22 @@ import javax.sql.rowset.CachedRowSet;
public interface DbLibService {
- /* (non-Javadoc)
- * @see DataAccessor#getData(java.lang.String, java.util.ArrayList)
- */
- public abstract CachedRowSet getData(String statement,
- ArrayList<String> arguments, String preferredDS)
- throws SQLException;
-
- /* (non-Javadoc)
- * @see DataAccessor#writeData(java.lang.String, java.util.ArrayList)
- */
- public abstract boolean writeData(String statement,
- ArrayList<String> arguments, String preferredDS)
- throws SQLException;
-
- public abstract boolean isActive();
-
- public abstract Connection getConnection() throws SQLException;
+ /* (non-Javadoc)
+ * @see DataAccessor#getData(java.lang.String, java.util.ArrayList)
+ */
+ CachedRowSet getData(String statement,
+ ArrayList<String> arguments, String preferredDS)
+ throws SQLException;
+
+ /* (non-Javadoc)
+ * @see DataAccessor#writeData(java.lang.String, java.util.ArrayList)
+ */
+ boolean writeData(String statement,
+ ArrayList<String> arguments, String preferredDS)
+ throws SQLException;
+
+ boolean isActive();
+
+ Connection getConnection() throws SQLException;
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java
index 127e6d37..b4d1ef67 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/TerminatingCachedDataSource.java
@@ -33,38 +33,47 @@ public class TerminatingCachedDataSource extends CachedDataSource implements SQL
super(jdbcElem);
}
+ @Override
protected void configure(BaseDBConfiguration jdbcElem) throws DBConfigException {
// no action
}
+ @Override
public long getInterval() {
return 1000;
}
+ @Override
public long getInitialDelay() {
return 1000;
}
+ @Override
public long getExpectedCompletionTime() {
return 50;
}
+ @Override
public void setExpectedCompletionTime(long value) {
}
+ @Override
public void setInterval(long value) {
}
+ @Override
public void setInitialDelay(long value) {
}
+ @Override
public long getUnprocessedFailoverThreshold() {
return 3;
}
+ @Override
public void setUnprocessedFailoverThreshold(long value) {
}
@@ -74,6 +83,7 @@ public class TerminatingCachedDataSource extends CachedDataSource implements SQL
return 0;
}
+ @Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
// TODO Auto-generated method stub
return null;
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java
index 4b738d42..a8bc58b8 100644..100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,83 +22,224 @@ package org.onap.ccsdk.sli.core.dblib.config;
import java.util.Properties;
+/**
+ * Base class responsible for parsing business logic for database configuration from given <code>Properties</code>.
+ */
public abstract class BaseDBConfiguration {
- public static final String DATABASE_TYPE = "org.onap.ccsdk.sli.dbtype";
- public static final String DATABASE_URL = "org.onap.ccsdk.sli.jdbc.url";
- public static final String DATABASE_NAME = "org.onap.ccsdk.sli.jdbc.database";
- public static final String CONNECTION_NAME = "org.onap.ccsdk.sli.jdbc.connection.name";
- public static final String DATABASE_USER = "org.onap.ccsdk.sli.jdbc.user";
- public static final String DATABASE_PSSWD = "org.onap.ccsdk.sli.jdbc.password";
- public static final String CONNECTION_TIMEOUT="org.onap.ccsdk.sli.jdbc.connection.timeout";
- public static final String REQUEST_TIMEOUT = "org.onap.ccsdk.sli.jdbc.request.timeout";
- public static final String MIN_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.min";
- public static final String MAX_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.max";
- public static final String INIT_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.init";
- public static final String DATABASE_HOSTS = "org.onap.ccsdk.sli.jdbc.hosts";
-
-
- protected final Properties props;
-
- public BaseDBConfiguration(Properties properties) {
- this.props = properties;
- }
-
- public int getConnTimeout() {
- try {
- String value = props.getProperty(CONNECTION_TIMEOUT);
- return Integer.parseInt(value);
- } catch(Exception exc) {
- return -1;
- }
- }
-
- public int getRequestTimeout() {
- try {
- String value = props.getProperty(REQUEST_TIMEOUT);
- if(value == null)
- return -1;
- return Integer.parseInt(value);
- } catch(Exception exc) {
- return -1;
- }
- }
-
- public String getDbConnectionName() {
- return props.getProperty(CONNECTION_NAME);
- }
-
- public String getDatabaseName() {
- return props.getProperty(DATABASE_NAME);
- }
-
- public String getDbUserId() {
- return props.getProperty(DATABASE_USER);
- }
-
- public String getDbPasswd() {
- return props.getProperty(DATABASE_PSSWD);
- }
-
- public int getDbMinLimit() {
- String value = props.getProperty(MIN_LIMIT);
- return Integer.parseInt(value);
- }
-
- public int getDbMaxLimit() {
- String value = props.getProperty(MAX_LIMIT);
- return Integer.parseInt(value);
- }
-
- public int getDbInitialLimit() {
- String value = props.getProperty(INIT_LIMIT);
- return Integer.parseInt(value);
- }
-
- public String getDbUrl() {
- return props.getProperty(DATABASE_URL);
- }
-
- public String getServerGroup() {
- return null;
- }
+
+ /**
+ * Property key within a properties configuration File for db type
+ */
+ public static final String DATABASE_TYPE = "org.onap.ccsdk.sli.dbtype";
+
+ /**
+ * Property key with a properties configuration File for db url
+ */
+ public static final String DATABASE_URL = "org.onap.ccsdk.sli.jdbc.url";
+
+ /**
+ * Property key with a properties configuration File for database name
+ */
+ public static final String DATABASE_NAME = "org.onap.ccsdk.sli.jdbc.database";
+
+ /**
+ * Property key with a properties configuration File for jdbc driver
+ */
+ public static final String DRIVER_NAME = "org.onap.ccsdk.sli.jdbc.driver";
+
+ /**
+ * Property key with a properties configuration File for db database connection name
+ */
+ public static final String CONNECTION_NAME = "org.onap.ccsdk.sli.jdbc.connection.name";
+
+ /**
+ * Property key with a properties configuration File for database user
+ */
+ public static final String DATABASE_USER = "org.onap.ccsdk.sli.jdbc.user";
+
+ /**
+ * Property key with a properties configuration File for database password
+ * for associated with <code>org.onap.ccsdk.sli.jdbc.user</code>.
+ */
+ public static final String DATABASE_PSSWD = "org.onap.ccsdk.sli.jdbc.password";
+
+ /**
+ * Property key with a properties configuration File for database connection
+ * timeout
+ */
+ public static final String CONNECTION_TIMEOUT="org.onap.ccsdk.sli.jdbc.connection.timeout";
+
+ /**
+ * Property key with a properties configuration File for database request
+ * timeout
+ */
+ public static final String REQUEST_TIMEOUT = "org.onap.ccsdk.sli.jdbc.request.timeout";
+
+ /**
+ * Property key with a properties configuration File for database minimum
+ * limit
+ */
+ public static final String MIN_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.min";
+
+ /**
+ * Property key with a properties configuration File for database maximum
+ * limit
+ */
+ public static final String MAX_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.max";
+
+ /**
+ * Property key with a properties configuration File for database initial
+ * limit
+ */
+ public static final String INIT_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.init";
+
+ /**
+ * Property key with a properties configuration File for database hosts
+ */
+ public static final String DATABASE_HOSTS = "org.onap.ccsdk.sli.jdbc.hosts";
+
+ /**
+ * default value when the connection timeout is not present or cannot be
+ * parsed.
+ */
+ private static final String DEFAULT_REJECT_CHANGE_VALUE = "-1";
+
+ /**
+ * A set of properties with database configuration information.
+ */
+ protected final Properties properties;
+
+ /**
+ * Builds a configuration based on given properties
+ *
+ * @param properties
+ * properties represented by the public constant keys defined by
+ * this class
+ */
+ public BaseDBConfiguration(final Properties properties) {
+ this.properties = properties;
+ }
+
+ /**
+ * Extracts the connection timeout.
+ *
+ * @return the connection timeout, or
+ * <code>DEFAULT_REJECT_CHANGE_VALUE</code> if not present
+ */
+ public int getConnTimeout() {
+ try {
+ String value = properties.getProperty(CONNECTION_TIMEOUT, DEFAULT_REJECT_CHANGE_VALUE);
+ return Integer.parseInt(value);
+ } catch (Exception exc) {
+ return Integer.parseInt(DEFAULT_REJECT_CHANGE_VALUE);
+ }
+ }
+
+ /**
+ * Extracts the request timeout.
+ *
+ * @return the request timeout, or <code>DEFAULT_REQUEST_TIMEOUT</code> if
+ * not present
+ */
+ public int getRequestTimeout() {
+ try {
+ String value = properties.getProperty(REQUEST_TIMEOUT, DEFAULT_REJECT_CHANGE_VALUE);
+ return Integer.parseInt(value);
+ } catch (Exception exc) {
+ return Integer.parseInt(DEFAULT_REJECT_CHANGE_VALUE);
+ }
+ }
+
+ /**
+ * Extracts the db connection name.
+ *
+ * @return the db connection name, or <code>null</code> if not present
+ */
+ public String getDbConnectionName() {
+ return properties.getProperty(CONNECTION_NAME);
+ }
+
+ /**
+ * Extracts the db name.
+ *
+ * @return the db name, or <code>null</code> if not present
+ */
+ public String getDatabaseName() {
+ return properties.getProperty(DATABASE_NAME);
+ }
+
+ /**
+ * Extracts the jdbc driver's name.
+ *
+ * @return the jdbc name, or <code>com.mysql.jdbc.Driver</code> if not present
+ */
+ public String getDriverName() {
+ return properties.getProperty(DRIVER_NAME, "com.mysql.jdbc.Driver");
+ }
+
+ /**
+ * Extracts the db user id.
+ *
+ * @return the db user id, or <code>null</code> if not present
+ */
+ public String getDbUserId() {
+ return properties.getProperty(DATABASE_USER);
+ }
+
+ /**
+ * Extracts the db password.
+ *
+ * @return the db password, or <code>null</code> if not present
+ */
+ public String getDbPasswd() {
+ return properties.getProperty(DATABASE_PSSWD);
+ }
+
+ /**
+ * Extracts the db min limit.
+ *
+ * @return the db min limit
+ * @throws NumberFormatException
+ * if the property is not specified, or cannot be parsed as an
+ * <code>Integer</code>.
+ */
+ public int getDbMinLimit() throws NumberFormatException {
+ String value = properties.getProperty(MIN_LIMIT);
+ return Integer.parseInt(value);
+ }
+
+ /**
+ * Extracts the db max limit.
+ *
+ * @return the db max limit
+ * @throws NumberFormatException
+ * if the property is not specified, or cannot be parsed as an
+ * <code>Integer</code>.
+ */
+ public int getDbMaxLimit() throws NumberFormatException {
+ String value = properties.getProperty(MAX_LIMIT);
+ return Integer.parseInt(value);
+ }
+
+ /**
+ * Extracts the db initial limit.
+ *
+ * @return the db initial limit
+ * @throws NumberFormatException
+ * if the property is not specified, or cannot be parsed as an
+ * <code>Integer</code>.
+ */
+ public int getDbInitialLimit() throws NumberFormatException {
+ String value = properties.getProperty(INIT_LIMIT);
+ return Integer.parseInt(value);
+ }
+
+ /**
+ * Extracts the db url.
+ *
+ * @return the db url, or <code>null</code> if not present
+ */
+ public String getDbUrl() {
+ return properties.getProperty(DATABASE_URL);
+ }
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractDBResourceManagerFactory.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractDBResourceManagerFactory.java
deleted file mode 100644
index e88734d2..00000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractDBResourceManagerFactory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * onap
- * ================================================================================
- * Copyright (C) 2016 - 2017 ONAP
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.dblib.factory;
-
-import org.onap.ccsdk.sli.core.dblib.jdbc.JdbcDbResourceManagerFactory;
-
-/**
- * @version $Revision: 1.1 $
- * Change Log
- * Author Date Comments
- * ============== ======== ====================================================
- * Rich Tabedzki
- */
-public class AbstractDBResourceManagerFactory {
-
- public static AbstractResourceManagerFactory getFactory(String type) throws FactoryNotDefinedException {
-
- // JDBC
- return JdbcDbResourceManagerFactory.createIntstance();
- }
-}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractResourceManagerFactory.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractResourceManagerFactory.java
deleted file mode 100644
index 741169c3..00000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractResourceManagerFactory.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * onap
- * ================================================================================
- * Copyright (C) 2016 - 2017 ONAP
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.dblib.factory;
-
-
-import java.sql.SQLException;
-import java.util.Set;
-import java.util.concurrent.Callable;
-
-import org.onap.ccsdk.sli.core.dblib.CachedDataSource;
-import org.onap.ccsdk.sli.core.dblib.CachedDataSourceFactory;
-import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
-import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration;
-import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
-import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @version $Revision: 1.6 $
- * Change Log
- * Author Date Comments
- * ============== ======== ====================================================
- * Rich Tabedzki
- */
-public abstract class AbstractResourceManagerFactory {
- private static Logger LOGGER = LoggerFactory.getLogger(AbstractResourceManagerFactory.class);
-
- public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager) throws Exception;
- public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager dbResourceManager, String sourceName) throws SQLException ;
-
-
- public static AbstractResourceManagerFactory createIntstance() throws FactoryNotDefinedException {
- throw new FactoryNotDefinedException("Factory method 'createIntstance' needs to be overriden in DBResourceManagerFactory");
- }
-
- public class DBInitTask implements Callable<CachedDataSource>
- {
- private BaseDBConfiguration config = null;
- private Set<DBInitTask> activeTasks;
-
- public DBInitTask(JDBCConfiguration jdbcconfig, Set<DBInitTask> tasks) {
- this.config = jdbcconfig;
- this.activeTasks = tasks;
- }
-
- public CachedDataSource call() throws Exception {
- CachedDataSource ds = null;
- try {
- ds = CachedDataSourceFactory.createDataSource(config);
- return ds;
- } finally {
- synchronized(activeTasks) {
- activeTasks.remove(this);
- if (activeTasks.isEmpty()) {
- final Runnable closure = new Runnable() {
-
- public void run() {
- try {
- Thread.sleep(300);
- } catch (Exception e) {
- }
- synchronized(activeTasks) {
- activeTasks.notifyAll();
- }
- }
- };
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Completed CachedDataSource.Call and notifyAll from " + ds.getDbConnectionName());
- }
- Thread worker = new Thread(closure);
- worker.setDaemon(true);
- worker.start();
- } else {
- if (LOGGER.isDebugEnabled()) {
- if (ds != null) {
- LOGGER.debug("Completed CachedDataSource.Call from " + ds.getDbConnectionName());
- }
- }
- }
- }
- }
- }
- }
-}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/FactoryNotDefinedException.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/FactoryNotDefinedException.java
deleted file mode 100644
index b6383a53..00000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/FactoryNotDefinedException.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * onap
- * ================================================================================
- * Copyright (C) 2016 - 2017 ONAP
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.dblib.factory;
-
-
-/**
- * @version 1.3
- * Change Log
- * Author Date Comments
- * ============== ======== ====================================================
- * Rich Tabedzki 01/16/08 Initial version
- */
-public class FactoryNotDefinedException extends Exception {
-
- public FactoryNotDefinedException(String message) {
- super(message);
- }
-
-}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java
index ffe83445..3ec4f2ed 100644..100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDBCachedDataSource.java
@@ -33,19 +33,10 @@ import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.mysql.jdbc.Driver;
-
-
-/**
- * @version $Revision: 1.7 $
- * Change Log
- * Author Date Comments
- * ============== ======== ====================================================
- * Rich Tabedzki
- */
public class JdbcDBCachedDataSource extends CachedDataSource
{
+ private String dbDriver;
private String dbUserId;
private String dbPasswd;
private String dbUrl;
@@ -96,15 +87,14 @@ public class JdbcDBCachedDataSource extends CachedDataSource
LOGGER.error(AS_CONF_ERROR + errorMsg);
throw new DBConfigException(errorMsg);
}
- /*
- dbDriver = jdbcConfig.getDbDriver();
+
+ dbDriver = jdbcConfig.getDriverName();
if (dbDriver == null)
{
String errorMsg = "Invalid XML contents: JDBCConnection missing dbDriver attribute";
LOGGER.error(AS_CONF_ERROR + errorMsg);
- throw new ScpTblUpdateError(errorMsg);
+ throw new DBConfigException(errorMsg);
}
- */
minLimit = jdbcConfig.getDbMinLimit();
// if (minLimit == null)
@@ -136,11 +126,10 @@ public class JdbcDBCachedDataSource extends CachedDataSource
}
try {
- Driver dr = new com.mysql.jdbc.Driver();
- Class clazz = Class.forName("com.mysql.jdbc.Driver") ;
+ Class clazz = Class.forName(dbDriver) ;
PoolProperties p = new PoolProperties();
- p.setDriverClassName("com.mysql.jdbc.Driver");
+ p.setDriverClassName(dbDriver);
p.setUrl(dbUrl);
p.setUsername(dbUserId);
p.setPassword(dbPasswd);
@@ -172,30 +161,9 @@ public class JdbcDBCachedDataSource extends CachedDataSource
PreparedStatement st = null;
ResultSet rs = null;
- try {
- con = dataSource.getConnection();
- st = con.prepareStatement("Select 1 FROM DUAL");
- rs = st.executeQuery();
- } catch(Exception exc) {
- LOGGER.error(exc.getMessage());
- } finally {
- if(rs != null) rs.close();
- if(st != null) st.close();
- if(con != null) con.close();
- }
-
initialized = true;
- LOGGER.info("MySQLDataSource <"+dbConnectionName+"> configured successfully. Using URL: "+dbUrl);
+ LOGGER.info("JdbcDBCachedDataSource <"+dbConnectionName+"> configured successfully. Using URL: "+dbUrl);
}
-
-// } catch (SQLException exc) {
-// initialized = false;
-// StringBuffer sb = new StringBuffer();
-// sb.append("Failed to initialize MySQLDataSource<");
-// sb.append(dbConnectionName).append(">. Reason: ");
-// sb.append(exc.getMessage());
-// LOGGER.error("AS_CONF_ERROR: " + sb.toString());
-//// throw new DBConfigException(e.getMessage());
} catch (Exception exc) {
initialized = false;
StringBuffer sb = new StringBuffer();
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDbResourceManagerFactory.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDbResourceManagerFactory.java
deleted file mode 100644
index 803e6b3e..00000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDbResourceManagerFactory.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * onap
- * ================================================================================
- * Copyright (C) 2016 - 2017 ONAP
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.dblib.jdbc;
-
-
-import java.sql.SQLException;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
-
-import org.onap.ccsdk.sli.core.dblib.CachedDataSource;
-import org.onap.ccsdk.sli.core.dblib.CachedDataSourceFactory;
-import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
-import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
-import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration;
-import org.onap.ccsdk.sli.core.dblib.factory.AbstractResourceManagerFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @version $Revision: 1.6 $
- * Change Log
- * Author Date Comments
- * ============== ======== ====================================================
- * Rich Tabedzki
- */
-public class JdbcDbResourceManagerFactory extends AbstractResourceManagerFactory {
- private static Logger LOGGER = LoggerFactory.getLogger(JdbcDbResourceManagerFactory.class );
- private JdbcDbResourceManagerFactory(){
-
- }
-
- class MyFutureTask extends FutureTask<CachedDataSource>
- {
-
- public MyFutureTask(Callable<CachedDataSource> result) {
- super(result);
- }
-
- }
-
- public CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager, String sourceName) throws SQLException
- {
- // here create the data sources objects
- JDBCConfiguration[] list = dbConfig.getJDBCbSourceArray();
- CachedDataSource[] cachedDS = new CachedDataSource[1];
-
- for(int i=0, max=list.length; i<max; i++){
- if(!sourceName.equals(list[i].getDbConnectionName()))
- continue;
-
- JDBCConfiguration config = list[i];
- CachedDataSource dataSource = CachedDataSourceFactory.createDataSource(config);
- cachedDS[0] = dataSource;
- }
- return cachedDS;
- }
-
- public CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager) /* throws Exception */ {
-
- ExecutorService threadExecutor = Executors.newFixedThreadPool(2);
- // here create the data sources objects
- JDBCConfiguration[] list = dbConfig.getJDBCbSourceArray();
-
- MyFutureTask[] futures = new MyFutureTask[list.length];
- final Set<DBInitTask> tasks = new HashSet<DBInitTask>();
- if(LOGGER.isDebugEnabled()) {
- LOGGER.debug("Creating " + list.length + " datasources.");
- }
-
- for(int i=0, max=list.length; i<max; i++){
- JDBCConfiguration config = list[i];
-
- DBInitTask task = new DBInitTask(config, tasks);
- tasks.add(task);
- futures[i] = new MyFutureTask(task);
- }
-
- try {
- synchronized(tasks){
- for(int i=0, max=list.length; i<max; i++){
- if(LOGGER.isDebugEnabled())
- LOGGER.debug("Starting executor tasks.");
- threadExecutor.execute(futures[i]);
- }
- // the timeout param is set is seconds.
- long timeout = ((dbConfig.getTimeout() <= 0) ? 60L : dbConfig.getTimeout());
- LOGGER.debug("Timeout set to " +timeout+" seconds");
- timeout *= 1000;
- // the timeout param is set is seconds, hence it needs to be multiplied by 1000.
- tasks.wait(timeout);
- if(LOGGER.isDebugEnabled())
- LOGGER.debug("initDBResourceManager wait completed.");
- }
- } catch(Exception exc) {
- LOGGER.error("Failed to initialize JndiCachedDataSource. Reason: ", exc);
- }
-
- if(threadExecutor != null){
- try {
- threadExecutor.shutdown();
- } catch(Exception exc){}
- }
-
- CachedDataSource[] cachedDS = new CachedDataSource[futures.length];
-
- boolean initialized = false;
- for(int i=0; i<futures.length; i++){
- Object obj = null;
- if(futures[i].isDone()){
- try {
- obj = futures[i].get();
- if(obj instanceof CachedDataSource){
- cachedDS[i] = (CachedDataSource)obj;
- initialized |= cachedDS[i].isInitialized();
- if(cachedDS[i].isInitialized())
- LOGGER.info("DataSource "+list[i].getDbConnectionName()+" initialized successfully");
- else
- LOGGER.error("DataSource "+list[i].getDbConnectionName()+" initialization failed");
- } else {
- if(obj == null) {
- LOGGER.warn("DataSource " + i + " initialization failed. Returned object is null");
- } else {
- LOGGER.warn("DataSource " + i + " initialization failed. Returned object is " + obj.getClass().getName());
- }
- }
- } catch (InterruptedException exc) {
- LOGGER.error("DataSource "+list[i].getDbConnectionName()+" initialization failed", exc);
- } catch (ExecutionException exc) {
- LOGGER.error("DataSource "+list[i].getDbConnectionName()+" initialization failed", exc);
- } catch (Exception exc) {
- LOGGER.error("DataSource "+list[i].getDbConnectionName()+" initialization failed", exc);
- }
- } else {
- try {
- obj = futures[i].get();
- if(obj instanceof CachedDataSource){
- LOGGER.warn("DataSource "+((CachedDataSource)obj).getDbConnectionName()+" failed");
- } else {
- if(obj == null) {
- LOGGER.warn("DataSource " + i + " initialization failed. Returned object is null");
- } else {
- LOGGER.warn("DataSource " + i + " initialization failed. Returned object is " + obj.getClass().getName());
- }
- }
- } catch (Exception exc) {
- LOGGER.error("DataSource "+list[i].getDbConnectionName()+" initialization failed", exc);
- }
- }
- }
-
- if(!initialized){
- new Error("Failed to initialize DB Library.");
- }
- return cachedDS;
- }
-
- public static AbstractResourceManagerFactory createIntstance() {
- return new JdbcDbResourceManagerFactory();
- }
-}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java
index c17696a8..2fdde1ee 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java
@@ -21,17 +21,17 @@
package org.onap.ccsdk.sli.core.dblib.pm;
public interface SQLExecutionMonitorObserver {
- public String getDbConnectionName();
+ String getDbConnectionName();
- public long getInterval();
- public void setInterval(long value);
+ long getInterval();
+ void setInterval(long value);
- public long getInitialDelay();
- public void setInitialDelay(long value);
+ long getInitialDelay();
+ void setInitialDelay(long value);
- public long getExpectedCompletionTime();
- public void setExpectedCompletionTime(long value);
+ long getExpectedCompletionTime();
+ void setExpectedCompletionTime(long value);
- public long getUnprocessedFailoverThreshold();
- public void setUnprocessedFailoverThreshold(long value);
+ long getUnprocessedFailoverThreshold();
+ void setUnprocessedFailoverThreshold(long value);
}
diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java
index 41011e55..41011e55 100644
--- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java
+++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java
diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java
index 77589893..77589893 100644
--- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java
+++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java
diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java
index 65ebfbae..65ebfbae 100644
--- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java
+++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java
diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java
index 0a032e8b..0a032e8b 100644
--- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java
+++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java