aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/dblib/src/main
diff options
context:
space:
mode:
authorMichael Dürre <michael.duerre@highstreet-technologies.com>2022-08-31 08:46:55 +0200
committerDan Timoney <dtimoney@att.com>2022-08-31 21:04:07 +0000
commit34f89faa64f815d5cf33d0905046eaf392017b39 (patch)
tree7bd6295609feb87b3fa187602985b58e34965fe4 /sdnr/wt/data-provider/dblib/src/main
parent63d92319b01b54d72bde494f923f80eb6c242cfe (diff)
add fixes for wt sulfur
fix devmgrs and db access Issue-ID: CCSDK-3749 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com> Change-Id: I41018d2daa55b200a9ba89e784f8adf4200d32c3 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/dblib/src/main')
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java11
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java30
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBStatusReader.java6
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RegexSqlDBFilter.java2
4 files changed, 45 insertions, 4 deletions
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<T extends DataObject> {
}
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<T extends DataObject> {
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<T extends DataObject> {
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<T extends DataObject> {
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<T extends DataObject> {
}
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<T extends DataObject> {
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<String> 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