diff options
6 files changed, 68 insertions, 16 deletions
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java index f3ecfa27..bc466d93 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 @@ -59,10 +59,11 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito 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 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 <"; + private static final String DATA_SOURCE_CONNECT_SUCCESS = "SQL DataSource < {} > connected to {}, read-only is {}, tested successfully"; + private static final String DATA_SOURCE_CONNECT_FAILURE = "SQL DataSource < {} > test failed. Cause : {}> test failed. Cause : {}"; protected long connReqTimeout = 30L; protected long dataReqTimeout = 100L; @@ -94,6 +95,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito } protected abstract DataSource configure(BaseDBConfiguration jdbcElem) throws DBConfigException; + protected abstract int getAvailableConnections(); /* * (non-Javadoc) @@ -355,17 +357,14 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito hostname = rs.getString(2); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(SQL_DATA_SOURCE + getDbConnectionName() + "> connected to " + hostname - + ", read-only is " + readOnly + ", tested successfully "); + LOGGER.debug(DATA_SOURCE_CONNECT_SUCCESS,getDbConnectionName(),hostname,readOnly); } } } catch (Exception exc) { if (errorLevel) { - LOGGER.error( - SQL_DATA_SOURCE + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage()); + LOGGER.error(DATA_SOURCE_CONNECT_FAILURE, this.getDbConnectionName(),exc.getMessage()); } else { - LOGGER.info( - SQL_DATA_SOURCE + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage()); + LOGGER.info(DATA_SOURCE_CONNECT_FAILURE, this.getDbConnectionName(),exc.getMessage()); } return false; } finally { @@ -488,9 +487,9 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito isSlave = true; } if (isSlave) { - LOGGER.debug("SQL SLAVE : {} on server {}", connectionName, hostname); + LOGGER.debug("SQL SLAVE : {} on server {}, pool {}", connectionName, hostname, getAvailableConnections()); } else { - LOGGER.debug("SQL MASTER : {} on server {}", connectionName, hostname); + LOGGER.debug("SQL MASTER : {} on server {}, pool {}", connectionName, hostname, getAvailableConnections()); } return isSlave; } 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 85acd272..9d797d09 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 @@ -50,6 +50,7 @@ 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.config.JDBCConfiguration; +import org.onap.ccsdk.sli.core.dblib.config.TerminatingConfiguration; 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; @@ -755,7 +756,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb if(broken != null) { try { - broken.add( new TerminatingCachedDataSource(null)); + broken.add( new TerminatingCachedDataSource(new TerminatingConfiguration())); } catch(Exception exc){ LOGGER.error("Waiting for Worker to stop", exc); } 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 e1afcc22..884f8882 100755 --- 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 @@ -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. @@ -29,6 +29,8 @@ import org.onap.ccsdk.sli.core.dblib.pm.SQLExecutionMonitorObserver; public class TerminatingCachedDataSource extends CachedDataSource implements SQLExecutionMonitorObserver { + private static final int DEFAULT_AVAILABLE_CONNECTIONS = 0; + public TerminatingCachedDataSource(BaseDBConfiguration jdbcElem) throws DBConfigException { super(jdbcElem); } @@ -43,4 +45,8 @@ public class TerminatingCachedDataSource extends CachedDataSource implements SQL return null; } + @Override + protected int getAvailableConnections() { + return DEFAULT_AVAILABLE_CONNECTIONS; + } } 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 967059a3..ea6bc450 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 @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; */ public abstract class BaseDBConfiguration { - private Logger logger = LoggerFactory.getLogger(BaseDBConfiguration.class); + private static final Logger LOGGER = LoggerFactory.getLogger(BaseDBConfiguration.class); /** * Property key within a properties configuration File for db type */ @@ -134,7 +134,7 @@ public abstract class BaseDBConfiguration { String value = properties.getProperty(CONNECTION_TIMEOUT, DEFAULT_REJECT_CHANGE_VALUE); return Integer.parseInt(value); } catch (Exception exc) { - logger.error("Exception",exc); + LOGGER.error("Exception",exc); return Integer.parseInt(DEFAULT_REJECT_CHANGE_VALUE); } } @@ -150,7 +150,7 @@ public abstract class BaseDBConfiguration { String value = properties.getProperty(REQUEST_TIMEOUT, DEFAULT_REJECT_CHANGE_VALUE); return Integer.parseInt(value); } catch (Exception exc) { - logger.error("Exception",exc); + LOGGER.error("Exception",exc); return Integer.parseInt(DEFAULT_REJECT_CHANGE_VALUE); } } @@ -247,4 +247,12 @@ public abstract class BaseDBConfiguration { public String getDbUrl() { return properties.getProperty(DATABASE_URL); } + + public boolean containsKey(String propertyname) { + return properties.containsKey(propertyname); + } + + public String getProperty(String propertyname) { + return properties.getProperty(propertyname); + } } diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/TerminatingConfiguration.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/TerminatingConfiguration.java new file mode 100755 index 00000000..1ebd1441 --- /dev/null +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/TerminatingConfiguration.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * onap + * ================================================================================ + * Copyright (C) 2016 - 2017 ONAP + * ================================================================================ + * Modifications Copyright (C) 2018 IBM. + * ================================================================================ + * 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.config; + +import java.util.Properties; + +public class TerminatingConfiguration extends BaseDBConfiguration { + + public TerminatingConfiguration() { + super(new Properties()); + } + +} 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 09c1c202..a53d1863 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 @@ -193,4 +193,9 @@ public class JdbcDBCachedDataSource extends CachedDataSource { dataSource.close(true); super.cleanUp(); } + + @Override + protected int getAvailableConnections() { + return org.apache.tomcat.jdbc.pool.DataSource.class.cast(ds).getSize(); + } } |