aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-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
-rw-r--r--filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java8
-rwxr-xr-xpom.xml16
-rwxr-xr-xsli/common/pom.xml297
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/CommonConstants.java (renamed from dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/FactoryNotDefinedException.java)26
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java132
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java25
-rw-r--r--sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java78
-rw-r--r--sli/common/src/test/resources/svclogic.properties12
-rwxr-xr-xsli/provider/pom.xml6
-rw-r--r--sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java22
-rw-r--r--sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java82
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java100
-rwxr-xr-xsli/recording/pom.xml2
-rw-r--r--sli/recording/src/main/java/org/onap/ccsdk/sli/core/sli/recording/RecordingActivator.java75
-rw-r--r--sli/recording/src/main/resources/org/opendaylight/blueprint/recording-blueprint.xml20
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java2
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java22
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextList.java4
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java2
37 files changed, 859 insertions, 1028 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/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
diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java
index 4b14b21d..abbb7c66 100644
--- a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java
+++ b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/LogFilter.java
@@ -144,7 +144,7 @@ public class LogFilter implements Filter {
String authzHeader = request.getHeader("Authorization");
String usernameAndPassword = new String(Base64.decodeBase64(authzHeader.substring(6).getBytes()));
- int userNameIndex = usernameAndPassword.indexOf(":");
+ int userNameIndex = usernameAndPassword.indexOf(':');
String username = usernameAndPassword.substring(0, userNameIndex);
userName = username;
@@ -171,7 +171,7 @@ public class LogFilter implements Filter {
MDC.put(END_TIMESTAMP,asIso8601(System.currentTimeMillis()));
//MDC.put(REQUEST_ID,"already done above");
MDC.put(SERVICE_NAME,request.getRequestURL().toString());
- int idx = request.getPathInfo().toString().lastIndexOf(":");
+ int idx = request.getPathInfo().lastIndexOf(':');
String instance = "";
if ( idx != -1 ) {
instance = request.getPathInfo().substring(idx+1);
@@ -186,13 +186,13 @@ public class LogFilter implements Filter {
MDC.put(STATUS_CODE,"COMPLETE");
}
- MDC.put(RESP_CODE,"" + response.getStatus());
+ MDC.put(RESP_CODE, Integer.toString(response.getStatus()));
MDC.put(RESP_DESC,"");
MDC.put(INSTANCE_UUID,"");
MDC.put(CATEGORY,"");
MDC.put(SEVERITY,"");
//MDC.put(SERVER_IP,""); //by chef
- MDC.put(ELAPSED_TIME,"" + (System.currentTimeMillis() - startTime));
+ MDC.put(ELAPSED_TIME,Long.toString(System.currentTimeMillis() - startTime));
//MDC.put(SERVER_HOST,""); //by chef
MDC.put(CLIENT_IP,request.getRemoteHost());
MDC.put(CLASS,"");
diff --git a/pom.xml b/pom.xml
index 3bf8b1e6..1c6cd4ae 100755
--- a/pom.xml
+++ b/pom.xml
@@ -13,15 +13,9 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-carbon-sr1</artifactId>
- <version>0.0.1-SNAPSHOT</version>
+ <version>0.0.2-SNAPSHOT</version>
</parent>
- <issueManagement>
- <system>JIRA</system>
- <url>http://jira.onap.org/</url>
- </issueManagement>
-
-
<scm>
<connection>scm:git:ssh://git@${onap.git.host}/sdnc-code.git</connection>
<developerConnection>scm:git:ssh://${onap.git.host}:${onap.git.port}/${onap.git.project}/sdnc-core.git</developerConnection>
@@ -29,12 +23,8 @@
<tag>sdnc-core-1.1.0</tag>
</scm>
- <ciManagement>
- <system>Jenkins</system>
- <url>https://jenkins.onap.org/</url>
- </ciManagement>
-
+<!--
<distributionManagement>
<repository>
<id>ecomp-releases</id>
@@ -51,7 +41,7 @@
<url>dav:https://${onap.nexus.host}/content/sites/site/org/onap/sdnc/core/${project.artifactId}/${project.version}</url>
</site>
</distributionManagement>
-
+-->
<profiles>
<profile>
diff --git a/sli/common/pom.xml b/sli/common/pom.xml
index f71ca35f..c367dd77 100755
--- a/sli/common/pom.xml
+++ b/sli/common/pom.xml
@@ -1,150 +1,157 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <artifactId>sli</artifactId>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <version>0.1.2-SNAPSHOT</version>
- </parent>
- <artifactId>sli-common</artifactId>
- <packaging>bundle</packaging>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>sli</artifactId>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <version>0.1.2-SNAPSHOT</version>
+ </parent>
+ <artifactId>sli-common</artifactId>
+ <packaging>bundle</packaging>
- <name>SLI - Common Classes</name>
- <description>The SLI Common package includes common classes used by the various SLI subcomponents, as well as classes used by clients to interface with the service logic interpreter</description>
+ <name>SLI - Common Classes</name>
+ <description>The SLI Common package includes common classes used by the various SLI subcomponents, as well as classes used by clients to interface with the service logic interpreter</description>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4</artifactId>
- <version>${antlr.version}</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.7.5</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>${commons.lang3.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>yang-binding</artifactId>
- <version>${odl.mdsal.yang.binding.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-common</artifactId>
- <version>${odl.yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.mdsal.model</groupId>
- <artifactId>ietf-inet-types</artifactId>
- <version>${odl.ietf-inet-types.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.mdsal.model</groupId>
- <artifactId>ietf-yang-types</artifactId>
- <version>${odl.ietf-yang-types.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-core-api</artifactId>
- <version>${odl.mdsal.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-impl</artifactId>
- <version>${odl.yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>equinoxSDK381</groupId>
- <artifactId>org.eclipse.osgi</artifactId>
- <version>${equinox.osgi.version}</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>${mysql.connector.version}</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib-provider</artifactId>
- <version>${sdnctl.dblib.version}</version>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.vorburger.mariaDB4j</groupId>
+ <artifactId>mariaDB4j</artifactId>
+ <version>2.2.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4</artifactId>
+ <version>${antlr.version}</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.5</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${commons.lang3.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>yang-binding</artifactId>
+ <version>${odl.mdsal.yang.binding.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-common</artifactId>
+ <version>${odl.yangtools.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>ietf-inet-types</artifactId>
+ <version>${odl.ietf-inet-types.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>ietf-yang-types</artifactId>
+ <version>${odl.ietf-yang-types.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-core-api</artifactId>
+ <version>${odl.mdsal.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-impl</artifactId>
+ <version>${odl.yangtools.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>${equinox.osgi.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>${mysql.connector.version}</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>dblib-provider</artifactId>
+ <version>${sdnctl.dblib.version}</version>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.4</version>
- <configuration>
- <includes>**/*.xsd</includes>
- <archive>
- <manifest>
- <mainClass>org.onap.ccsdk.sli.core.sli.SvcLogicParser</mainClass>
- <packageName>org.onap.ccsdk.sli.core.sli</packageName>
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Export-Package>org.onap.ccsdk.sli.core.sli;version=${project.version}</Export-Package>
- <Import-Package>*</Import-Package>
- <Embed-Dependency>*;scope=compile;artifactId=commons-lang|commons-lang3</Embed-Dependency>
- <Embed-Transitive>true</Embed-Transitive>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-maven-plugin</artifactId>
- <version>${antlr.version}</version>
- <executions>
- <execution>
- <configuration>
- <outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
- </configuration>
- <id>antlr</id>
- <goals>
- <goal>antlr4</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <includes>**/*.xsd</includes>
+ <archive>
+ <manifest>
+ <mainClass>org.onap.ccsdk.sli.core.sli.SvcLogicParser</mainClass>
+ <packageName>org.onap.ccsdk.sli.core.sli</packageName>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>org.onap.ccsdk.sli.core.sli;version=${project.version}</Export-Package>
+ <Import-Package>*</Import-Package>
+ <Embed-Dependency>*;scope=compile;artifactId=commons-lang|commons-lang3</Embed-Dependency>
+ <Embed-Transitive>true</Embed-Transitive>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-maven-plugin</artifactId>
+ <version>${antlr.version}</version>
+ <executions>
+ <execution>
+ <configuration>
+ <outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
+ </configuration>
+ <id>antlr</id>
+ <goals>
+ <goal>antlr4</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/FactoryNotDefinedException.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/CommonConstants.java
index b6383a53..d30b2b62 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/FactoryNotDefinedException.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/CommonConstants.java
@@ -1,15 +1,16 @@
/*-
* ============LICENSE_START=======================================================
- * onap
+ * ONAP : CCSDK
* ================================================================================
- * Copyright (C) 2016 - 2017 ONAP
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
* ================================================================================
* 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.
@@ -18,20 +19,9 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.ccsdk.sli.core.dblib.factory;
+package org.onap.ccsdk.sli.core.sli;
+public interface CommonConstants {
-/**
- * @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);
- }
-
+ public static final String SERVICE_LOGIC_STATUS = "SvcLogic.status";
}
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
index eaf57428..23277439 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
@@ -8,9 +8,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.
@@ -38,39 +38,38 @@ import org.w3c.dom.Text;
public class SvcLogicContext {
- private static final Logger LOG = LoggerFactory
- .getLogger(SvcLogicContext.class);
-
+ private static final Logger LOG = LoggerFactory.getLogger(SvcLogicContext.class);
+
private HashMap<String, String> attributes;
-
+
private DOMDataBroker domDataBroker;
-
+
private String status = "success";
-
+
public SvcLogicContext()
{
- this.attributes = new HashMap<String,String> ();
-
+ this.attributes = new HashMap<> ();
+
}
-
+
public SvcLogicContext(Properties props)
{
- this.attributes = new HashMap<String, String> ();
-
- if (props.containsKey("SvcLogic.status"))
+ this.attributes = new HashMap<> ();
+
+ if (props.containsKey(CommonConstants.SERVICE_LOGIC_STATUS))
{
- this.status = props.getProperty("SvcLogic.status");
+ this.status = props.getProperty(CommonConstants.SERVICE_LOGIC_STATUS);
}
-
+
for (Object nameObj : props.keySet())
{
String propName = (String) nameObj;
attributes.put(propName, props.getProperty(propName));
}
}
-
-
-
+
+
+
public DOMDataBroker getDomDataBroker() {
return domDataBroker;
}
@@ -83,14 +82,14 @@ public class SvcLogicContext {
{
if (attributes.containsKey(name))
{
- return(attributes.get(name));
+ return attributes.get(name);
}
else
{
- return(null);
+ return null;
}
}
-
+
public void setAttribute(String name, String value)
{
if (value == null) {
@@ -101,10 +100,10 @@ public class SvcLogicContext {
attributes.put(name, value);
}
}
-
+
public Set<String> getAttributeKeySet()
{
- return(attributes.keySet());
+ return attributes.keySet();
}
public String getStatus() {
@@ -114,86 +113,88 @@ public class SvcLogicContext {
public void setStatus(String status) {
this.status = status;
}
-
+
public Properties toProperties()
{
Properties props = new Properties();
-
+
if (status != null)
{
- props.setProperty("SvcLogic.status", status);
+ props.setProperty(CommonConstants.SERVICE_LOGIC_STATUS, status);
}
-
- for (String attrName : attributes.keySet())
+
+ String attrName;
+ String attrVal;
+ for (Map.Entry<String, String> entry : attributes.entrySet())
{
- String attrVal = attributes.get(attrName);
+ attrName = entry.getKey();
+ attrVal = entry.getValue();
if (attrVal == null) {
- LOG.warn("attribute " + attrName
- + "null - setting to empty string");
+ LOG.warn("attribute {} value is null - setting to empty string", attrName);
props.setProperty(attrName, "");
} else {
- props.setProperty(attrName, attributes.get(attrName));
+ props.setProperty(attrName, attrVal);
}
}
-
- return(props);
+
+ return props;
}
-
+
public void mergeDocument(String pfx, Document doc) {
String prefix = "";
-
+
if (pfx != null) {
prefix = pfx;
}
-
+
Element root = doc.getDocumentElement();
-
+
mergeElement(prefix, root, null);
}
-
+
public void mergeElement(String pfx, Element element, Map<String, Integer> nodeMap) {
-
+
// In XML, cannot tell the difference between containers and lists.
// So, have to treat each element as both (ugly but necessary).
- // We do this by passing a nodeMap to be used to count instance of each tag,
- // which will be used to set _length and to set index
-
- LOG.trace("mergeElement("+pfx+","+element.getTagName()+","+nodeMap+")");
+ // We do this by passing a nodeMap to be used to count instance of each tag,
+ // which will be used to set _length and to set index
+
+ LOG.trace("mergeElement({},{},{})", pfx, element.getTagName(), nodeMap);
String curTagName = element.getTagName();
String prefix = curTagName;
-
+
if (pfx != null) {
prefix = pfx + "." + prefix;
}
-
+
int myIdx = 0;
-
+
if (nodeMap != null) {
if (nodeMap.containsKey(curTagName)) {
- myIdx = nodeMap.get(curTagName).intValue();
+ myIdx = nodeMap.get(curTagName);
}
- nodeMap.put(curTagName, new Integer(myIdx+1));
- this.setAttribute(prefix+"_length", ""+(myIdx+1));
+ nodeMap.put(curTagName, myIdx+1);
+ this.setAttribute(prefix+"_length", Integer.toString(myIdx+1));
}
-
+
NodeList children = element.getChildNodes();
-
+
int numChildren = children.getLength();
-
- Map<String, Integer> childMap = new HashMap<String, Integer>();
- Map<String, Integer> idxChildMap = new HashMap<String, Integer>();
-
+
+ Map<String, Integer> childMap = new HashMap<>();
+ Map<String, Integer> idxChildMap = new HashMap<>();
+
for (int i = 0 ; i < numChildren ; i++) {
Node curNode = children.item(i);
-
+
if (curNode instanceof Text) {
Text curText = (Text) curNode;
String curTextValue = curText.getTextContent();
- LOG.trace("Setting ctx variable "+prefix+" = "+curTextValue);
+ LOG.trace("Setting ctx variable {} = {}", prefix, curTextValue);
this.setAttribute(prefix, curText.getTextContent());
-
+
} else if (curNode instanceof Element) {
mergeElement(prefix, (Element) curNode, childMap);
@@ -204,9 +205,9 @@ public class SvcLogicContext {
}
}
}
-
+
}
-
+
public String resolve(String ctxVarName) {
if (ctxVarName.indexOf('[') == -1) {
@@ -215,16 +216,15 @@ public class SvcLogicContext {
}
// Resolve any array references
- StringBuffer sbuff = new StringBuffer();
+ StringBuilder sbuff = new StringBuilder();
String[] ctxVarParts = ctxVarName.split("\\[");
sbuff.append(ctxVarParts[0]);
for (int i = 1; i < ctxVarParts.length; i++) {
if (ctxVarParts[i].startsWith("$")) {
- int endBracketLoc = ctxVarParts[i].indexOf("]");
+ int endBracketLoc = ctxVarParts[i].indexOf(']');
if (endBracketLoc == -1) {
// Missing end bracket ... give up parsing
- LOG.warn("Variable reference " + ctxVarName
- + " seems to be missing a ']'");
+ LOG.warn("Variable reference {} seems to be missing a ']'", ctxVarName);
return (this.getAttribute(ctxVarName));
}
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java
index 5270143a..26d45ce9 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicParser.java
@@ -21,17 +21,6 @@
package org.onap.ccsdk.sli.core.sli;
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.LinkedList;
-
-import javax.xml.XMLConstants;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
@@ -41,6 +30,16 @@ import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.LinkedList;
+
/**
* @author dt5972
*
@@ -336,7 +335,7 @@ public class SvcLogicParser {
Schema schema = null;
String validateSchema = System.getProperty(SLI_VALIDATING_PARSER, "true");
- if (validateSchema != null || validateSchema.equalsIgnoreCase("true")) {
+ if ("true".equalsIgnoreCase(validateSchema)) {
xsdUrl = getClass().getResource(SVCLOGIC_XSD);
}
@@ -362,7 +361,7 @@ public class SvcLogicParser {
SAXParser saxParser = factory.newSAXParser();
if (saxParser.isValidating()) {
- LOGGER.info("Validating against schema " + xsdUrl.getPath());
+ LOGGER.info("Parser not configured to validate XML {}", (xsdUrl != null ? xsdUrl.getPath() : null));
}
graphs = new LinkedList<>();
diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java
index 0e6000fb..07f40a2e 100644
--- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java
+++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java
@@ -8,9 +8,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,7 +20,7 @@
*/
/**
- *
+ *
*/
package org.onap.ccsdk.sli.core.sli;
@@ -28,7 +28,10 @@ import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
+import java.util.Properties;
+import ch.vorburger.mariadb4j.DB;
+import ch.vorburger.mariadb4j.DBConfigurationBuilder;
import junit.framework.TestCase;
/**
@@ -40,22 +43,43 @@ public class ITCaseSvcLogicParser extends TestCase {
/**
* Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}.
*/
-
-
+
+
public void testParse() {
-
+
try
{
+
+
URL propUrl = getClass().getResource("/svclogic.properties");
-
+
InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
-
- SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr);
-
+
+ Properties props = new Properties();
+
+ props.load(propStr);
+
+
+ // Start MariaDB4j database
+ DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder();
+ config.setPort(0); // 0 => autom. detect free port
+ DB db = DB.newEmbeddedDB(config.build());
+ db.start();
+
+
+
+ // Override jdbc URL and database name
+ props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test"));
+
+
+
+ SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(props);
+
assertNotNull(store);
-
+
store.registerNodeType("switch");
store.registerNodeType("block");
store.registerNodeType("get-resource");
@@ -69,15 +93,15 @@ public class ITCaseSvcLogicParser extends TestCase {
store.registerNodeType("release");
store.registerNodeType("for");
store.registerNodeType("set");
-
-
+
+
InputStream testStr = getClass().getResourceAsStream("/parser-good.tests");
BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
String testCaseFile = null;
while ((testCaseFile = testsReader.readLine()) != null) {
-
+
testCaseFile = testCaseFile.trim();
-
+
if (testCaseFile.length() > 0)
{
if (!testCaseFile.startsWith("/"))
@@ -94,23 +118,23 @@ public class ITCaseSvcLogicParser extends TestCase {
SvcLogicParser.validate(testCaseUrl.getPath(), store);
} catch (Exception e) {
fail("Validation failure ["+e.getMessage()+"]");
-
+
}
-
-
-
+
+
+
}
}
-
+
testStr = getClass().getResourceAsStream("/parser-bad.tests");
testsReader = new BufferedReader(new InputStreamReader(testStr));
testCaseFile = null;
while ((testCaseFile = testsReader.readLine()) != null) {
-
+
testCaseFile = testCaseFile.trim();
-
+
if (testCaseFile.length() > 0)
{
if (!testCaseFile.startsWith("/"))
@@ -134,7 +158,7 @@ public class ITCaseSvcLogicParser extends TestCase {
if (valid) {
fail("Expected compiler error on "+testCaseFile+", but got success");
}
-
+
}
}
@@ -148,10 +172,10 @@ public class ITCaseSvcLogicParser extends TestCase {
e.printStackTrace();
fail("Caught exception processing test cases");
}
-
-
+
+
}
-
-
+
+
}
diff --git a/sli/common/src/test/resources/svclogic.properties b/sli/common/src/test/resources/svclogic.properties
index 25eb3bd4..33d7ae6e 100644
--- a/sli/common/src/test/resources/svclogic.properties
+++ b/sli/common/src/test/resources/svclogic.properties
@@ -8,9 +8,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,7 +20,7 @@
###
org.onap.ccsdk.sli.dbtype = jdbc
-org.onap.ccsdk.sli.jdbc.url = jdbc:mysql://localhost:3306/sdnctl
-org.onap.ccsdk.sli.jdbc.database = sdnctl
-org.onap.ccsdk.sli.jdbc.user = sdnctl
-org.onap.ccsdk.sli.jdbc.password = gamma
+org.onap.ccsdk.sli.jdbc.url = jdbc:mysql://localhost:3306/test
+org.onap.ccsdk.sli.jdbc.database = test
+org.onap.ccsdk.sli.jdbc.user = test
+org.onap.ccsdk.sli.jdbc.password = test123
diff --git a/sli/provider/pom.xml b/sli/provider/pom.xml
index f665c56a..529f9769 100755
--- a/sli/provider/pom.xml
+++ b/sli/provider/pom.xml
@@ -19,6 +19,12 @@
<version>3.8.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>ch.vorburger.mariaDB4j</groupId>
+ <artifactId>mariaDB4j</artifactId>
+ <version>2.2.3</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
<artifactId>sli-common</artifactId>
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
index 8ab308eb..60dd6b46 100644
--- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
+++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
@@ -65,23 +65,13 @@ public class MdsalHelper {
public static void loadProperties(String propertiesFile) {
File file = new File(propertiesFile);
Properties properties = new Properties();
- InputStream input = null;
if (file.isFile() && file.canRead()) {
- try {
- input = new FileInputStream(file);
- properties.load(input);
- MdsalHelper.setYangMappingProperties(properties);
- LOG.info("Loaded properties from " + propertiesFile);
+ try (InputStream input = new FileInputStream(file)) {
+ properties.load(input);
+ MdsalHelper.setYangMappingProperties(properties);
+ LOG.info("Loaded properties from " + propertiesFile);
} catch (Exception e) {
- LOG.error("Failed to load properties " + propertiesFile + "\n", e);
- } finally {
- if (input != null) {
- try {
- input.close();
- } catch (IOException e) {
- LOG.error("Failed to close properties file " + propertiesFile + "\n", e);
- }
- }
+ LOG.error("Failed to load properties " + propertiesFile + "\n", e);
}
}else{
LOG.error("Failed to load the properties file " + propertiesFile + "\n");
@@ -127,7 +117,7 @@ public class MdsalHelper {
for (int i = 0; i < fromList.size(); i++) {
toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass);
}
- props.setProperty(pfx + "_length", "" + fromList.size());
+ props.setProperty(pfx + "_length", Integer.toString(fromList.size()));
} else if (isYangGenerated(fromClass)) {
// Class is yang generated.
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java
index 23911b68..19d985dd 100644
--- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java
+++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java
@@ -28,49 +28,49 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
public interface SvcLogicService {
- public static final String NAME = "org.onap.ccsdk.sli.core.sli.provider.SvcLogicService";
+ String NAME = "org.onap.ccsdk.sli.core.sli.provider.SvcLogicService";
- // public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException;
- /**
- * Check for existence of a directed graph
- * @param module - module name
- * @param rpc - rpc name
- * @param version - version. If null, looks for active version
- * @param mode - mode (sync/async)
- * @return true if directed graph found, false otherwise
- * @throws SvcLogicException
- */
- public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException;
+ // public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException;
+ /**
+ * Check for existence of a directed graph
+ * @param module - module name
+ * @param rpc - rpc name
+ * @param version - version. If null, looks for active version
+ * @param mode - mode (sync/async)
+ * @return true if directed graph found, false otherwise
+ * @throws SvcLogicException
+ */
+ boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException;
- /**
- * Execute a directed graph
- *
- * @param module - module name
- * @param rpc - rpc name
- * @param version - version. If null, use active version
- * @param mode - mode (sync/async)
- * @param parms - parameters, used to set SvcLogicContext attributes
- * @return final values of attributes from SvcLogicContext, as Properties
- * @throws SvcLogicException
- *
- *
- * @deprecated use execute(String module, String rpc, String version, String mode, DOMDataBroker dataBroker) instead
- */
- @Deprecated
- public Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException;
+ /**
+ * Execute a directed graph
+ *
+ * @param module - module name
+ * @param rpc - rpc name
+ * @param version - version. If null, use active version
+ * @param mode - mode (sync/async)
+ * @param parms - parameters, used to set SvcLogicContext attributes
+ * @return final values of attributes from SvcLogicContext, as Properties
+ * @throws SvcLogicException
+ *
+ *
+ * @deprecated use execute(String module, String rpc, String version, String mode, DOMDataBroker dataBroker) instead
+ */
+ @Deprecated
+ Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException;
- /**
- * Execute a directed graph
- *
- * @param module - module name
- * @param rpc - rpc name
- * @param version - version. If null, use active version
- * @param mode - mode (sync/async)
- * @param parms - parameters, used to set SvcLogicContext attributes
- * @param domDataBroker - DOMDataBroker object
- * @return final values of attributes from SvcLogicContext, as Properties
- * @throws SvcLogicException
- */
- public Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException;
+ /**
+ * Execute a directed graph
+ *
+ * @param module - module name
+ * @param rpc - rpc name
+ * @param version - version. If null, use active version
+ * @param mode - mode (sync/async)
+ * @param parms - parameters, used to set SvcLogicContext attributes
+ * @param domDataBroker - DOMDataBroker object
+ * @return final values of attributes from SvcLogicContext, as Properties
+ * @throws SvcLogicException
+ */
+ Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException;
}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
index 5e895aa3..cdf837af 100644
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
+++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
@@ -8,9 +8,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.
@@ -31,43 +31,22 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
-import org.onap.ccsdk.sli.core.sli.MetricLogger;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
-import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
import org.onap.ccsdk.sli.core.sli.SvcLogicParser;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
-import org.onap.ccsdk.sli.core.sli.provider.BlockNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.CallNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.ConfigureNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.DeleteNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.ExecuteNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.ExistsNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.ForNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.GetResourceNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.IsAvailableNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.NotifyNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.RecordNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.ReleaseNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.ReserveNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.ReturnNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.SaveNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.SetNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.SvcLogicNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl;
-import org.onap.ccsdk.sli.core.sli.provider.SwitchNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.UpdateNodeExecutor;
-import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import ch.vorburger.mariadb4j.DB;
+import ch.vorburger.mariadb4j.DBConfigurationBuilder;
import junit.framework.TestCase;
public class ITCaseSvcLogicGraphExecutor extends TestCase {
private static final Logger LOG = LoggerFactory
.getLogger(SvcLogicGraph.class);
-
+
private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() {
{
put("block", new BlockNodeExecutor());
@@ -91,19 +70,36 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase {
}
};
-
+
public void testExecute() {
-
+
try {
InputStream testStr = getClass().getResourceAsStream("/executor.tests");
BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
-
+
InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
-
- SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr);
-
+
+ Properties svcprops = new Properties();
+ svcprops.load(propStr);
+
+ // Start MariaDB4j database
+ DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder();
+ config.setPort(0); // 0 => autom. detect free port
+ DB db = DB.newEmbeddedDB(config.build());
+ db.start();
+
+
+
+ // Override jdbc URL and database name
+ svcprops.setProperty("org.onap.ccsdk.sli.jdbc.database", "test");
+ svcprops.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test"));
+
+
+
+ SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops);
+
assertNotNull(store);
-
+
store.registerNodeType("switch");
store.registerNodeType("block");
store.registerNodeType("get-resource");
@@ -118,26 +114,26 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase {
store.registerNodeType("for");
store.registerNodeType("set");
SvcLogicParser parser = new SvcLogicParser(store);
-
+
// Loop through executor tests
SvcLogicServiceImpl svc = new SvcLogicServiceImpl();
-
+
for (String nodeType : BUILTIN_NODES.keySet()) {
LOG.info("SLI - registering node executor for node type "+nodeType);
-
+
svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType));
}
String testCaseLine = null;
while ((testCaseLine = testsReader.readLine()) != null) {
-
+
String[] testCaseFields = testCaseLine.split(":");
String testCaseFile = testCaseFields[0];
String testCaseMethod = testCaseFields[1];
String testCaseParameters = null;
-
+
if (testCaseFields.length > 2) {
testCaseParameters = testCaseFields[2];
}
@@ -145,7 +141,7 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase {
SvcLogicContext ctx = new SvcLogicContext();
if (testCaseParameters != null) {
String[] testCaseParameterSettings = testCaseParameters.split(",");
-
+
for (int i = 0 ; i < testCaseParameterSettings.length ; i++) {
String[] nameValue = testCaseParameterSettings[i].split("=");
if (nameValue != null) {
@@ -154,14 +150,14 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase {
if (nameValue.length > 1) {
value = nameValue[1];
}
-
+
ctx.setAttribute(name, value);
}
}
}
-
+
testCaseFile = testCaseFile.trim();
-
+
if (testCaseFile.length() > 0) {
if (!testCaseFile.startsWith("/")) {
testCaseFile = "/"+testCaseFile;
@@ -170,12 +166,12 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase {
if (testCaseUrl == null) {
fail("Could not resolve test case file "+testCaseFile);
}
-
+
LinkedList<SvcLogicGraph> graphs = parser.parse(testCaseUrl.getPath());
-
+
assertNotNull(graphs);
-
+
for (SvcLogicGraph graph: graphs) {
if (graph.getRpc().equals(testCaseMethod)) {
Properties props = ctx.toProperties();
@@ -184,9 +180,9 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase {
String propName = (String) e1.nextElement();
LOG.info(propName+" = "+props.getProperty(propName));
}
-
+
svc.execute(graph, ctx);
-
+
props = ctx.toProperties();
LOG.info("SvcLogicContext after executing "+testCaseMethod+":");
for (Enumeration e2 = props.propertyNames(); e2.hasMoreElements() ; ) {
@@ -197,16 +193,16 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase {
}
}
-
-
+
+
}
-
-
+
+
} catch (Exception e) {
LOG.error("Caught exception executing directed graphs", e);
fail("Exception executing graphs");
}
}
-
+
}
diff --git a/sli/recording/pom.xml b/sli/recording/pom.xml
index 97c99188..f0bc0970 100755
--- a/sli/recording/pom.xml
+++ b/sli/recording/pom.xml
@@ -59,9 +59,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-Activator>org.onap.ccsdk.sli.core.sli.recording.RecordingActivator</Bundle-Activator>
<Export-Package>org.onap.ccsdk.sli.core.sli.recording;version=${project.version}</Export-Package>
- <Import-Package>*</Import-Package>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
diff --git a/sli/recording/src/main/java/org/onap/ccsdk/sli/core/sli/recording/RecordingActivator.java b/sli/recording/src/main/java/org/onap/ccsdk/sli/core/sli/recording/RecordingActivator.java
deleted file mode 100644
index 9228d15c..00000000
--- a/sli/recording/src/main/java/org/onap/ccsdk/sli/core/sli/recording/RecordingActivator.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * 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.sli.recording;
-
-import java.util.LinkedList;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class RecordingActivator implements BundleActivator {
-
- private LinkedList<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
-
- private static final Logger LOG = LoggerFactory
- .getLogger(RecordingActivator.class);
-
- @Override
- public void start(BundleContext ctx) throws Exception {
-
- if (registrations == null)
- {
- registrations = new LinkedList<ServiceRegistration>();
- }
-
-
- FileRecorder fileRecorder = new FileRecorder();
- String regName = fileRecorder.getClass().getName();
- LOG.debug("Registering FileRecorder service "+regName);
- ServiceRegistration reg =ctx.registerService(regName, fileRecorder, null);
- registrations.add(reg);
-
- Slf4jRecorder slf4jRecorder = new Slf4jRecorder();
- regName = slf4jRecorder.getClass().getName();
- LOG.debug("Registering Slf4jRecorder service "+regName);
- reg =ctx.registerService(regName, slf4jRecorder, null);
- registrations.add(reg);
-
- }
-
- @Override
- public void stop(BundleContext arg0) throws Exception {
- if (registrations != null) {
- for (ServiceRegistration reg : registrations) {
- ServiceReference regRef = reg.getReference();
- reg.unregister();
- }
- registrations = null;
- }
- }
-
-}
diff --git a/sli/recording/src/main/resources/org/opendaylight/blueprint/recording-blueprint.xml b/sli/recording/src/main/resources/org/opendaylight/blueprint/recording-blueprint.xml
new file mode 100644
index 00000000..d8035376
--- /dev/null
+++ b/sli/recording/src/main/resources/org/opendaylight/blueprint/recording-blueprint.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <bean id="fileRecorder" class="org.onap.ccsdk.sli.core.sli.recording.FileRecorder" />
+ <!-- Implementation name was chosen over interface name due to the fact that this Service
+ was previously registered using the implementation name rather than the interface name.
+ To ensure backwards compatibility with abstractions polling the Service Registry for the
+ fileRecorder, the implementation name was chosen here. -->
+ <service ref="fileRecorder" interface="org.onap.ccsdk.sli.core.sli.recording.FileRecorder" />
+
+ <bean id="slf4jRecorder" class="org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder" />
+ <!-- Implementation name was chosen over interface name due to the fact that this Service
+ was previously registered using the implementation name rather than the interface name.
+ To ensure backwards compatibility with abstractions polling the Service Registry for the
+ slf4jRecorder, the implementation name was chosen here. -->
+ <service ref="slf4jRecorder" class="org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder" />
+
+</blueprint> \ No newline at end of file
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java
index 326490d9..6bdd87e2 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java
@@ -124,7 +124,7 @@ public class DME2 implements SvcLogicJavaPlugin {
sb.append("&dme2.partner=" + this.partner);
}
sb.append("&dme2.allowhttpcode=true");
- return (sb.toString());
+ return sb.toString();
}
public synchronized String acquireHostName() {
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
index 488dc395..32375868 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
@@ -138,7 +138,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
// Obtain key-value pairs to check from parameters
LOG.trace("reading keys parameter list");
- HashMap<String,String> keys_values = new HashMap<String,String>();
+ HashMap<String,String> keys_values = new HashMap<>();
for( int i = 0; i < keys_length; i++ ) {
keys_values.put(parameters.get("keys[" + i + "].key"), parameters.get("keys[" + i + "].value"));
}
@@ -174,7 +174,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
*/
public void ctxSortList( Map<String, String> parameters, SvcLogicContext ctx ) throws SvcLogicException {
checkParameters(parameters, new String[]{"list","delimiter"}, LOG);
- ArrayList<SortableCtxListElement> list = new ArrayList<SortableCtxListElement>();
+ ArrayList<SortableCtxListElement> list = new ArrayList<>();
String[] sort_fields = null;
if( parameters.containsKey("sort-fields") ) {
@@ -205,7 +205,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
i++;
}
// Reset list length (removed by ctxBulkErase above)
- ctx.setAttribute(ctx_list_str+"_length", ""+listSz);
+ ctx.setAttribute(ctx_list_str+"_length", Integer.toString(listSz));
}
/**
@@ -284,7 +284,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
log.debug("required parameters was empty, exiting early.");
return;
}
- if (parametersMap == null || parametersMap.keySet().size() < 1){
+ if (parametersMap == null || parametersMap.keySet().isEmpty()){
String errorMessage = "This method requires the parameters [" + StringUtils.join(requiredParams,",") + "], but no parameters were passed in.";
log.error(errorMessage);
throw new SvcLogicException(errorMessage);
@@ -307,7 +307,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
* @since 1.0
*/
public static final void ctxBulkErase( SvcLogicContext ctx, String pfx ) {
- ArrayList<String> Keys = new ArrayList<String>( ctx.getAttributeKeySet() );
+ ArrayList<String> Keys = new ArrayList<>(ctx.getAttributeKeySet());
for( String key : Keys ) {
if( key.startsWith( pfx ) ) {
ctx.setAttribute( pfx + key.substring(pfx.length()) , null);
@@ -337,7 +337,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
// For each context key that begins with src_pfx, set the value of the
// key dest_pfx + the suffix of the key to the key's value
- ArrayList<String> Keys = new ArrayList<String>(ctx.getAttributeKeySet());
+ ArrayList<String> Keys = new ArrayList<>(ctx.getAttributeKeySet());
for( String key : Keys ) {
if( key.startsWith(src_pfx) ) {
// Get suffix (no leading period)
@@ -361,7 +361,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
* in ctx whose key begins with prefix.
*/
public static final Map<String, String> ctxGetBeginsWith( SvcLogicContext ctx, String prefix ) {
- Map<String, String> prefixMap = new HashMap<String, String>();
+ Map<String, String> prefixMap = new HashMap<>();
for( String key : ctx.getAttributeKeySet() ) {
if( key.startsWith(prefix) ) {
@@ -481,7 +481,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
* @since 1.0
*/
public static final int getArrayLength( SvcLogicContext ctx, String key, Logger log, LogLevel logLevel, String log_message ) {
- String ctxKey = ( key.endsWith("_length") ) ? key : key + "_length";
+ String ctxKey = key.endsWith("_length") ? key : key + "_length";
try {
return Integer.parseInt(ctx.getAttribute(ctxKey));
}
@@ -525,7 +525,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
logLevelIsEnabled( log, logLevel );
// Print sorted context memory key-value pairs to the log
- ArrayList<String> keys = new ArrayList<String>(ctx.getAttributeKeySet());
+ ArrayList<String> keys = new ArrayList<>(ctx.getAttributeKeySet());
Collections.sort(keys);
for( String key : keys ) {
logMessageAtLevel( log, logLevel, key + " = " + ctx.getAttribute(key) );
@@ -616,7 +616,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
// ========== LOCAL CLASSES ==========
private class SortableCtxListElement implements Comparable<SortableCtxListElement> {
- HashMap<String,String> child_elements = new HashMap<String,String>();
+ HashMap<String,String> child_elements = new HashMap<>();
String[] sort_fields;
public SortableCtxListElement( SvcLogicContext ctx, String root, String[] sort_fields ) {
@@ -729,7 +729,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static void requiredParameters(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- if (parameters == null || parameters.keySet().size() < 1) {
+ if (parameters == null || parameters.keySet().isEmpty()) {
String errorMessage = "requiredParameters should not be called if the parameters hashmap is null or empty!";
LOG.error(errorMessage);
throw new SvcLogicException(errorMessage);
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextList.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextList.java
index aa25fe37..32e1aebd 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextList.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextList.java
@@ -60,7 +60,7 @@ public class SvcLogicContextList {
// Initialize list
int capacity = getCtxListLength(ctx, prefix);
- this.list = new ArrayList<HashMap<String, String>>(capacity);
+ this.list = new ArrayList<>(capacity);
for( int i = 0; i < capacity; i++ ) {
this.list.add(i, new HashMap<String,String>());
}
@@ -158,7 +158,7 @@ public class SvcLogicContextList {
for( int i = 0; i < this.list.size(); i++ ) {
for( Map.Entry<String,String> entry : this.list.get(i).entrySet() ) {
- if( entry.getKey().equals("") ) {
+ if("".equals(entry.getKey())) {
ctx.setAttribute(prefix + '[' + i + ']', entry.getValue());
} else {
ctx.setAttribute(prefix + '[' + i + "]." + entry.getKey(), entry.getValue());
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java
index eaa92c3f..aa41a5c6 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java
@@ -24,5 +24,5 @@ package org.onap.ccsdk.sli.core.slipluginutils;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
public interface SvcLogicContextObject {
- public void writeToContext( SvcLogicContext ctx, String root );
+ void writeToContext(SvcLogicContext ctx, String root );
}