From 34f89faa64f815d5cf33d0905046eaf392017b39 Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Wed, 31 Aug 2022 08:46:55 +0200 Subject: add fixes for wt sulfur MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix devmgrs and db access Issue-ID: CCSDK-3749 Signed-off-by: Michael Dürre Change-Id: I41018d2daa55b200a9ba89e784f8adf4200d32c3 Signed-off-by: Michael Dürre --- .../dataprovider/database/sqldb/SqlDBClient.java | 11 ++++++++ .../database/sqldb/database/SqlDBReaderWriter.java | 30 +++++++++++++++++++--- .../database/sqldb/database/SqlDBStatusReader.java | 6 +++++ .../sqldb/query/filters/RegexSqlDBFilter.java | 2 +- 4 files changed, 45 insertions(+), 4 deletions(-) (limited to 'sdnr/wt/data-provider/dblib/src/main/java/org') diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java index 1ed0b5f17..b93145cbb 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java @@ -30,6 +30,9 @@ import java.sql.Statement; import java.text.ParseException; import java.util.regex.Matcher; import java.util.regex.Pattern; + +import com.zaxxer.hikari.HikariDataSource; +import org.mariadb.jdbc.MariaDbPoolDataSource; import org.onap.ccsdk.features.sdnr.wt.common.database.Portstatus; import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntry; import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntryList; @@ -42,6 +45,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.sql.ConnectionPoolDataSource; + public class SqlDBClient { private static final Logger LOG = LoggerFactory.getLogger(SqlDBClient.class); @@ -58,11 +63,13 @@ public class SqlDBClient { private static final String SELECT_VERSION_QUERY = "SELECT @@version as version"; private static final String DBNAME_DEFAULT = "sdnrdb"; + private static final int DEFAULT_POOLSIZE = 50; private final String dbConnectionString; private final String dbName; private final String dbHost; private final int dbPort; + private final HikariDataSource connectionPool; /** * * @param dbUrl e.g. jdbc:mysql://sdnrdb:3306/sdnrdb @@ -78,6 +85,10 @@ public class SqlDBClient { this.dbHost = matcher.group(2); this.dbPort = Integer.parseInt(matcher.group(3)); this.dbName = matcher.group(4); + this.connectionPool = new HikariDataSource(); + this.connectionPool.setJdbcUrl(this.dbConnectionString); + this.connectionPool.setUsername(username); + this.connectionPool.setPassword(password); } public AliasesEntryList readViews() { diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java index 56e965c9f..56a986e55 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java @@ -185,8 +185,9 @@ public class SqlDBReaderWriter { } String insertedId = null; PreparedStatement stmt = null; + Connection connection = null; try { - Connection connection = this.dbService.getConnection(); + connection = this.dbService.getConnection(); stmt = connection.prepareStatement(query.toSql()); stmt.execute(); @@ -208,6 +209,13 @@ public class SqlDBReaderWriter { LOG.warn("problem closing sql statement: ", e); } } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + LOG.warn("problem closing sql connection: ", e); + } + } } return insertedId; @@ -221,8 +229,9 @@ public class SqlDBReaderWriter { LOG.trace("query={}", query.toSql()); } PreparedStatement stmt = null; + Connection connection = null; try { - Connection connection = this.dbService.getConnection(); + connection = this.dbService.getConnection(); stmt = connection.prepareStatement(query.toSql()); stmt.execute(); @@ -241,6 +250,13 @@ public class SqlDBReaderWriter { LOG.warn("problem closing sql statement: ", e); } } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + LOG.warn("problem closing sql connection: ", e); + } + } } return insertedId; } @@ -262,8 +278,9 @@ public class SqlDBReaderWriter { } int affectedRows = 0; PreparedStatement stmt = null; + Connection connection = null; try { - Connection connection = this.dbService.getConnection(); + connection = this.dbService.getConnection(); stmt = connection.prepareStatement(query.toSql()); stmt.execute(); affectedRows = stmt.getUpdateCount(); @@ -278,6 +295,13 @@ public class SqlDBReaderWriter { LOG.warn("problem closing sql statement: ", e); } } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + LOG.warn("problem closing sql connection: ", e); + } + } } return affectedRows; } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBStatusReader.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBStatusReader.java index 75d8c9ad2..d98d36d7c 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBStatusReader.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBStatusReader.java @@ -61,6 +61,9 @@ public class SqlDBStatusReader { long minorCount = 0; long warningCount = 0; ResultSet data; + if(LOG.isTraceEnabled()){ + LOG.trace("query={}", selectQuery); + } try { data = this.dbClient.read(selectQuery); String severity; @@ -92,6 +95,9 @@ public class SqlDBStatusReader { long connectedCount = 0, connectingCount = 0, disconnectedCount = 0, mountedCount = 0, unableToConnectCount = 0, undefinedCount = 0, unmountedCount = 0; long cnt; + if(LOG.isTraceEnabled()){ + LOG.trace("query={}", selectQuery); + } try { data = this.dbClient.read(selectQuery); while (data.next()) { diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RegexSqlDBFilter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RegexSqlDBFilter.java index 65e0c54e4..bc888df50 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RegexSqlDBFilter.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RegexSqlDBFilter.java @@ -30,7 +30,7 @@ public class RegexSqlDBFilter extends DBKeyValuePair implements SqlDBFil @Override public String getFilterExpression() { - return String.format("`%s` RLIKE '%s'", this.getKey(), this.getValue()); + return String.format("`%s` RLIKE '^%s$'", this.getKey(), this.getValue()); } @Override -- cgit 1.2.3-korg