diff options
23 files changed, 1128 insertions, 772 deletions
diff --git a/dblib/provider/pom.xml b/dblib/provider/pom.xml index ad1cc9d2..6d4d9323 100755 --- a/dblib/provider/pom.xml +++ b/dblib/provider/pom.xml @@ -58,7 +58,7 @@ </dependency> <dependency> <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>utils</artifactId> + <artifactId>utils-provider</artifactId> <version>${project.version}</version> </dependency> 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 072a6f47..356f5ee8 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,17 +20,6 @@ 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; @@ -45,8 +34,18 @@ import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Observer; - +import javax.sql.DataSource; +import javax.sql.rowset.CachedRowSet; +import javax.sql.rowset.RowSetProvider; +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; /** * @version $Revision: 1.13 $ @@ -56,582 +55,502 @@ import java.util.Observer; * Rich Tabedzki */ -public abstract class CachedDataSource implements DataSource, SQLExecutionMonitorObserver -{ - private static Logger LOGGER = LoggerFactory.getLogger(CachedDataSource.class); - - protected static final String AS_CONF_ERROR = "AS_CONF_ERROR: "; - - protected long CONN_REQ_TIMEOUT = 30L; - protected long DATA_REQ_TIMEOUT = 100L; - - private final SQLExecutionMonitor monitor; - protected DataSource ds = null; - protected String connectionName = null; - protected boolean initialized = false; - - private long interval = 1000; - private long initialDelay = 5000; - private long expectedCompletionTime = 50L; - private boolean canTakeOffLine = true; - private long unprocessedFailoverThreshold = 3L; - - private long nextErrorReportTime = 0L; - - private String globalHostName = null; - - - public CachedDataSource(BaseDBConfiguration jdbcElem) throws DBConfigException - { - configure(jdbcElem); - monitor = new SQLExecutionMonitor(this); - } - - protected abstract void configure(BaseDBConfiguration jdbcElem) throws DBConfigException; - /* (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 - { - TestObject testObject = null; - testObject = monitor.registerRequest(); - - Connection connection = null; - try { - connection = this.getConnection(); - if(connection == null ) { - throw new SQLException("Connection invalid"); - } - if(LOGGER.isDebugEnabled()) - LOGGER.debug("Obtained connection <" + connectionName + ">: "+connection.toString()); - return executePreparedStatement(connection, statement, arguments, true); - } finally { - try { - if(connection != null && !connection.isClosed()) { - connection.close(); - } - } catch(Throwable exc) { - // the exception not monitored - } finally { - connection = null; - } - - monitor.deregisterRequest(testObject); - } - } - - public boolean writeData(String statement, ArrayList<Object> arguments) - throws SQLException, Throwable - { - TestObject testObject = null; - testObject = monitor.registerRequest(); - - Connection connection = null; - try { - connection = this.getConnection(); - if(connection == null ) { - throw new SQLException("Connection invalid"); - } - if(LOGGER.isDebugEnabled()) - LOGGER.debug("Obtained connection <" + connectionName + ">: "+connection.toString()); - return executeUpdatePreparedStatement(connection, statement, arguments, true); - } finally { - try { - if(connection != null && !connection.isClosed()) { - connection.close(); - } - } catch(Throwable exc) { - // the exception not monitored - } finally { - connection = null; - } - - monitor.deregisterRequest(testObject); - } - } - - CachedRowSet executePreparedStatement(Connection conn, String statement, - ArrayList<Object> arguments, boolean close) throws SQLException, Throwable - { - long time = System.currentTimeMillis(); - - CachedRowSet data = null; - if(LOGGER.isDebugEnabled()){ - LOGGER.debug("SQL Statement: "+ statement); - if(arguments != null && !arguments.isEmpty()) { - LOGGER.debug("Argunments: "+ Arrays.toString(arguments.toArray())); - } - } - - ResultSet rs = null; - PreparedStatement ps = null; - try { - data = RowSetProvider.newFactory().createCachedRowSet(); - ps = conn.prepareStatement(statement); - if(arguments != null) - { - for(int i = 0, max = arguments.size(); i < max; i++){ - ps.setObject(i+1, arguments.get(i)); - } - } - rs = ps.executeQuery(); - data.populate(rs); - // Point the rowset Cursor to the start - if(LOGGER.isDebugEnabled()){ - LOGGER.debug("SQL SUCCESS. rows returned: " + data.size()+ ", time(ms): "+ (System.currentTimeMillis() - time)); } - } catch(SQLException exc){ - if(LOGGER.isDebugEnabled()){ - LOGGER.debug("SQL FAILURE. time(ms): "+ (System.currentTimeMillis() - time)); - } - try { conn.rollback(); } catch(Throwable thr){} - if(arguments != null && !arguments.isEmpty()) { - LOGGER.error("<"+connectionName+"> Failed to execute: "+ statement + " with arguments: "+arguments.toString(), exc); - } else { - LOGGER.error("<"+connectionName+"> Failed to execute: "+ statement + " with no arguments. ", exc); - } - throw exc; - } catch(Throwable exc){ - if(LOGGER.isDebugEnabled()){ - LOGGER.debug("SQL FAILURE. time(ms): "+ (System.currentTimeMillis() - time)); - } - if(arguments != null && !arguments.isEmpty()) { - LOGGER.error("<"+connectionName+"> Failed to execute: "+ statement + " with arguments: "+arguments.toString(), exc); - } else { - LOGGER.error("<"+connectionName+"> Failed to execute: "+ statement + " with no arguments. ", exc); - } - throw exc; // new SQLException(exc); - } finally { - - try { - if(rs != null){ - rs.close(); - rs = null; - } - } catch(Exception exc){ - - } - try { - if(conn != null && close){ - conn.close(); - conn = null; - } - } catch(Exception exc){ - - } - try { - if (ps != null){ - ps.close(); - } - } catch (Exception exc){ - - } - } - - return data; - } - - boolean executeUpdatePreparedStatement(Connection conn, String statement, ArrayList<Object> arguments, boolean close) throws SQLException, Throwable { - long time = System.currentTimeMillis(); - - CachedRowSet data = null; - - int rs = -1; - try { - data = RowSetProvider.newFactory().createCachedRowSet(); - PreparedStatement ps = conn.prepareStatement(statement); - if(arguments != null) - { - for(int i = 0, max = arguments.size(); i < max; i++){ - if(arguments.get(i) instanceof Blob) { - ps.setBlob(i+1, (Blob)arguments.get(i)); - } else if(arguments.get(i) instanceof Timestamp) { - ps.setTimestamp(i+1, (Timestamp)arguments.get(i)); - } else if(arguments.get(i) instanceof Integer) { - ps.setInt(i+1, (Integer)arguments.get(i)); - } else if(arguments.get(i) instanceof Long) { - ps.setLong(i+1, (Long)arguments.get(i)); - } else if(arguments.get(i) instanceof Date) { - ps.setDate(i+1, (Date)arguments.get(i)); - } else { - ps.setObject(i+1, arguments.get(i)); - } - } - } - rs = ps.executeUpdate(); - // Point the rowset Cursor to the start - if(LOGGER.isDebugEnabled()){ - LOGGER.debug("SQL SUCCESS. rows returned: " + data.size()+ ", time(ms): "+ (System.currentTimeMillis() - time)); - } - } catch(SQLException exc){ - if(LOGGER.isDebugEnabled()){ - LOGGER.debug("SQL FAILURE. time(ms): "+ (System.currentTimeMillis() - time)); - } - try { conn.rollback(); } catch(Throwable thr){} - if(arguments != null && !arguments.isEmpty()) { - LOGGER.error("<"+connectionName+"> Failed to execute: "+ statement + " with arguments: "+arguments.toString(), exc); - } else { - LOGGER.error("<"+connectionName+"> Failed to execute: "+ statement + " with no arguments. ", exc); - } - throw exc; - } catch(Throwable exc){ - if(LOGGER.isDebugEnabled()){ - LOGGER.debug("SQL FAILURE. time(ms): "+ (System.currentTimeMillis() - time)); - } - if(arguments != null && !arguments.isEmpty()) { - LOGGER.error("<"+connectionName+"> Failed to execute: "+ statement + " with arguments: "+arguments.toString(), exc); - } else { - LOGGER.error("<"+connectionName+"> Failed to execute: "+ statement + " with no arguments. ", exc); - } - throw exc; // new SQLException(exc); - } finally { - try { - if(conn != null && close){ - conn.close(); - conn = null; - } - } catch(Exception exc){ - - } - } - - return true; - } - - /* (non-Javadoc) - * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String) - */ - @Override - public Connection getConnection(String username, String password) - throws SQLException - { - return ds.getConnection(username, password); - } - - /* (non-Javadoc) - * @see javax.sql.DataSource#getLogWriter() - */ - @Override - public PrintWriter getLogWriter() throws SQLException - { - return ds.getLogWriter(); - } - - /* (non-Javadoc) - * @see javax.sql.DataSource#getLoginTimeout() - */ - @Override - public int getLoginTimeout() throws SQLException - { - return ds.getLoginTimeout(); - } - - /* (non-Javadoc) - * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter) - */ - @Override - public void setLogWriter(PrintWriter out) throws SQLException - { - ds.setLogWriter(out); - } - - /* (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; - } - - protected final void setDbConnectionName(String name) { - this.connectionName = name; - } - - public void cleanUp(){ - if(ds != null && ds instanceof Closeable) { - try { - ((Closeable)ds).close(); - } catch (IOException e) { - LOGGER.warn(e.getMessage()); - } - } - ds = null; - monitor.deleteObservers(); - monitor.cleanup(); - } - - public boolean isInitialized() { - return initialized; - } - - protected boolean testConnection(){ - return testConnection(false); - } - - protected boolean testConnection(boolean error_level){ - Connection conn = null; - ResultSet rs = null; - Statement stmt = null; - try - { - Boolean readOnly = null; - String hostname = null; - conn = this.getConnection(); - stmt = conn.createStatement(); - rs = stmt.executeQuery("SELECT @@global.read_only, @@global.hostname"); //("SELECT 1 FROM DUAL"); //"select BANNER from SYS.V_$VERSION" - while(rs.next()) - { - readOnly = rs.getBoolean(1); - hostname = rs.getString(2); - - if(LOGGER.isDebugEnabled()){ - LOGGER.debug("SQL DataSource <"+getDbConnectionName() + "> connected to " + hostname + ", read-only is " + readOnly + ", tested successfully "); - } - } - - } catch (Throwable exc) { - if(error_level) { - LOGGER.error("SQL DataSource <" + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage()); - } else { - LOGGER.info("SQL DataSource <" + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage()); - } - return false; - } finally { - if(rs != null) { - try { - rs.close(); - rs = null; - } catch (SQLException e) { - } - } - if(stmt != null) { - try { - stmt.close(); - stmt = null; - } catch (SQLException e) { - } - } - if(conn !=null){ - try { - conn.close(); - conn = null; - } catch (SQLException e) { - } - } - } - return true; - } - - @Override - public boolean isWrapperFor(Class<?> iface) throws SQLException { - return false; - } - - @Override - public <T> T unwrap(Class<T> iface) throws SQLException { - return null; - } - - @SuppressWarnings("deprecation") - public void setConnectionCachingEnabled(boolean state) - { +public abstract class CachedDataSource implements DataSource, SQLExecutionMonitorObserver { + + private static final Logger LOGGER = LoggerFactory.getLogger(CachedDataSource.class); + + private static final String SQL_FAILURE = "SQL FAILURE. time(ms): "; + private static final String FAILED_TO_EXECUTE = "> Failed to execute: "; + private static final String WITH_ARGUMENTS = " with arguments: "; + private static final String WITH_NO_ARGUMENTS = " with no arguments. "; + private static final String SQL_DATA_SOURCE = "SQL DataSource <"; + + + protected long connReqTimeout = 30L; + protected long dataReqTimeout = 100L; + + private final SQLExecutionMonitor monitor; + protected DataSource ds = null; + protected String connectionName = null; + protected boolean initialized = false; + + private long interval = 1000; + private long initialDelay = 5000; + private long expectedCompletionTime = 50L; + private boolean canTakeOffLine = true; + private long unprocessedFailoverThreshold = 3L; + + private long nextErrorReportTime = 0L; + + private String globalHostName = null; + + + public CachedDataSource(BaseDBConfiguration jdbcElem) throws DBConfigException { + configure(jdbcElem); + monitor = new SQLExecutionMonitor(this); + } + + protected abstract void configure(BaseDBConfiguration jdbcElem) throws DBConfigException; + + /* (non-Javadoc) + * @see javax.sql.DataSource#getConnection() + */ + @Override + public Connection getConnection() throws SQLException { + return ds.getConnection(); + } + + public CachedRowSet getData(String statement, List<Object> arguments) + throws SQLException { + TestObject testObject = monitor.registerRequest(); + + try (Connection connection = this.getConnection()) { + if (connection == null) { + throw new SQLException("Connection invalid"); + } + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Obtained connection <" + connectionName + ">: " + connection.toString()); + } + return executePreparedStatement(connection, statement, arguments, true); + } finally { + monitor.deregisterRequest(testObject); + } + } + + public boolean writeData(String statement, List<Object> arguments) + throws SQLException { + TestObject testObject = monitor.registerRequest(); + + try (Connection connection = this.getConnection()) { + if (connection == null) { + throw new SQLException("Connection invalid"); + } + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Obtained connection <" + connectionName + ">: " + connection.toString()); + } + return executeUpdatePreparedStatement(connection, statement, arguments, true); + } finally { + monitor.deregisterRequest(testObject); + } + } + + CachedRowSet executePreparedStatement(Connection conn, String statement, + List<Object> arguments, boolean close) throws SQLException { + long time = System.currentTimeMillis(); + + CachedRowSet data = null; + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SQL Statement: " + statement); + if (arguments != null && !arguments.isEmpty()) { + LOGGER.debug("Argunments: " + Arrays.toString(arguments.toArray())); + } + } + + ResultSet rs = null; + try (PreparedStatement ps = conn.prepareStatement(statement)) { + data = RowSetProvider.newFactory().createCachedRowSet(); + if (arguments != null) { + for (int i = 0, max = arguments.size(); i < max; i++) { + ps.setObject(i + 1, arguments.get(i)); + } + } + rs = ps.executeQuery(); + data.populate(rs); + // Point the rowset Cursor to the start + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SQL SUCCESS. rows returned: " + data.size() + ", time(ms): " + (System.currentTimeMillis() + - time)); + } + } catch (SQLException exc) { + handleSqlExceptionForExecuteStatement(conn, statement, arguments, exc, time); + } finally { + handleFinallyBlockForExecutePreparedStatement(rs, conn, close); + } + + return data; + } + + private void handleSqlExceptionForExecuteStatement(Connection conn, String statement, + List<Object> arguments, SQLException exc, long time) throws SQLException { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(SQL_FAILURE + (System.currentTimeMillis() - time)); + } + try { + conn.rollback(); + } catch (Exception thr) { + LOGGER.error(thr.getLocalizedMessage(), thr); + } + if (arguments != null && !arguments.isEmpty()) { + LOGGER.error(String.format("<%s%s%s%s%s", connectionName, FAILED_TO_EXECUTE, statement, WITH_ARGUMENTS, + arguments.toString()), exc); + } else { + LOGGER.error(String.format("<%s%s%s%s", connectionName, FAILED_TO_EXECUTE, statement, WITH_NO_ARGUMENTS), + exc); + } + throw exc; + } + + private void handleFinallyBlockForExecutePreparedStatement(ResultSet rs, Connection conn, boolean close) { + try { + if (rs != null) { + rs.close(); + } + } catch (Exception exc) { + LOGGER.error(exc.getLocalizedMessage(), exc); + } + try { + if (conn != null && close) { + conn.close(); + } + } catch (Exception exc) { + LOGGER.error(exc.getLocalizedMessage(), exc); + } + } + + boolean executeUpdatePreparedStatement(Connection conn, String statement, List<Object> arguments, + boolean close) throws SQLException { + long time = System.currentTimeMillis(); + + CachedRowSet data; + + try (PreparedStatement ps = conn.prepareStatement(statement)) { + data = RowSetProvider.newFactory().createCachedRowSet(); + if (arguments != null) { + prepareStatementForExecuteUpdate(arguments, ps); + } + ps.executeUpdate(); + // Point the rowset Cursor to the start + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SQL SUCCESS. rows returned: " + data.size() + ", time(ms): " + (System.currentTimeMillis() + - time)); + } + ps.close(); + } catch (SQLException exc) { + handleSqlExceptionForExecuteStatement(conn, statement, arguments, exc, time); + } finally { + try { + if (close) { + conn.close(); + } + } catch (Exception exc) { + LOGGER.error(exc.getLocalizedMessage(), exc); + } + } + + return true; + } + + private void prepareStatementForExecuteUpdate(List<Object> arguments, PreparedStatement ps) + throws SQLException { + for (int i = 0, max = arguments.size(); i < max; i++) { + Object value = arguments.get(i); + if (value instanceof Blob) { + ps.setBlob(i + 1, (Blob) value); + } else if (value instanceof Timestamp) { + ps.setTimestamp(i + 1, (Timestamp) value); + } else if (value instanceof Integer) { + ps.setInt(i + 1, (Integer) value); + } else if (value instanceof Long) { + ps.setLong(i + 1, (Long) value); + } else if (value instanceof Date) { + ps.setDate(i + 1, (Date) value); + } else { + ps.setObject(i + 1, value); + } + } + } + + /* (non-Javadoc) + * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String) + */ + @Override + public Connection getConnection(String username, String password) + throws SQLException { + return ds.getConnection(username, password); + } + + /* (non-Javadoc) + * @see javax.sql.DataSource#getLogWriter() + */ + @Override + public PrintWriter getLogWriter() throws SQLException { + return ds.getLogWriter(); + } + + /* (non-Javadoc) + * @see javax.sql.DataSource#getLoginTimeout() + */ + @Override + public int getLoginTimeout() throws SQLException { + return ds.getLoginTimeout(); + } + + /* (non-Javadoc) + * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter) + */ + @Override + public void setLogWriter(PrintWriter out) throws SQLException { + ds.setLogWriter(out); + } + + /* (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; + } + + protected final void setDbConnectionName(String name) { + this.connectionName = name; + } + + public void cleanUp() { + if (ds != null && ds instanceof Closeable) { + try { + ((Closeable) ds).close(); + } catch (IOException e) { + LOGGER.warn(e.getMessage()); + } + } + ds = null; + monitor.deleteObservers(); + monitor.cleanup(); + } + + public boolean isInitialized() { + return initialized; + } + + protected boolean testConnection() { + return testConnection(false); + } + + protected boolean testConnection(boolean errorLevel) { + ResultSet rs = null; + try (Connection conn = this.getConnection(); Statement stmt = conn.createStatement()) { + Boolean readOnly; + String hostname; + rs = stmt.executeQuery( + "SELECT @@global.read_only, @@global.hostname"); //("SELECT 1 FROM DUAL"); //"select BANNER from SYS.V_$VERSION" + while (rs.next()) { + readOnly = rs.getBoolean(1); + hostname = rs.getString(2); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + SQL_DATA_SOURCE + getDbConnectionName() + "> connected to " + hostname + ", read-only is " + + readOnly + ", tested successfully "); + } + } + } catch (Exception exc) { + if (errorLevel) { + LOGGER.error( + SQL_DATA_SOURCE + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage()); + } else { + LOGGER.info( + SQL_DATA_SOURCE + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage()); + } + return false; + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + LOGGER.error(e.getLocalizedMessage(), e); + } + } + } + return true; + } + + @Override + public boolean isWrapperFor(Class<?> iface) throws SQLException { + return false; + } + + @Override + public <T> T unwrap(Class<T> iface) throws SQLException { + return null; + } + + @SuppressWarnings("deprecation") + public void setConnectionCachingEnabled(boolean state) { // if(ds != null && ds instanceof OracleDataSource) // try { // ((OracleDataSource)ds).setConnectionCachingEnabled(true); // } catch (SQLException exc) { // LOGGER.warn("", exc); // } - } - - public void addObserver(Observer observer) { - monitor.addObserver(observer); - } - - public void deleteObserver(Observer observer) { - 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; - } - - public boolean canTakeOffLine() { - return canTakeOffLine; - } - - public void blockImmediateOffLine() { - canTakeOffLine = false; - final Thread offLineTimer = new Thread() - { - @Override - public void run(){ - try { - Thread.sleep(30000L); - }catch(Throwable exc){ - - }finally{ - canTakeOffLine = true; - } - } - }; - offLineTimer.setDaemon(true); - offLineTimer.start(); - } - - /** - * @return the monitor - */ - final SQLExecutionMonitor getMonitor() { - return monitor; - } - - protected boolean isSlave() throws PoolExhaustedException { - CachedRowSet rs = null; - boolean isSlave = true; - String hostname = "UNDETERMINED"; - try { - boolean localSlave = true; - rs = this.getData("SELECT @@global.read_only, @@global.hostname", new ArrayList<Object>()); - while(rs.next()) { - localSlave = rs.getBoolean(1); - hostname = rs.getString(2); - } - isSlave = localSlave; - } catch(PoolExhaustedException peexc){ - throw peexc; - } catch (SQLException e) { - LOGGER.error("", e); - isSlave = true; - } catch (Throwable e) { - LOGGER.error("", e); - isSlave = true; - } - if(isSlave){ - LOGGER.debug("SQL SLAVE : "+connectionName + " on server " + hostname); - } else { - LOGGER.debug("SQL MASTER : "+connectionName + " on server " + hostname); - } - return isSlave; - } - - public boolean isFabric() { - return false; - } - - protected boolean lockTable(Connection conn, String tableName) { - boolean retValue = false; - Statement lock = null; - try { - if(tableName != null) { - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("Executing 'LOCK TABLES " + tableName + " WRITE' on connection " + conn.toString()); - if("SVC_LOGIC".equals(tableName)) { - Exception e = new Exception(); - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - LOGGER.debug(sw.toString()); - } - } - lock = conn.createStatement(); - lock.execute("LOCK TABLES " + tableName + " WRITE"); - retValue = true; - } - } catch(Exception exc){ - LOGGER.error("", exc); - retValue = false; - } finally { - try { - if (lock != null) { - lock.close(); - } - } catch(Exception exc) { - - } - } - return retValue; - } - - protected boolean unlockTable(Connection conn) { - boolean retValue = false; - try (Statement lock = conn.createStatement()){ - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("Executing 'UNLOCK TABLES' on connection " + conn.toString()); - } - retValue = lock.execute("UNLOCK TABLES"); - } catch(Exception exc){ - LOGGER.error("", exc); - retValue = false; - } - return retValue; - } - - public void getPoolInfo(boolean allocation) { - - } - - public long getNextErrorReportTime() { - return nextErrorReportTime; - } - - public void setNextErrorReportTime(long nextTime) { - this.nextErrorReportTime = nextTime; - } - - public void setGlobalHostName(String hostname) { - this.globalHostName = hostname; - } - - public String getGlobalHostName() { - return globalHostName; - } + } + + public void addObserver(Observer observer) { + monitor.addObserver(observer); + } + + public void deleteObserver(Observer observer) { + 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; + } + + public boolean canTakeOffLine() { + return canTakeOffLine; + } + + public void blockImmediateOffLine() { + canTakeOffLine = false; + final Thread offLineTimer = new Thread(() -> { + try { + Thread.sleep(30000L); + } catch (Exception exc) { + LOGGER.error(exc.getLocalizedMessage(), exc); + } finally { + canTakeOffLine = true; + } + }); + offLineTimer.setDaemon(true); + offLineTimer.start(); + } + + /** + * @return the monitor + */ + final SQLExecutionMonitor getMonitor() { + return monitor; + } + + protected boolean isSlave() throws PoolExhaustedException { + CachedRowSet rs = null; + boolean isSlave = true; + String hostname = "UNDETERMINED"; + try { + boolean localSlave = true; + rs = this.getData("SELECT @@global.read_only, @@global.hostname", new ArrayList<Object>()); + while (rs.next()) { + localSlave = rs.getBoolean(1); + hostname = rs.getString(2); + } + isSlave = localSlave; + } catch (PoolExhaustedException peexc) { + throw peexc; + } catch (Exception e) { + LOGGER.error("", e); + isSlave = true; + } + if (isSlave) { + LOGGER.debug(String.format("SQL SLAVE : %s on server %s", connectionName, hostname)); + } else { + LOGGER.debug(String.format("SQL MASTER : %s on server %s", connectionName, hostname)); + } + return isSlave; + } + + public boolean isFabric() { + return false; + } + + protected boolean lockTable(Connection conn, String tableName) { + boolean retValue = false; + String query = "LOCK TABLES " + tableName + " WRITE"; + try (Statement preStmt = conn.createStatement(); Statement lock = conn.prepareStatement(query); + ResultSet rs = preStmt.executeQuery("GETDATE()")) { + if (tableName != null) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Executing 'LOCK TABLES " + tableName + " WRITE' on connection " + conn.toString()); + if ("SVC_LOGIC".equals(tableName)) { + Exception e = new Exception(); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + LOGGER.debug(sw.toString()); + } + } + lock.execute(query); + retValue = true; + } + } catch (Exception exc) { + LOGGER.error("", exc); + retValue = false; + } + return retValue; + } + + protected boolean unlockTable(Connection conn) { + boolean retValue; + try (Statement lock = conn.createStatement()) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Executing 'UNLOCK TABLES' on connection " + conn.toString()); + } + retValue = lock.execute("UNLOCK TABLES"); + } catch (Exception exc) { + LOGGER.error("", exc); + retValue = false; + } + return retValue; + } + + public void getPoolInfo(boolean allocation) { + + } + + public long getNextErrorReportTime() { + return nextErrorReportTime; + } + + public void setNextErrorReportTime(long nextTime) { + this.nextErrorReportTime = nextTime; + } + + public void setGlobalHostName(String hostname) { + this.globalHostName = hostname; + } + + public String getGlobalHostName() { + return globalHostName; + } } 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 3ec4f2ed..ca16834c 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 @@ -20,11 +20,7 @@ package org.onap.ccsdk.sli.core.dblib.jdbc; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLFeatureNotSupportedException; - import org.apache.tomcat.jdbc.pool.DataSource; import org.apache.tomcat.jdbc.pool.PoolProperties; import org.onap.ccsdk.sli.core.dblib.CachedDataSource; @@ -34,66 +30,61 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class JdbcDBCachedDataSource extends CachedDataSource -{ - private String dbDriver; - private String dbUserId; - private String dbPasswd; - private String dbUrl; - - private int minLimit; - private int maxLimit; - private int initialLimit; - - private static final String AS_CONF_ERROR = "AS_CONF_ERROR: "; - - private static Logger LOGGER = LoggerFactory.getLogger(JdbcDBCachedDataSource.class); - - /** - * @param jdbcElem - */ - public JdbcDBCachedDataSource(BaseDBConfiguration jdbcElem) - { - super(jdbcElem); - } - - @Override - protected void configure(BaseDBConfiguration xmlElem) throws DBConfigException - { - BaseDBConfiguration jdbcConfig = (BaseDBConfiguration)xmlElem; - if(jdbcConfig.getConnTimeout() > 0){ - this.CONN_REQ_TIMEOUT = jdbcConfig.getConnTimeout(); - } - if(jdbcConfig.getRequestTimeout() > 0){ - this.DATA_REQ_TIMEOUT = jdbcConfig.getRequestTimeout(); - } - - // set connection pool name - String dbConnectionName = jdbcConfig.getDbConnectionName(); - super.setDbConnectionName(dbConnectionName); - // Configure the JDBC connection - dbUserId = jdbcConfig.getDbUserId(); - if (dbUserId == null) - { - String errorMsg = "Invalid XML contents: JDBCConnection missing dbUserId attribute"; - LOGGER.error(AS_CONF_ERROR + errorMsg); +public class JdbcDBCachedDataSource extends CachedDataSource { + + private String dbDriver; + private String dbUserId; + private String dbPasswd; + private String dbUrl; + + private int minLimit; + private int maxLimit; + private int initialLimit; + + private static final String AS_CONF_ERROR = "AS_CONF_ERROR: "; + + private static final Logger LOGGER = LoggerFactory.getLogger(JdbcDBCachedDataSource.class); + + /** + * @param jdbcElem + */ + public JdbcDBCachedDataSource(BaseDBConfiguration jdbcElem) { + super(jdbcElem); + } + + @Override + protected void configure(BaseDBConfiguration xmlElem) throws DBConfigException { + BaseDBConfiguration jdbcConfig = xmlElem; + if (jdbcConfig.getConnTimeout() > 0) { + this.connReqTimeout = jdbcConfig.getConnTimeout(); + } + if (jdbcConfig.getRequestTimeout() > 0) { + this.dataReqTimeout = jdbcConfig.getRequestTimeout(); + } + + // set connection pool name + String dbConnectionName = jdbcConfig.getDbConnectionName(); + super.setDbConnectionName(dbConnectionName); + // Configure the JDBC connection + dbUserId = jdbcConfig.getDbUserId(); + if (dbUserId == null) { + String errorMsg = "Invalid XML contents: JDBCConnection missing dbUserId attribute"; + LOGGER.error(AS_CONF_ERROR + errorMsg); throw new DBConfigException(errorMsg); } dbPasswd = jdbcConfig.getDbPasswd(); - if (dbPasswd == null) - { - String errorMsg = "Invalid XML contents: JDBCConnection missing dbPasswd attribute"; - LOGGER.error(AS_CONF_ERROR + errorMsg); + if (dbPasswd == null) { + String errorMsg = "Invalid XML contents: JDBCConnection missing dbPasswd attribute"; + LOGGER.error(AS_CONF_ERROR + errorMsg); throw new DBConfigException(errorMsg); } dbDriver = jdbcConfig.getDriverName(); - if (dbDriver == null) - { - String errorMsg = "Invalid XML contents: JDBCConnection missing dbDriver attribute"; - LOGGER.error(AS_CONF_ERROR + errorMsg); - throw new DBConfigException(errorMsg); + if (dbDriver == null) { + String errorMsg = "Invalid XML contents: JDBCConnection missing dbDriver attribute"; + LOGGER.error(AS_CONF_ERROR + errorMsg); + throw new DBConfigException(errorMsg); } minLimit = jdbcConfig.getDbMinLimit(); @@ -103,14 +94,14 @@ public class JdbcDBCachedDataSource extends CachedDataSource // LOGGER.error(AS_CONF_ERROR + errorMsg); // throw new DBConfigException(errorMsg); // } - maxLimit = jdbcConfig.getDbMaxLimit(); + maxLimit = jdbcConfig.getDbMaxLimit(); // if (maxLimit == null) // { // String errorMsg = "Invalid XML contents: JDBC Connection missing maxLimit attribute"; // LOGGER.error(AS_CONF_ERROR + errorMsg); // throw new DBConfigException(errorMsg); // } - initialLimit = jdbcConfig.getDbInitialLimit(); + initialLimit = jdbcConfig.getDbInitialLimit(); // if (initialLimit == null) // { // String errorMsg = "Invalid XML contents: JDBC Connection missing initialLimit attribute"; @@ -119,98 +110,86 @@ public class JdbcDBCachedDataSource extends CachedDataSource // } dbUrl = jdbcConfig.getDbUrl(); - if(dbUrl == null){ - String errorMsg = "Invalid XML contents: JDBCConnection missing dbUrl attribute"; - LOGGER.error(AS_CONF_ERROR + errorMsg); + if (dbUrl == null) { + String errorMsg = "Invalid XML contents: JDBCConnection missing dbUrl attribute"; + LOGGER.error(AS_CONF_ERROR + errorMsg); throw new DBConfigException(errorMsg); } - try { - Class clazz = Class.forName(dbDriver) ; - - PoolProperties p = new PoolProperties(); - p.setDriverClassName(dbDriver); - p.setUrl(dbUrl); - p.setUsername(dbUserId); - p.setPassword(dbPasswd); - p.setJmxEnabled(true); - p.setTestWhileIdle(false); - p.setTestOnBorrow(true); - p.setValidationQuery("SELECT 1"); - p.setTestOnReturn(false); - p.setValidationInterval(30000); - p.setTimeBetweenEvictionRunsMillis(30000); - p.setInitialSize(initialLimit); - p.setMaxActive(maxLimit); - p.setMaxIdle(maxLimit); - p.setMaxWait(10000); - p.setRemoveAbandonedTimeout(60); - p.setMinEvictableIdleTimeMillis(30000); - p.setMinIdle(minLimit); - p.setLogAbandoned(true); - p.setRemoveAbandoned(true); - p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" - + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); - - DataSource dataSource = new DataSource(p); - - synchronized(this) - { - this.ds = dataSource; - Connection con = null; - PreparedStatement st = null; - ResultSet rs = null; - - initialized = true; - LOGGER.info("JdbcDBCachedDataSource <"+dbConnectionName+"> configured successfully. Using URL: "+dbUrl); - } - } catch (Exception exc) { - initialized = false; - StringBuffer sb = new StringBuffer(); - sb.append("Failed to initialize MySQLCachedDataSource <"); - sb.append(dbConnectionName).append(">. Reason: "); - sb.append(exc.getMessage()); - LOGGER.error("AS_CONF_ERROR: " + sb.toString()); + try { + + PoolProperties p = new PoolProperties(); + p.setDriverClassName(dbDriver); + p.setUrl(dbUrl); + p.setUsername(dbUserId); + p.setPassword(dbPasswd); + p.setJmxEnabled(true); + p.setTestWhileIdle(false); + p.setTestOnBorrow(true); + p.setValidationQuery("SELECT 1"); + p.setTestOnReturn(false); + p.setValidationInterval(30000); + p.setTimeBetweenEvictionRunsMillis(30000); + p.setInitialSize(initialLimit); + p.setMaxActive(maxLimit); + p.setMaxIdle(maxLimit); + p.setMaxWait(10000); + p.setRemoveAbandonedTimeout(60); + p.setMinEvictableIdleTimeMillis(30000); + p.setMinIdle(minLimit); + p.setLogAbandoned(true); + p.setRemoveAbandoned(true); + p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" + + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); + + DataSource dataSource = new DataSource(p); + + synchronized (this) { + this.ds = dataSource; + + initialized = true; + LOGGER.info(String.format("JdbcDBCachedDataSource <%s> configured successfully. Using URL: %s", + dbConnectionName, dbUrl)); + } + } catch (Exception exc) { + initialized = false; + LOGGER.error(String.format("AS_CONF_ERROR: Failed to initialize MySQLCachedDataSource <%s>. Reason: %s", + dbConnectionName, exc.getMessage())); // throw new DBConfigException(e.getMessage()); - } + } } - public final String getDbUrl() - { - return dbUrl; - } - - public final String getDbUserId() - { - return dbUserId; - } - - public final String getDbPasswd() - { - return dbPasswd; - } - - public static JdbcDBCachedDataSource createInstance(BaseDBConfiguration config) /*throws Exception*/ { - return new JdbcDBCachedDataSource(config); - } - - public String toString(){ - return getDbConnectionName(); - } - - public java.util.logging.Logger getParentLogger() - throws SQLFeatureNotSupportedException { - // TODO Auto-generated method stub - return null; - } - - public void cleanUp(){ - DataSource dataSource = (DataSource)ds; - dataSource.getPool().purge(); - int active = dataSource.getActive(); - int size = dataSource.getSize(); - dataSource.close(true); - super.cleanUp(); - } + public final String getDbUrl() { + return dbUrl; + } + + public final String getDbUserId() { + return dbUserId; + } + + public final String getDbPasswd() { + return dbPasswd; + } + + public static JdbcDBCachedDataSource createInstance(BaseDBConfiguration config) /*throws Exception*/ { + return new JdbcDBCachedDataSource(config); + } + + public String toString() { + return getDbConnectionName(); + } + public java.util.logging.Logger getParentLogger() + throws SQLFeatureNotSupportedException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void cleanUp() { + DataSource dataSource = (DataSource) ds; + dataSource.getPool().purge(); + dataSource.close(true); + super.cleanUp(); + } } @@ -109,12 +109,12 @@ </build> <modules> + <module>utils</module> <module>dblib</module> <module>sli</module> <module>filters</module> <module>sliPluginUtils</module> <module>sliapi</module> - <module>utils</module> </modules> <organization> <name>ONAP</name> diff --git a/utils/features/pom.xml b/utils/features/pom.xml new file mode 100755 index 00000000..6871d8eb --- /dev/null +++ b/utils/features/pom.xml @@ -0,0 +1,138 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>utils</artifactId> + <groupId>org.onap.ccsdk.sli.core</groupId> + <version>0.1.2-SNAPSHOT</version> + </parent> + <artifactId>utils-features</artifactId> + <name>DBLIB Adaptor - Features</name> + + <packaging>jar</packaging> + + <dependencies> + + + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>utils-provider</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.opendaylight.mdsal</groupId> + <artifactId>features-mdsal</artifactId> + <version>${odl.mdsal.features.version}</version> + <classifier>features</classifier> + <type>xml</type> + + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tomcat</groupId> + <artifactId>tomcat-jdbc</artifactId> + <version>${tomcat-jdbc.version}</version> + </dependency> + + <!-- dependency for opendaylight-karaf-empty for use by testing --> + <dependency> + <groupId>org.opendaylight.odlparent</groupId> + <artifactId>opendaylight-karaf-empty</artifactId> + <version>${odl.karaf.empty.distro.version}</version> + <type>zip</type> + </dependency> + + <dependency> + <!-- Required for launching the feature tests --> + <groupId>org.opendaylight.odlparent</groupId> + <artifactId>features-test</artifactId> + <version>${odl.commons.opendaylight.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.opendaylight.yangtools</groupId> + <artifactId>features-yangtools</artifactId> + <version>${odl.yangtools.version}</version> + <classifier>features</classifier> + <type>xml</type> + <scope>runtime</scope> + </dependency> + </dependencies> + + <build> + <resources> + <resource> + <filtering>true</filtering> + <directory>src/main/resources</directory> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>filter</id> + <goals> + <goal>resources</goal> + </goals> + <phase>generate-resources</phase> + </execution> + </executions> + </plugin> + <!-- launches the feature test, which validates that your karaf feature + can be installed inside of a karaf container. It doesn't validate that your + functionality works correctly, just that you have all of the dependent bundles + defined correctly. + <plugin> + + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.16</version> + <configuration> + <systemPropertyVariables> + <karaf.distro.groupId>org.opendaylight.odlparent</karaf.distro.groupId> + <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId> + <karaf.distro.version>${odl.karaf.empty.distro.version}</karaf.distro.version> + </systemPropertyVariables> + <dependenciesToScan> + <dependency>org.opendaylight.yangtools:features-test</dependency> + </dependenciesToScan> + </configuration> + </plugin> + --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>attach-artifacts</id> + <goals> + <goal>attach-artifact</goal> + </goals> + <phase>package</phase> + <configuration> + <artifacts> + <artifact> + <file>${project.build.directory}/classes/${features.file}</file> + <type>xml</type> + <classifier>features</classifier> + </artifact> + </artifacts> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/utils/features/src/main/resources/features.xml b/utils/features/src/main/resources/features.xml new file mode 100755 index 00000000..409f8c48 --- /dev/null +++ b/utils/features/src/main/resources/features.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<features name="sdnc-slicore-utils-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0"> + + <repository>mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features</repository> + + + <feature name='sdnc-slicore-utils' description="sdnc-slicore-utils" version='${project.version}'> + <!-- Most applications will have a dependency on the ODL MD-SAL Broker --> + <feature version="${odl.mdsal.version}">odl-mdsal-broker</feature> + <bundle>mvn:org.onap.ccsdk.sli.core/util-provider/${project.version}</bundle> + </feature> + +</features> diff --git a/utils/installer/pom.xml b/utils/installer/pom.xml new file mode 100755 index 00000000..b6f7f825 --- /dev/null +++ b/utils/installer/pom.xml @@ -0,0 +1,138 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>utils</artifactId> + <groupId>org.onap.ccsdk.sli.core</groupId> + <version>0.1.2-SNAPSHOT</version> + </parent> + <artifactId>utils-installer</artifactId> + <name>SLI core utils - Karaf Installer</name> + <packaging>pom</packaging> + + <properties> + <application.name>sdnc-core-utils</application.name> + <features.boot>sdnc-core-utils</features.boot> + <features.repositories>mvn:org.onap.ccsdk.sli.core/utils-features/${project.version}/xml/features</features.repositories> + <include.transitive.dependencies>false</include.transitive.dependencies> + </properties> + + <dependencies> + + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>utils-features</artifactId> + <version>${project.version}</version> + <classifier>features</classifier> + <type>xml</type> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>utils-provider</artifactId> + <version>${project.version}</version> + </dependency> + + + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>maven-repo-zip</id> + <goals> + <goal>single</goal> + </goals> + <phase>package</phase> + <configuration> + <attach>false</attach> + <finalName>stage/${application.name}-${project.version}</finalName> + <descriptors> + <descriptor>src/assembly/assemble_mvnrepo_zip.xml</descriptor> + </descriptors> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + </execution> + <execution> + <id>installer-zip</id> + <goals> + <goal>single</goal> + </goals> + <phase>package</phase> + <configuration> + <attach>true</attach> + <finalName>${application.name}-${project.version}-installer</finalName> + <descriptors> + <descriptor>src/assembly/assemble_installer_zip.xml</descriptor> + </descriptors> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-dependencies</id> + <goals> + <goal>copy-dependencies</goal> + </goals> + <phase>prepare-package</phase> + <configuration> + <transitive>false</transitive> + <outputDirectory>${project.build.directory}/assembly/system</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>true</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + <useRepositoryLayout>true</useRepositoryLayout> + <addParentPoms>false</addParentPoms> + <copyPom>false</copyPom> + <includeGroupIds>org.onap.ccsdk.sli,org.apache.tomcat</includeGroupIds> + <excludeArtifactIds>sli-common,sli-provider</excludeArtifactIds> + <scope>provided</scope> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <version>2.6</version> + <executions> + <execution> + <id>copy-version</id> + <goals> + <goal>copy-resources</goal> + </goals><!-- here the phase you need --> + <phase>validate</phase> + <configuration> + <outputDirectory>${basedir}/target/stage</outputDirectory> + <resources> + <resource> + <directory>src/main/resources/scripts</directory> + <includes> + <include>install-feature.sh</include> + </includes> + <filtering>true</filtering> + </resource> + </resources> + </configuration> + </execution> + + </executions> + </plugin> + + </plugins> + </build> + +</project> diff --git a/utils/installer/src/assembly/assemble_installer_zip.xml b/utils/installer/src/assembly/assemble_installer_zip.xml new file mode 100755 index 00000000..a6a22a9b --- /dev/null +++ b/utils/installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,39 @@ +<!-- Defines how we build the .zip file which is our distribution. --> + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> + <id>bin</id> + + <formats> + <format>zip</format> + </formats> + + <!-- we want "system" and related files right at the root level + as this file is suppose to be unzip on top of a karaf + distro. --> + <includeBaseDirectory>false</includeBaseDirectory> + + <fileSets> + <fileSet> + <directory>target/stage/</directory> + <outputDirectory>${application.name}</outputDirectory> + <fileMode>755</fileMode> + <includes> + <include>*.sh</include> + </includes> + </fileSet> + <fileSet> + <directory>target/stage/</directory> + <outputDirectory>${application.name}</outputDirectory> + <fileMode>644</fileMode> + <excludes> + <exclude>*.sh</exclude> + </excludes> + </fileSet> + </fileSets> + + + +</assembly> diff --git a/utils/installer/src/assembly/assemble_mvnrepo_zip.xml b/utils/installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100755 index 00000000..d96c9f40 --- /dev/null +++ b/utils/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,29 @@ +<!-- Defines how we build the .zip file which is our distribution. --> + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> + <id>bin</id> + + <formats> + <format>zip</format> + </formats> + + <!-- we want "system" and related files right at the root level + as this file is suppose to be unzip on top of a karaf + distro. --> + <includeBaseDirectory>false</includeBaseDirectory> + + <fileSets> + <fileSet> + <directory>target/assembly/</directory> + <outputDirectory>.</outputDirectory> + <excludes> + </excludes> + </fileSet> + </fileSets> + + + +</assembly> diff --git a/utils/installer/src/main/resources/scripts/install-feature.sh b/utils/installer/src/main/resources/scripts/install-feature.sh new file mode 100644 index 00000000..16b5be8c --- /dev/null +++ b/utils/installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} +ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} +ODL_KARAF_CLIENT_OPTS=${ODL_KARAF_CLIENT_OPTS:-"-u karaf"} +INSTALLERDIR=$(dirname $0) + +REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip + +if [ -f ${REPOZIP} ] +then + unzip -d ${ODL_HOME} ${REPOZIP} +else + echo "ERROR : repo zip ($REPOZIP) not found" + exit 1 +fi + +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:repo-add ${features.repositories} +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:install ${features.boot} diff --git a/utils/pom.xml b/utils/pom.xml index 93326a9d..cf7dbc50 100644..100755 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -1,56 +1,79 @@ <?xml version="1.0" encoding="UTF-8"?> -<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"> - +<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/maven-v4_0_0.xsd"> <parent> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>ccsdk-sli-core</artifactId> <version>0.1.2-SNAPSHOT</version> </parent> + <modelVersion>4.0.0</modelVersion> - <packaging>bundle</packaging> + <packaging>pom</packaging> + <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>utils</artifactId> - <name>SLI Core Utilities Package</name> - - <description> - The SLI Core Utilities Package provides common functionality for setting up SLI connectivity. - </description> - - <dependencies> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - <dependency> - <groupId>equinoxSDK381</groupId> - <artifactId>org.eclipse.osgi</artifactId> - <version>${equinox.osgi.version}</version> - </dependency> - - <!-- Testing Dependencies --> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> + + + <name>SLI Utils</name> + <description>Utilities used across sli-core</description> + + <version>0.1.2-SNAPSHOT</version> <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>${bundle.plugin.version}</version> - </plugin> - </plugins> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>${maven.compile.plugin.version}</version> + <configuration> + <source>${java.version.source}</source> + <target>${java.version.target}</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.10</version> + + <executions> + <execution> + <id>aggregate</id> + <goals> + <goal>aggregate</goal> + </goals> + <phase>site</phase> + + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-source-plugin</artifactId> + <version>2.1.1</version> + <executions> + <execution> + <id>bundle-sources</id> + <phase>package</phase> + <goals> + <!-- produce source artifact for main project sources --> + <goal>jar-no-fork</goal> + + <!-- produce source artifact for project test sources --> + <goal>test-jar-no-fork</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + + </pluginManagement> </build> <organization> - <name>Inocybe Technologies and Others</name> + <name>AT&T</name> </organization> + <modules> + <module>provider</module> + <module>features</module> + <module>installer</module> + </modules> </project> diff --git a/utils/provider/pom.xml b/utils/provider/pom.xml new file mode 100644 index 00000000..41527f0e --- /dev/null +++ b/utils/provider/pom.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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"> + + <parent> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>ccsdk-sli-core</artifactId> + <version>0.1.2-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <packaging>bundle</packaging> + <artifactId>utils-provider</artifactId> + <name>SLI Core Utilities Package</name> + + <description> + The SLI Core Utilities Package provides common functionality for setting up SLI connectivity. + </description> + + <dependencies> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + <dependency> + <groupId>equinoxSDK381</groupId> + <artifactId>org.eclipse.osgi</artifactId> + <version>${equinox.osgi.version}</version> + </dependency> + + <!-- Testing Dependencies --> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>${bundle.plugin.version}</version> + </plugin> + </plugins> + </build> + <organization> + <name>Inocybe Technologies and Others</name> + </organization> +</project> diff --git a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java index 8938aa6e..8938aa6e 100644 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java +++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java diff --git a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java index 3e438d1a..3e438d1a 100644 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java +++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java diff --git a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java index 5cd6c360..5cd6c360 100644 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java +++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java diff --git a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java index 0cb75450..0cb75450 100644 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java +++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java diff --git a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java index bfb417dc..bfb417dc 100644 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java +++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java diff --git a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java index 56b4ca1b..56b4ca1b 100644 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java +++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java diff --git a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java index 9eef4cee..9eef4cee 100644 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java +++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java diff --git a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java index e5051d65..e5051d65 100644 --- a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java +++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java diff --git a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java index 5e407daf..5e407daf 100644 --- a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java +++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java diff --git a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java index 4b28d449..4b28d449 100644 --- a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java +++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java diff --git a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java index bae4168d..bae4168d 100644 --- a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java +++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java |