diff options
74 files changed, 933 insertions, 1119 deletions
diff --git a/dblib/features/pom.xml b/dblib/features/pom.xml index 2be6c8dbe..4053efaf9 100755 --- a/dblib/features/pom.xml +++ b/dblib/features/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>dblib</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>dblib-features</artifactId> <name>DBLIB Adaptor - Features</name> diff --git a/dblib/installer/pom.xml b/dblib/installer/pom.xml index 10845db17..a2d7362a9 100755 --- a/dblib/installer/pom.xml +++ b/dblib/installer/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>dblib</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>dblib-installer</artifactId> <name>DBLIB Adaptor - Karaf Installer</name> diff --git a/dblib/pom.xml b/dblib/pom.xml index 9e1516374..8e7afabb5 100755 --- a/dblib/pom.xml +++ b/dblib/pom.xml @@ -3,7 +3,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>ccsdk-sli-core</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> @@ -16,7 +16,7 @@ <name>DBLIB Adaptor</name> <description>The DBLIB adaptor allows service logic to access persistent data in a local sql database</description> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> <build> diff --git a/dblib/provider/pom.xml b/dblib/provider/pom.xml index 11e0ff748..07fc61ab1 100755 --- a/dblib/provider/pom.xml +++ b/dblib/provider/pom.xml @@ -4,10 +4,10 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>dblib</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>dblib-provider</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> <packaging>bundle</packaging> <name>DBLIB Adaptor - Provider</name> <url>http://maven.apache.org</url> 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 9dc262d07..a5902d54b 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,6 +20,17 @@ package org.onap.ccsdk.sli.core.dblib; +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; +import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitor.TestObject; +import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitorObserver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import javax.sql.rowset.CachedRowSet; +import javax.sql.rowset.RowSetProvider; import java.io.Closeable; import java.io.IOException; import java.io.PrintWriter; @@ -36,20 +47,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Observer; -import javax.sql.DataSource; -import javax.sql.rowset.CachedRowSet; -import javax.sql.rowset.RowSetProvider; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -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; -import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitorObserver; -import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitor.TestObject; - -import com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException; - /** * @version $Revision: 1.13 $ @@ -94,12 +91,14 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito /* (non-Javadoc) * @see javax.sql.DataSource#getConnection() */ + @Override public Connection getConnection() throws SQLException { return ds.getConnection(); } - public CachedRowSet getData(String statement, ArrayList<Object> arguments) throws SQLException, Throwable + public CachedRowSet getData(String statement, ArrayList<Object> arguments) + throws SQLException, Throwable { TestObject testObject = null; testObject = monitor.registerRequest(); @@ -128,7 +127,8 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito } } - public boolean writeData(String statement, ArrayList<Object> arguments) throws SQLException, Throwable + public boolean writeData(String statement, ArrayList<Object> arguments) + throws SQLException, Throwable { TestObject testObject = null; testObject = monitor.registerRequest(); @@ -157,7 +157,8 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito } } - CachedRowSet executePreparedStatement(Connection conn, String statement, ArrayList<Object> arguments, boolean close) throws SQLException, Throwable + CachedRowSet executePreparedStatement(Connection conn, String statement, + ArrayList<Object> arguments, boolean close) throws SQLException, Throwable { long time = System.currentTimeMillis(); @@ -170,9 +171,10 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito } ResultSet rs = null; + PreparedStatement ps = null; try { data = RowSetProvider.newFactory().createCachedRowSet(); - PreparedStatement ps = conn.prepareStatement(statement); + ps = conn.prepareStatement(statement); if(arguments != null) { for(int i = 0, max = arguments.size(); i < max; i++){ @@ -223,6 +225,13 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito } catch(Exception exc){ } + try { + if (ps != null){ + ps.close(); + } + } catch (Exception exc){ + + } } return data; @@ -298,6 +307,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito /* (non-Javadoc) * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String) */ + @Override public Connection getConnection(String username, String password) throws SQLException { @@ -307,6 +317,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito /* (non-Javadoc) * @see javax.sql.DataSource#getLogWriter() */ + @Override public PrintWriter getLogWriter() throws SQLException { return ds.getLogWriter(); @@ -315,6 +326,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito /* (non-Javadoc) * @see javax.sql.DataSource#getLoginTimeout() */ + @Override public int getLoginTimeout() throws SQLException { return ds.getLoginTimeout(); @@ -323,6 +335,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito /* (non-Javadoc) * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter) */ + @Override public void setLogWriter(PrintWriter out) throws SQLException { ds.setLogWriter(out); @@ -331,12 +344,14 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito /* (non-Javadoc) * @see javax.sql.DataSource#setLoginTimeout(int) */ + @Override public void setLoginTimeout(int seconds) throws SQLException { ds.setLoginTimeout(seconds); } + @Override public final String getDbConnectionName(){ return connectionName; } @@ -420,10 +435,12 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito return true; } + @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { return false; } + @Override public <T> T unwrap(Class<T> iface) throws SQLException { return null; } @@ -447,34 +464,42 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito monitor.deleteObserver(observer); } + @Override public long getInterval() { return interval; } + @Override public long getInitialDelay() { return initialDelay; } + @Override public void setInterval(long value) { interval = value; } + @Override public void setInitialDelay(long value) { initialDelay = value; } + @Override public long getExpectedCompletionTime() { return expectedCompletionTime; } + @Override public void setExpectedCompletionTime(long value) { expectedCompletionTime = value; } + @Override public long getUnprocessedFailoverThreshold() { return unprocessedFailoverThreshold; } + @Override public void setUnprocessedFailoverThreshold(long value) { this.unprocessedFailoverThreshold = value; } @@ -487,6 +512,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito canTakeOffLine = false; final Thread offLineTimer = new Thread() { + @Override public void run(){ try { Thread.sleep(30000L); @@ -508,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"; @@ -520,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); @@ -565,7 +591,9 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito retValue = false; } finally { try { - lock.close(); + if (lock != null) { + lock.close(); + } } catch(Exception exc) { } diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceFactory.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceFactory.java index 07e3dfab1..296fe70f1 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceFactory.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceFactory.java @@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.core.dblib; import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration; import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration; import org.onap.ccsdk.sli.core.dblib.jdbc.JdbcDBCachedDataSource; -import org.onap.ccsdk.sli.core.dblib.jdbc.MySQLCachedDataSource; /** * @version $Revision: 1.1 $ diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java index 201cc4019..062cd8408 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java @@ -20,11 +20,8 @@ package org.onap.ccsdk.sli.core.dblib; -import com.google.common.annotations.VisibleForTesting; - import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.Optional; import java.util.Properties; @@ -35,10 +32,6 @@ import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibEnvVarFileResol import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibJREFileResolver; import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibKarafRootFileResolver; import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibPropertiesFileResolver; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -146,7 +139,6 @@ public class DBLIBResourceProvider { * <li>A <code>dblib.properties</code> file located in the karaf root directory</li> * </ol> */ - @VisibleForTesting File determinePropertiesFile(final DBLIBResourceProvider dblibResourceProvider) { for (final DblibPropertiesFileResolver dblibPropertiesFileResolver : dblibPropertiesFileResolvers) { 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 8181b1300..40d1a2382 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 @@ -43,7 +43,6 @@ import java.util.concurrent.Executor; import javax.sql.rowset.CachedRowSet; import org.apache.tomcat.jdbc.pool.PooledConnection; -import org.apache.tomcat.jdbc.pool.ProxyConnection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,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() { @@ -80,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); } @@ -95,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 46c003a5a..a2eb0f9c1 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; @@ -38,7 +48,6 @@ import java.util.PriorityQueue; import java.util.Properties; import java.util.Queue; import java.util.Set; -import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; @@ -48,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 @@ -76,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; @@ -149,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; @@ -240,6 +329,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb class RecoveryMgr extends Thread { + @Override public void run() { while(!terminating) { @@ -295,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); } @@ -336,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; @@ -356,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."); } } @@ -410,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."); } } @@ -423,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); } @@ -431,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()) { @@ -444,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; } @@ -498,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."); } } @@ -506,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 { @@ -535,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()); @@ -859,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 2e1a6e953..f30212dca 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 7921fa5c5..fdfb47bca 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 bc14fb8b9..4cfcc7318 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 de9846679..b31de3547 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 @@ -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,7 @@ package org.onap.ccsdk.sli.core.dblib; +import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; @@ -27,20 +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(); + /* (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 127e6d376..b4d1ef679 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 4b738d426..a8bc58b8b 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 e88734d2e..000000000 --- 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 6fc7e7a04..000000000 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/AbstractResourceManagerFactory.java +++ /dev/null @@ -1,104 +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.DBConfigException; -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 c024d0021..3ec4f2edf 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 @@ -30,23 +30,13 @@ import org.apache.tomcat.jdbc.pool.PoolProperties; import org.onap.ccsdk.sli.core.dblib.CachedDataSource; import org.onap.ccsdk.sli.core.dblib.DBConfigException; import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration; -import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration; 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; @@ -97,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) @@ -137,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); @@ -173,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 978de0eb3..000000000 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/JdbcDbResourceManagerFactory.java +++ /dev/null @@ -1,186 +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.Arrays; -import java.util.HashSet; -import java.util.List; -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.DataSourceComparator; -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/jdbc/MySQLCachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/MySQLCachedDataSource.java index 407209850..bea0d631f 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/MySQLCachedDataSource.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/jdbc/MySQLCachedDataSource.java @@ -26,7 +26,6 @@ import java.util.Properties; import org.onap.ccsdk.sli.core.dblib.CachedDataSource; import org.onap.ccsdk.sli.core.dblib.DBConfigException; import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration; -import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 c17696a80..2fdde1ee4 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/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java index 17c42ec83..0b69109f9 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java @@ -21,6 +21,7 @@ package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; import com.google.common.base.Strings; + import java.io.File; import java.nio.file.Paths; import java.util.Optional; 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 41011e55b..41011e55b 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 775898930..775898930 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 117492d0b..65ebfbae2 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 @@ -2,8 +2,6 @@ package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver; import static org.junit.Assert.*; -import java.io.File; -import java.util.Optional; import org.junit.Test; public class DblibJREFileResolverTest { 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 0a032e8b7..0a032e8b7 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/features/pom.xml b/filters/features/pom.xml index 0d71e9167..95ccdfcd3 100755 --- a/filters/features/pom.xml +++ b/filters/features/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>filters</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>filters-features</artifactId> <name>Filters - Features</name> diff --git a/filters/installer/pom.xml b/filters/installer/pom.xml index 1e839d93e..e2eb43060 100755 --- a/filters/installer/pom.xml +++ b/filters/installer/pom.xml @@ -4,7 +4,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>filters</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>filters-installer</artifactId> <name>Filters - Karaf Installer</name> diff --git a/filters/pom.xml b/filters/pom.xml index 2e159c410..f79787ea4 100644 --- a/filters/pom.xml +++ b/filters/pom.xml @@ -4,7 +4,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>ccsdk-sli-core</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> @@ -16,7 +16,7 @@ <name>Filters</name> <description>Servlet filter to implement ECOMP logging spec</description> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> diff --git a/filters/provider/pom.xml b/filters/provider/pom.xml index 240966e8b..a59071937 100755 --- a/filters/provider/pom.xml +++ b/filters/provider/pom.xml @@ -4,7 +4,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>filters</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>filters-provider</artifactId> <packaging>bundle</packaging> 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 4b14b21df..abbb7c66e 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,""); @@ -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> @@ -128,7 +118,7 @@ <organization> <name>ONAP</name> </organization> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </project> diff --git a/sli/common/pom.xml b/sli/common/pom.xml index 52bfd53f4..c367dd779 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.1-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 b6383a53b..d30b2b626 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/SvcLogicAtom.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicAtom.java index 699ace2e8..5e19a52c6 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicAtom.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicAtom.java @@ -21,10 +21,6 @@ package org.onap.ccsdk.sli.core.sli; -import java.io.Serializable; -import java.util.LinkedList; -import java.util.List; - public class SvcLogicAtom extends SvcLogicExpression { public enum AtomType { 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 eaf57428f..232774396 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/SvcLogicDblibStore.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java index 9216519a8..712c64aba 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java @@ -145,7 +145,7 @@ public class SvcLogicDblibStore implements SvcLogicStore { try { - dbConn = ((DBResourceManager) dbSvc).getConnection(); + dbConn = dbSvc.getConnection(); ArrayList<String> args = new ArrayList<String>(); @@ -276,7 +276,7 @@ public class SvcLogicDblibStore implements SvcLogicStore { Connection dbConn = null; PreparedStatement storeGraphStmt = null; try { - dbConn = ((DBResourceManager) dbSvc).getConnection(); + dbConn = dbSvc.getConnection(); boolean oldAutoCommit = dbConn.getAutoCommit(); dbConn.setAutoCommit(false); storeGraphStmt = dbConn diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpression.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpression.java index b8a47c45e..26783e70f 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpression.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpression.java @@ -22,7 +22,6 @@ package org.onap.ccsdk.sli.core.sli; import java.io.Serializable; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicJavaPlugin.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicJavaPlugin.java index 451277576..23dff3e6e 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicJavaPlugin.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicJavaPlugin.java @@ -21,14 +21,10 @@ package org.onap.ccsdk.sli.core.sli; -import java.util.Map; - +/** + * A marker interface, used to indicate that a class exposes methods that can be + * called from an <execute> node. Such methods must have the signature: + * void methodName(Map, SvcLogicContext) + */ public interface SvcLogicJavaPlugin { - - /** - * A marker interface, used to indicate that a class exposes methods that can be - * called from an <execute> node. Such methods must have the signature: - * void methodName(Map, SvcLogicContext) - */ - } diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicNode.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicNode.java index 56ed53054..160107fea 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicNode.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicNode.java @@ -36,8 +36,6 @@ import java.util.TreeMap; import org.apache.commons.lang3.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.xml.sax.Locator; - public class SvcLogicNode implements Serializable { diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicResource.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicResource.java index 40295bd75..0e2c42574 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicResource.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicResource.java @@ -21,7 +21,6 @@ package org.onap.ccsdk.sli.core.sli; -import java.sql.SQLException; import java.util.Map; public interface SvcLogicResource { 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 ec18b8765..07f40a2ec 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,13 +28,10 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; -import java.util.LinkedList; - -import org.onap.ccsdk.sli.core.sli.SvcLogicParser; -import org.onap.ccsdk.sli.core.sli.SvcLogicParserException; -import org.onap.ccsdk.sli.core.sli.SvcLogicStore; -import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; +import java.util.Properties; +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; import junit.framework.TestCase; /** @@ -46,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"); @@ -75,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("/")) @@ -100,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("/")) @@ -140,7 +158,7 @@ public class ITCaseSvcLogicParser extends TestCase { if (valid) { fail("Expected compiler error on "+testCaseFile+", but got success"); } - + } } @@ -154,10 +172,10 @@ public class ITCaseSvcLogicParser extends TestCase { e.printStackTrace(); fail("Caught exception processing test cases"); } - - + + } - - + + } diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicContextTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicContextTest.java index 60d70460d..3b9fff75e 100644 --- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicContextTest.java +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicContextTest.java @@ -21,17 +21,13 @@ package org.onap.ccsdk.sli.core.sli; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.io.InputStreamReader; import java.util.Enumeration; import java.util.Properties; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionParserTest.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionParserTest.java index 125ac5618..80df10cee 100644 --- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionParserTest.java +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionParserTest.java @@ -25,9 +25,6 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; -import org.onap.ccsdk.sli.core.sli.SvcLogicExprListener; -import org.onap.ccsdk.sli.core.sli.SvcLogicExpression; -import org.onap.ccsdk.sli.core.sli.SvcLogicExpressionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sli/common/src/test/resources/svclogic.properties b/sli/common/src/test/resources/svclogic.properties index 25eb3bd47..33d7ae6e4 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/features/pom.xml b/sli/features/pom.xml index 975839fc0..dc7a95dc1 100755 --- a/sli/features/pom.xml +++ b/sli/features/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>sli</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sli-features</artifactId> <name>SLI - Features</name> diff --git a/sli/installer/pom.xml b/sli/installer/pom.xml index 0319f5bcf..0eec3324a 100755 --- a/sli/installer/pom.xml +++ b/sli/installer/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>sli</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sli-installer</artifactId> <name>SLI - Karaf Installer</name> diff --git a/sli/pom.xml b/sli/pom.xml index b8ce1e3a0..7257e9ee4 100755 --- a/sli/pom.xml +++ b/sli/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>ccsdk-sli-core</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <packaging>pom</packaging> @@ -59,7 +59,7 @@ <organization> <name>ONAP</name> </organization> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </project> diff --git a/sli/provider/pom.xml b/sli/provider/pom.xml index 5ef47ef19..529f97690 100755 --- a/sli/provider/pom.xml +++ b/sli/provider/pom.xml @@ -4,7 +4,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sli</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sli-provider</artifactId> <packaging>bundle</packaging> @@ -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 8ab308ebc..60dd6b46a 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 23911b683..19d985dd4 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 5e895aa3e..cdf837afe 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 932e3ccab..f0bc09706 100755 --- a/sli/recording/pom.xml +++ b/sli/recording/pom.xml @@ -4,7 +4,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sli</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sli-recording</artifactId> <packaging>bundle</packaging> @@ -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 9228d15c2..000000000 --- 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 000000000..d8035376d --- /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/features/pom.xml b/sliPluginUtils/features/pom.xml index ce87536df..41381b6f0 100755 --- a/sliPluginUtils/features/pom.xml +++ b/sliPluginUtils/features/pom.xml @@ -8,7 +8,7 @@ <parent> <artifactId>sliPluginUtils</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <name>SliPluginUtils Plugin - Features</name> diff --git a/sliPluginUtils/installer/pom.xml b/sliPluginUtils/installer/pom.xml index a92c9cd9a..dd904e40d 100755 --- a/sliPluginUtils/installer/pom.xml +++ b/sliPluginUtils/installer/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>sliPluginUtils</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sliPluginUtils-installer</artifactId> <name>SLI Plugin Utilities - Karaf Installer</name> diff --git a/sliPluginUtils/pom.xml b/sliPluginUtils/pom.xml index 5e084af8d..3d80b7231 100755 --- a/sliPluginUtils/pom.xml +++ b/sliPluginUtils/pom.xml @@ -3,7 +3,7 @@ <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sliPluginUtils</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> <packaging>pom</packaging> <modelVersion>4.0.0</modelVersion> @@ -11,7 +11,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>ccsdk-sli-core</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <name>Service Logic Interface Plugin Utilities</name> <description>A package of static utility functions to be used when developing SLI plugins</description> diff --git a/sliPluginUtils/provider/pom.xml b/sliPluginUtils/provider/pom.xml index 430221fcb..ad950c0c8 100755 --- a/sliPluginUtils/provider/pom.xml +++ b/sliPluginUtils/provider/pom.xml @@ -8,7 +8,7 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sliPluginUtils</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <name>SliPluginUtils Plugin - Provider</name> 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 326490d9d..6bdd87e24 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 488dc395b..323758681 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 aa25fe374..32e1aebdc 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 eaa92c3f3..aa41a5c60 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 ); } diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java index 106b0cf46..166a60e90 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java @@ -27,7 +27,6 @@ import java.util.Map; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java index a46c85129..774aa1c84 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java @@ -32,7 +32,6 @@ import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortList.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortList.java index ba7a7660d..f9d70f2fb 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortList.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortList.java @@ -30,7 +30,6 @@ import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortListTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortListTest.java index 9768108de..bf7cc1399 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortListTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortListTest.java @@ -30,7 +30,6 @@ import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java index 09683ac36..72b3264e9 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java @@ -35,7 +35,6 @@ import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.slipluginutils.SliStringUtils; /** * @author km991u diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextListTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextListTest.java index 263ba1f1d..f916bbfca 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextListTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextListTest.java @@ -29,7 +29,6 @@ import java.util.HashMap; import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.slipluginutils.SvcLogicContextList; public class SvcLogicContextListTest { //private static final Logger LOG = LoggerFactory.getLogger(SvcLogicContextTest.class); diff --git a/sliapi/features/pom.xml b/sliapi/features/pom.xml index 531315e8d..caa6a8b39 100755 --- a/sliapi/features/pom.xml +++ b/sliapi/features/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>sliapi</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sliapi-features</artifactId> diff --git a/sliapi/installer/pom.xml b/sliapi/installer/pom.xml index 249520569..dff580b62 100755 --- a/sliapi/installer/pom.xml +++ b/sliapi/installer/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>sliapi</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sliapi-installer</artifactId> <packaging>pom</packaging> diff --git a/sliapi/model/pom.xml b/sliapi/model/pom.xml index 8fed20036..fc9b76377 100755 --- a/sliapi/model/pom.xml +++ b/sliapi/model/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>sliapi</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sliapi-model</artifactId> <packaging>bundle</packaging> diff --git a/sliapi/pom.xml b/sliapi/pom.xml index 64f84b9ac..a58596a93 100755 --- a/sliapi/pom.xml +++ b/sliapi/pom.xml @@ -6,13 +6,13 @@ <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>ccsdk-sli-core</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <packaging>pom</packaging> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sliapi</artifactId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> <properties> <feature-name>sliapi</feature-name> diff --git a/sliapi/provider/pom.xml b/sliapi/provider/pom.xml index e679f3687..7e0bd2642 100755 --- a/sliapi/provider/pom.xml +++ b/sliapi/provider/pom.xml @@ -4,7 +4,7 @@ <parent> <artifactId>sliapi</artifactId> <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.1-SNAPSHOT</version> + <version>0.1.2-SNAPSHOT</version> </parent> <artifactId>sliapi-provider</artifactId> <packaging>bundle</packaging> |