diff options
author | Michael DÜrre <michael.duerre@highstreet-technologies.com> | 2022-03-10 10:39:16 +0100 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2022-03-23 15:08:48 -0400 |
commit | eb2a7c97c0007b013bd1784ac17d57be02b63d03 (patch) | |
tree | b0861438532727219216cfd426e21ae053abb31a /sdnr/wt/data-provider/dblib | |
parent | 3c74361514bb920ed441d105f66ca978bd074ced (diff) |
migrate sdnr features to phosphorus
fix mapper and switch to dom api
Updated to use phosphorus version of parent poms
Issue-ID: CCSDK-3566
Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Change-Id: I98c5bef9286622e0d66b53db687557d798cd53f5
Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/dblib')
25 files changed, 517 insertions, 194 deletions
diff --git a/sdnr/wt/data-provider/dblib/pom.xml b/sdnr/wt/data-provider/dblib/pom.xml index e4bc57519..b1dd4ff04 100644 --- a/sdnr/wt/data-provider/dblib/pom.xml +++ b/sdnr/wt/data-provider/dblib/pom.xml @@ -28,7 +28,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> - <version>2.3.2</version> + <version>2.3.3-SNAPSHOT</version> <relativePath/> </parent> 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 ce9d4dcd1..1ed0b5f17 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 @@ -56,7 +56,6 @@ public class SqlDBClient { private static final String DBVERSION_REGEX = "^([\\d]+\\.[\\d]+\\.[\\d]+)"; private static final Pattern DBVERSION_PATTERN = Pattern.compile(DBVERSION_REGEX); private static final String SELECT_VERSION_QUERY = "SELECT @@version as version"; - private static final String LOG_PROBLEM_CLOSING_CONNECTION = "problem closing connection: "; private static final String DBNAME_DEFAULT = "sdnrdb"; private final String dbConnectionString; @@ -100,6 +99,7 @@ public class SqlDBClient { } catch (SQLException e) { LOG.warn("problem reading views: ", e); } + try { data.close(); } catch (SQLException ignore) { } return list; } @@ -114,6 +114,7 @@ public class SqlDBClient { } catch (SQLException e) { LOG.warn("problem reading tables: ", e); } + try { data.close(); } catch (SQLException ignore) { } return list; } @@ -155,22 +156,18 @@ public class SqlDBClient { public boolean createTable(String query) { boolean result = false; PreparedStatement stmt = null; + Connection connection = null; try { - Connection connection = this.getConnection(); + connection = this.getConnection(); stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); stmt.execute(); - connection.close(); + result = true; } catch (SQLException e) { LOG.warn("problem creating table:", e); } finally { - if (stmt != null) { - try { - stmt.close(); - } catch (SQLException e) { - LOG.warn("problem closing stmt:", e); - } - } + if (stmt != null) try { stmt.close(); } catch (SQLException logOrIgnore) {} + if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} } return result; } @@ -199,20 +196,17 @@ public class SqlDBClient { boolean result = false; SQLException innerE = null; Statement stmt = null; - try (Connection connection = this.getConnection()) { + Connection connection = null; + try { + connection= this.getConnection(); stmt = connection.createStatement(); result = stmt.execute(query); result = stmt.getUpdateCount() > 0 ? stmt.getUpdateCount() > 0 : result; } catch (SQLException e) { innerE = e; } finally { - try { - if (stmt != null) { - stmt.close(); - } - } catch (SQLException e) { - LOG.warn(LOG_PROBLEM_CLOSING_CONNECTION, e); - } + if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {} + if (connection != null) try { connection.close(); } catch (SQLException ignore) {} } if (innerE != null) { throw innerE; @@ -224,20 +218,17 @@ public class SqlDBClient { boolean result = false; SQLException innerE = null; PreparedStatement stmt = null; - try (Connection connection = this.getConnection()) { + Connection connection = null; + try { + connection = this.getConnection(); stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); result = stmt.execute(); result = stmt.getUpdateCount() > 0 ? stmt.getUpdateCount() > 0 : result; } catch (SQLException e) { innerE = e; } finally { - try { - if (stmt != null) { - stmt.close(); - } - } catch (SQLException e) { - LOG.warn(LOG_PROBLEM_CLOSING_CONNECTION, e); - } + if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {} + if (connection != null) try { connection.close(); } catch (SQLException ignore) {} } if (innerE != null) { throw innerE; @@ -249,24 +240,22 @@ public class SqlDBClient { String result = null; SQLException innerE = null; PreparedStatement stmt = null; - try (Connection connection = this.getConnection()) { + ResultSet generatedKeys = null; + Connection connection = null; + try { + connection = this.getConnection(); stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); stmt.execute(); - ResultSet generatedKeys = stmt.getGeneratedKeys(); + generatedKeys = stmt.getGeneratedKeys(); if (generatedKeys.next()) { result = String.valueOf(generatedKeys.getLong(1)); } } catch (SQLException e) { innerE = e; } finally { - try { - if (stmt != null) { - stmt.close(); - } - - } catch (SQLException e) { - LOG.warn(LOG_PROBLEM_CLOSING_CONNECTION, e); - } + if (generatedKeys != null) try { generatedKeys.close(); } catch (SQLException ignore) {} + if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {} + if (connection != null) try { connection.close(); } catch (SQLException ignore) {} } if (innerE != null) { throw innerE; @@ -291,19 +280,16 @@ public class SqlDBClient { public ResultSet read(String query) { ResultSet data = null; Statement stmt = null; - try (Connection connection = this.getConnection()) { + Connection connection = null; + try{ + connection = this.getConnection(); stmt = connection.createStatement(); data = stmt.executeQuery(query); } catch (SQLException e) { LOG.warn("problem reading db for query '{}': ", query, e); } finally { - try { - if (stmt != null) { - stmt.close(); - } - } catch (SQLException e) { - LOG.warn(LOG_PROBLEM_CLOSING_CONNECTION, e); - } + if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {} + if (connection != null) try { connection.close(); } catch (SQLException ignore) {} } return data; } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerBase.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerBase.java index 60f28d95c..e015dd29f 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerBase.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerBase.java @@ -74,7 +74,7 @@ public abstract class HtUserdataManagerBase implements HtUserdataManager { @Override public boolean setUserdata(String username, String key, String data) { - JSONObject o = new JSONObject(); + JSONObject o = new JSONObject(this.getUserdata(username)); o.put(key, new JSONObject(data)); return this.setUserdata(username, o.toString()); } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerImpl.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerImpl.java index 79d963751..832d473c2 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerImpl.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerImpl.java @@ -21,16 +21,7 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data; -import java.util.Arrays; -import java.util.List; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriterUserdata; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.PaginationBuilder; -import org.opendaylight.yangtools.yang.common.Uint32; -import org.opendaylight.yangtools.yang.common.Uint64; public class HtUserdataManagerImpl extends HtUserdataManagerBase { @@ -42,7 +33,9 @@ public class HtUserdataManagerImpl extends HtUserdataManagerBase { @Override public boolean setUserdata(String username, String data) { - return this.rw.write(new UserdataBuilder().setId(username).setValue(data).build(), username) != null; + Userdata o = new UserdataBuilder().setId(username).setValue(data).build(); + String x = this.rw.updateOrInsert(o, username); + return x!=null; } @Override @@ -52,17 +45,8 @@ public class HtUserdataManagerImpl extends HtUserdataManagerBase { @Override protected String readUserdata(String username, String defaultValue) { - EntityInput input = new ReadFaultcurrentListInputBuilder() - .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(username).build())) - .setPagination(new PaginationBuilder().setPage(Uint64.valueOf(1)).setSize(Uint32.valueOf(1)).build()) - .build(); - QueryResult<Userdata> result = this.rw.getData(input); - if (result != null) { - List<Userdata> data = result.getResult(); - Userdata user = (data != null && !data.isEmpty()) ? data.get(0) : null; - return user == null ? defaultValue : user.getValue(); - } - return defaultValue; + Userdata user = this.rw.read(username); + return user!=null? user.getValue():defaultValue; } } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java index b6df73b89..1bb30dc69 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java @@ -120,11 +120,11 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa this.mediatorserverRW = new SqlDBReaderWriter<>(this.dbClient, Entity.MediatorServer, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.mediator.server.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId).setWriteInterface(MediatorServerEntity.class); + this.controllerId).setWriteInterface(MediatorServerEntity.class); this.maintenanceRW = new SqlDBReaderWriter<>(this.dbClient, Entity.Maintenancemode, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId).setWriteInterface(MaintenanceEntity.class); + this.controllerId).setWriteInterface(MaintenanceEntity.class); this.readStatus = new SqlDBStatusReader(this.dbClient, this.controllerId); @@ -137,7 +137,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa }; this.dbMaintenanceService = new HtDatabaseMaintenanceService(this); this.usermanager = new HtUserdataManagerImpl(new SqlDBReaderWriterUserdata(this.dbClient, - Entity.Userdata, config.getDbSuffix(), this.dbClient.getDatabaseName(), this.controllerId)); + Entity.Userdata, config.getDbSuffix())); if (initControllerId) { try { this.setControllerId(); @@ -512,6 +512,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa query = String.format("INSERT INTO `%s` (`id`,`desc`) VALUES ('%s','%s')", this.controllerTableName, this.controllerId, ""); LOG.trace(query); + try { data.close(); } catch (SQLException ignore) { } return this.dbClient.write(query); } else { LOG.trace("controllerId already set"); diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/DatabaseIdGenerator.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/DatabaseIdGenerator.java index 6244894e5..9d09a11c8 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/DatabaseIdGenerator.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/DatabaseIdGenerator.java @@ -74,7 +74,6 @@ public class DatabaseIdGenerator { public static String getFaultcurrentId(String nodeId, String objectId, String problemName) { String uuId = extractUuid(objectId); - return String.format(FORMAT_FAULTDATA_ID, nodeId, uuId, problemName); } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java index 88aaa583d..776c91fe5 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseEventsService.java @@ -40,6 +40,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionLogStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity; @@ -50,6 +51,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterBuilder; import org.slf4j.Logger; @@ -89,68 +91,68 @@ public class HtDatabaseEventsService implements DataProvider { this.dbClient = new SqlDBClient(config.getUrl(), config.getUsername(), config.getPassword()); this.connectionlogRW = new SqlDBReaderWriter<>(dbClient, Entity.Connectionlog, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); this.eventlogRW = new SqlDBReaderWriter<>(dbClient, Entity.Eventlog, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.eventlog.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); this.eventRWFaultLog = new SqlDBReaderWriter<>(dbClient, Entity.Faultlog, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultlog.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); this.eventRWFaultCurrent = new SqlDBReaderWriterFault<>(dbClient, Entity.Faultcurrent, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultcurrent.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); this.equipmentRW = new SqlDBReaderWriter<>(dbClient, Entity.Inventoryequipment, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); this.guicutthroughRW = new SqlDBReaderWriter<>(dbClient, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity.Guicutthrough, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.gui.cut.through.entry.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId).setWriteInterface(Guicutthrough.class); + this.controllerId).setWriteInterface(Guicutthrough.class); this.networkelementConnectionRW = new SqlDBReaderWriter<>(dbClient, Entity.NetworkelementConnection, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.network.element.connection.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); this.networkelementConnectionRW.setWriteInterface(NetworkElementConnectionEntity.class); this.pm15mRW = new SqlDBReaderWriterPm<>(dbClient, Entity.Historicalperformance15min, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); this.pm24hRW = new SqlDBReaderWriterPm<>(dbClient, Entity.Historicalperformance24h, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._24h.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); this.eventRWCMLog = new SqlDBReaderWriter<>(dbClient, Entity.Cmlog, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.Data.class, - this.dbClient.getDatabaseName(), this.controllerId); + this.controllerId); } @Override public void writeConnectionLog(ConnectionlogEntity event) { - this.connectionlogRW.write(event, event.getId()); + this.connectionlogRW.write(event, null); } @Override public void writeEventLog(EventlogEntity event) { - this.eventlogRW.write(event, event.getId()); + this.eventlogRW.write(event, null); } @Override public void writeFaultLog(FaultlogEntity fault) { - this.eventRWFaultLog.write(fault, fault.getId()); + this.eventRWFaultLog.write(fault, null); } @Override public void writeCMLog(CmlogEntity cm) { - this.eventRWCMLog.write(cm, cm.getId()); + this.eventRWCMLog.write(cm, null); } @Override public void updateFaultCurrent(FaultcurrentEntity fault) { - final String id = fault.getId() != null ? fault.getId() : DatabaseIdGenerator.getFaultcurrentId(fault); + final String id = DatabaseIdGenerator.getFaultcurrentId(fault); if (FaultEntityManager.isManagedAsCurrentProblem(fault)) { if (FaultEntityManager.isNoAlarmIndication(fault)) { LOG.debug("Remove from currentFaults: {}", fault.toString()); @@ -198,8 +200,7 @@ public class HtDatabaseEventsService implements DataProvider { @Override public int clearGuiCutThroughEntriesOfNode(String nodeName) { - this.guicutthroughRW.remove(nodeName); - return 0; + return this.guicutthroughRW.remove(nodeName); } @Override @@ -213,9 +214,28 @@ public class HtDatabaseEventsService implements DataProvider { return this.networkelementConnectionRW.updateOrInsert(ne, nodeId) != null; } + /** + * Remove network element connection if not required + * This function is called onDisconnect event for netconf node + */ @Override public void removeNetworkConnection(String nodeId) { - this.networkelementConnectionRW.remove(nodeId); + NetworkElementConnectionEntity e = this.networkelementConnectionRW.read(nodeId); + Boolean isRequired = e!=null? e.getIsRequired():null; + if (e != null && isRequired != null) { + if (isRequired) { + LOG.debug("updating connection status for {} of required ne to disconnected", nodeId); + this.networkelementConnectionRW.update(new UpdateNetworkElementConnectionInputBuilder() + .setStatus(ConnectionLogStatus.Disconnected).build(), nodeId); + } else { + LOG.debug("remove networkelement-connection for {} entry because of non-required", nodeId); + this.networkelementConnectionRW.remove(nodeId); + } + } else { + LOG.warn("Unable to update connection-status. dbentry for {} not found in networkelement-connection", + nodeId); + } + } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseMaintenanceService.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseMaintenanceService.java index a17c6ae48..8c549ded8 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseMaintenanceService.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/entity/HtDatabaseMaintenanceService.java @@ -33,8 +33,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMaintenanceInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.MaintenanceEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadNetworkElementConnectionListInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadNetworkElementConnectionListOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter; @@ -109,12 +107,7 @@ public class HtDatabaseMaintenanceService implements HtDatabaseMaintenance { @Override public MaintenanceEntity getMaintenance(@Nullable String nodeId) { - ReadMaintenanceListOutput result = this.dbProvider - .readMaintenanceList( - new ReadMaintenanceListInputBuilder().setFilter(getFilterInput("node-id", nodeId)).build()) - .build(); - final List<Data> data = result.getData(); - return data != null ? !data.isEmpty() ? data.get(0) : null : null; + return this.maintenanceRw.read(DatabaseIdGenerator.getMaintenanceId(nodeId)); } @Override diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java index c63d2f16b..19323b9f7 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java @@ -60,7 +60,7 @@ public class SqlDBMapper { private static final String ENUM_DBTYPE = "VARCHAR(100)"; private static final String BIGINT_DBTYPE = "BIGINT"; public static final String ODLID_DBCOL = "controller-id"; - private static final String ID_DBCOL = "id"; + public static final String ID_DBCOL = "id"; private static List<Class<?>> numericClasses = Arrays.asList(Byte.class, Integer.class, Long.class, BigInteger.class, Uint8.class, Uint16.class, Uint32.class, Uint64.class); private static final YangToolsMapper mapper = new YangToolsMapper(); @@ -78,18 +78,19 @@ public class SqlDBMapper { } public static <T> String createTable(Class<T> clazz, Entity e) throws UnableToMapClassException { - return createTable(clazz, e, "", false); + return createTable(clazz, e, "", false, true); } public static <T> String createTable(Class<T> clazz, Entity e, String suffix) throws UnableToMapClassException { - return createTable(clazz, e, suffix, false); + return createTable(clazz, e, suffix, false, true); } public static <T> String createTable(Class<T> clazz, Entity e, boolean autoIndex) throws UnableToMapClassException { - return createTable(clazz, e, "", false); + return createTable(clazz, e, "", false, true); } - public static <T> String createTable(Class<T> clazz, Entity e, String suffix, boolean autoIndex) + public static <T> String createTable(Class<T> clazz, Entity e, String suffix, boolean autoIndex, + boolean withControllerId) throws UnableToMapClassException { StringBuilder sb = new StringBuilder(); sb.append("CREATE TABLE IF NOT EXISTS `" + e.getName() + suffix + "` (\n"); @@ -99,7 +100,9 @@ public class SqlDBMapper { } else { sb.append("`" + ID_DBCOL + "` " + STRING_DBTYPE + " " + getColumnOptions(ID_DBCOL, STRING_DBTYPE) + ",\n"); } - sb.append("`" + ODLID_DBCOL + "` " + ODLID_DBTYPE + " " + getColumnOptions(ODLID_DBCOL, ODLID_DBTYPE) + ",\n"); + if(withControllerId) { + sb.append("`" + ODLID_DBCOL + "` " + ODLID_DBTYPE + " " + getColumnOptions(ODLID_DBCOL, ODLID_DBTYPE) + ",\n"); + } for (Method method : getFilteredMethods(clazz, true)) { Class<?> valueType = method.getReturnType(); String colName = getColumnName(method); @@ -110,8 +113,10 @@ public class SqlDBMapper { String options = getColumnOptions(colName, dbType); sb.append("`" + colName + "` " + dbType + " " + options + ",\n"); } - sb.append("primary key(" + ID_DBCOL + "),"); - sb.append("foreign key(`" + ODLID_DBCOL + "`) references " + TABLENAME_CONTROLLER + "(" + ID_DBCOL + ")"); + sb.append("primary key(" + ID_DBCOL + ")"); + if(withControllerId) { + sb.append(",foreign key(`" + ODLID_DBCOL + "`) references " + TABLENAME_CONTROLLER + "(" + ID_DBCOL + ")"); + } sb.append(");"); return sb.toString(); @@ -350,11 +355,14 @@ public class SqlDBMapper { public static <T> List<T> read(ResultSet data, Class<T> clazz, String column) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SQLException, InstantiationException, SecurityException, NoSuchMethodException, JsonProcessingException { - + if(data==null) { + return Arrays.asList(); + } Builder<T> builder = findPOJOBuilder(clazz); if(builder==null && column==null) { throw new InstantiationException("unable to find builder for class "+clazz.getName()); } + List<T> list = new ArrayList<>(); while (data.next()) { if (column == null) { 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 b5322d6ff..56e965c9f 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 @@ -57,34 +57,47 @@ public class SqlDBReaderWriter<T extends DataObject> { protected final Entity entity; private final Class<T> clazz; protected final SqlDBClient dbService; - private final String dbName; protected final String controllerId; protected final String tableName; + private final boolean ignoreControllerId; - public SqlDBReaderWriter(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String dbName, + public SqlDBReaderWriter(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String controllerId) { + this(dbService, e, dbSuffix, clazz, controllerId, false); + } + + public SqlDBReaderWriter(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, + String controllerId, boolean ignoreControllerId) { this.dbService = dbService; this.entity = e; this.clazz = clazz; - this.dbName = dbName; this.tableName = this.entity.getName() + dbSuffix; this.controllerId = controllerId; + this.ignoreControllerId = ignoreControllerId; } public long count(List<Filter> filter) throws SQLException { String query; if (filter == null || filter.isEmpty()) { - query = String.format("SELECT table_rows FROM `information_schema`.`tables` " - + "WHERE `table_schema` = '%s' AND `table_name` = '%s'", this.dbName, this.tableName); + // query = String.format("SELECT table_rows FROM `information_schema`.`tables` " + // + "WHERE `table_schema` = '%s' AND `table_name` = '%s'", this.dbName, this.tableName); + query = String.format("SELECT COUNT(`id`) FROM `%s`", this.tableName); } else { query = String.format("SELECT COUNT(`id`) FROM `%s` %s", this.tableName, SqlQuery.getWhereExpression(filter)); } ResultSet data = this.dbService.read(query); + if(data==null) { + return 0; + } long cnt = 0; if (data.next()) { cnt = data.getLong(1); } + try { + data.close(); + } catch (SQLException ignore) { + } return cnt; } @@ -106,11 +119,19 @@ public class SqlDBReaderWriter<T extends DataObject> { public QueryResult<T> getData(EntityInput input) { SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId); - LOG.trace("query={}", query.toSql()); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } try { ResultSet data = this.dbService.read(query.toSql()); List<T> mappedData = SqlDBMapper.read(data, clazz); final Map<FilterKey, Filter> filter = input.getFilter(); + try { + if(data!=null) { + data.close(); + } + } catch (SQLException ignore) { + } long total = this.count(filter != null ? new ArrayList<>(filter.values()) : null, this.controllerId); return new QueryResult<T>(mappedData, query.getPage(), query.getPageSize(), total); } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException @@ -126,8 +147,11 @@ public class SqlDBReaderWriter<T extends DataObject> { if (id == null) { return this.writeWithoutId(object); } - InsertQuery<S> query = new InsertQuery<S>(this.entity, object, this.controllerId); + InsertQuery<S> query = new InsertQuery<S>(this.entity, object, this.controllerId, this.ignoreControllerId); query.setId(id); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } boolean success = false; try { success = this.dbService.write(query.toSql()); @@ -140,7 +164,11 @@ public class SqlDBReaderWriter<T extends DataObject> { private <S extends DataObject> String writeWithoutId(S object) { - InsertQuery<S> query = new InsertQuery<S>(this.entity, object, this.controllerId); + InsertQuery<S> query = + new InsertQuery<S>(this.entity, object, this.controllerId, this.ignoreControllerId, true); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } try { return this.dbService.writeAndReturnId(query.toSql()); } catch (SQLException e) { @@ -150,8 +178,11 @@ public class SqlDBReaderWriter<T extends DataObject> { } public <S extends DataObject> String update(S object, String id) { - UpdateQuery<S> query = new UpdateQuery<S>(this.entity, object, this.controllerId); + UpdateQuery<S> query = new UpdateQuery<S>(this.entity, object, this.controllerId, this.ignoreControllerId, true); query.setId(id); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } String insertedId = null; PreparedStatement stmt = null; try { @@ -164,6 +195,9 @@ public class SqlDBReaderWriter<T extends DataObject> { if (affectedRows > 0) { insertedId = id; } + if (LOG.isTraceEnabled()) { + LOG.trace("insertedid={}", insertedId); + } } catch (SQLException e) { LOG.warn("problem writing data into db: ", e); } finally { @@ -180,10 +214,12 @@ public class SqlDBReaderWriter<T extends DataObject> { } public <S extends DataObject> String updateOrInsert(S object, String id) { - UpsertQuery<S> query = new UpsertQuery<S>(this.entity, object, this.controllerId); + UpsertQuery<S> query = new UpsertQuery<S>(this.entity, object, this.controllerId, this.ignoreControllerId, true); query.setId(id); String insertedId = null; - LOG.trace("query={}", query.toSql()); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } PreparedStatement stmt = null; try { Connection connection = this.dbService.getConnection(); @@ -221,6 +257,9 @@ public class SqlDBReaderWriter<T extends DataObject> { public int remove(List<Filter> filters) { DeleteQuery query = new DeleteQuery(this.entity, filters); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } int affectedRows = 0; PreparedStatement stmt = null; try { @@ -249,9 +288,16 @@ public class SqlDBReaderWriter<T extends DataObject> { public <S extends DataObject> List<S> readAll(Class<S> clazz) { SelectQuery query = new SelectQuery(this.tableName); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } try { ResultSet data = this.dbService.read(query.toSql()); List<S> mappedData = SqlDBMapper.read(data, clazz); + try { + data.close(); + } catch (SQLException ignore) { + } return mappedData; } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { @@ -262,9 +308,16 @@ public class SqlDBReaderWriter<T extends DataObject> { public List<String> readAll(String key) { SelectQuery query = new SelectQuery(this.tableName, key, this.controllerId).groupBy(key); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } try { ResultSet data = this.dbService.read(query.toSql()); List<String> mappedData = SqlDBMapper.read(data, String.class, key); + try { + data.close(); + } catch (SQLException ignore) { + } return mappedData; } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { @@ -272,4 +325,22 @@ public class SqlDBReaderWriter<T extends DataObject> { } return null; } + + public T read(String id) { + SelectQuery query = + new SelectQuery(this.tableName, this.controllerId).addFilter(SqlDBMapper.ID_DBCOL, id); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } + T item = null; + try { + ResultSet data = this.dbService.read(query.toSql()); + List<T> mappedData = SqlDBMapper.read(data, clazz); + item = mappedData.size()>0? mappedData.get(0): null; + } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { + LOG.warn("problem reading data {}: ", this.entity, e); + } + return item; + } } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterFault.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterFault.java index 2d4e26eea..86d888a16 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterFault.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterFault.java @@ -30,9 +30,9 @@ public class SqlDBReaderWriterFault<T extends DataObject> extends SqlDBReaderWri private static final String NODE_KEY = "node-id"; - public SqlDBReaderWriterFault(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String dbName, + public SqlDBReaderWriterFault(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String controllerId) { - super(dbService, e, dbSuffix, clazz, dbName, controllerId); + super(dbService, e, dbSuffix, clazz, controllerId); } public List<String> getAllNodes() { diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterPm.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterPm.java index 021741bd8..22aabc429 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterPm.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterPm.java @@ -53,9 +53,9 @@ public class SqlDBReaderWriterPm<T extends DataObject> extends SqlDBReaderWriter private static final FilterKey FILTERKEY = new FilterKey(KEY); - public SqlDBReaderWriterPm(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String dbName, + public SqlDBReaderWriterPm(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String controllerId) { - super(dbService, e, dbSuffix, clazz, dbName, controllerId); + super(dbService, e, dbSuffix, clazz, controllerId); } /** @@ -83,6 +83,7 @@ public class SqlDBReaderWriterPm<T extends DataObject> extends SqlDBReaderWriter try { ResultSet data = this.dbService.read(query.toSql()); List<String> mappedData = SqlDBMapper.read(data, String.class, UUID_KEY); + try { data.close(); } catch (SQLException ignore) { } Map<FilterKey, Filter> inpFilter = input.getFilter(); long total = this.count(inpFilter != null ? new ArrayList<>(inpFilter.values()) : null, this.controllerId); return new QueryResult<>(mappedData, query.getPage(), query.getPageSize(), total); @@ -114,6 +115,7 @@ public class SqlDBReaderWriterPm<T extends DataObject> extends SqlDBReaderWriter try { ResultSet data = this.dbService.read(query.toSql()); List<String> mappedData = SqlDBMapper.read(data, String.class, NODE_KEY); + try { data.close(); } catch (SQLException ignore) { } Map<FilterKey, Filter> inpFilter = input.getFilter(); long total = this.count(inpFilter != null ? new ArrayList<>(inpFilter.values()) : null, this.controllerId); return new QueryResult<>(mappedData, query.getPage(), query.getPageSize(), total); diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java index 2c849ac67..258cd160f 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java @@ -27,11 +27,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro public class SqlDBReaderWriterUserdata extends SqlDBReaderWriter<Userdata> { - public SqlDBReaderWriterUserdata(SqlDBClient dbService, Entity e, String dbSuffix, String dbName, - String controllerId) { - super(dbService, e, dbSuffix, Userdata.class, dbName, controllerId); + public SqlDBReaderWriterUserdata(SqlDBClient dbService, Entity e, String dbSuffix) { + super(dbService, e, dbSuffix, Userdata.class, null, true); } + } 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 c98ba388d..b0b169d18 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 @@ -74,6 +74,7 @@ public class SqlDBStatusReader { } } + try { data.close(); } catch (SQLException ignore) { } } catch (SQLException e) { LOG.warn("problem reading status:", e); } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/CountQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/CountQuery.java index c499fefb8..1c1ec622b 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/CountQuery.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/CountQuery.java @@ -59,7 +59,7 @@ public class CountQuery implements SqlQuery { this(e); Map<FilterKey, Filter> filter = input != null ? input.getFilter() : null; if (filter != null && filter.size() > 0) { - this.filters.addAll(filters); + this.filters.addAll(filter.values()); } if (controllerId != null) { this.addFilter(SqlDBMapper.ODLID_DBCOL, controllerId); diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java index 108888ad0..f52fbd55a 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java @@ -39,17 +39,28 @@ public class InsertQuery<T extends DataObject> implements SqlQuery { protected final Entity entity; private final String controllerId; + private final boolean ignoreControllerId; private final T object; private final boolean ignoreNull; private String id; + private final boolean ignoreIdField; public InsertQuery(Entity e, T object, String controllerId) { + this(e, object, controllerId, SqlQuery.DEFAULT_IGNORE_CONTROLLERID); + } + + public InsertQuery(Entity e, T object, String controllerId, boolean ignoreControllerId) { + this(e, object, controllerId, ignoreControllerId, SqlQuery.DEFAULT_IGNORE_ID_FIELD); + } + + public InsertQuery(Entity e, T object, String controllerId, boolean ignoreControllerId, boolean ignoreIdField) { this.entity = e; this.controllerId = controllerId; this.object = object; this.ignoreNull = true; this.id = null; - + this.ignoreControllerId = ignoreControllerId; + this.ignoreIdField = ignoreIdField; } @Override @@ -63,8 +74,8 @@ public class InsertQuery<T extends DataObject> implements SqlQuery { return null; } - protected String toSqlWithError() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, - JsonProcessingException { + protected String toSqlWithError() throws IllegalAccessException, IllegalArgumentException, + InvocationTargetException, JsonProcessingException { Class<?> cls = this.object.getClass(); List<DBKeyValuePair<String>> kvps = new ArrayList<>(); List<String> cols = new ArrayList<>(); @@ -78,26 +89,37 @@ public class InsertQuery<T extends DataObject> implements SqlQuery { m.setAccessible(true); value = m.invoke(this.object); col = SqlDBMapper.getColumnName(m); - if (col.equals("id") && this.id != null) { - value = this.id; + if (col.equals("id")) { + if (this.ignoreIdField) { + continue; + } + if (this.id != null) { + value = this.id; + } } if (ignoreNull && value == null) { continue; } - DBKeyValuePair<String> kvp = SqlDBMapper.getEscapedKeyValue(m,col, value); + DBKeyValuePair<String> kvp = SqlDBMapper.getEscapedKeyValue(m, col, value); cols.add(kvp.getKey()); args.add(kvp.getValue()); kvps.add(kvp); } if (this.id != null && !cols.contains("`id`")) { cols.add("`id`"); - args.add("'"+this.id+"'"); + args.add("'" + this.id + "'"); + } + if (!this.ignoreControllerId) { + args.add("'" + this.controllerId + "'"); + } + sb.append(String.join(",", cols)); + if (!this.ignoreControllerId) { + sb.append(",`" + SqlDBMapper.ODLID_DBCOL + "`) VALUES ("); + } else { + sb.append(") VALUES ("); } - args.add("'"+this.controllerId+"'"); - sb.append( String.join(",", cols)); - sb.append(",`" + SqlDBMapper.ODLID_DBCOL + "`) VALUES ("); - sb.append( String.join(",", args)+" )"); - this.appendAdditionalToQuery(sb,kvps); + sb.append(String.join(",", args) + " )"); + this.appendAdditionalToQuery(sb, kvps); return sb.toString(); } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java index 2b3f9f3fa..6403a5c1d 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java @@ -54,9 +54,11 @@ public class SelectQuery implements SqlQuery { private final List<String> groups; public SelectQuery(String tableName) { - this(tableName, Arrays.asList("*"), null); + this(tableName, (String)null); + } + public SelectQuery(String tableName, String controllerId) { + this(tableName, Arrays.asList("*"), controllerId); } - public SelectQuery(String tableName, List<String> fields, String controllerId) { this.tableName = tableName; this.fields = fields; @@ -105,18 +107,21 @@ public class SelectQuery implements SqlQuery { } - public void addFilter(String property, String filtervalue) { + public SelectQuery addFilter(String property, String filtervalue) { this.addFilter(new FilterBuilder().setProperty(property).setFiltervalue(filtervalue).build()); + return this; } private static Filter cleanFilter(Filter filter) { - if (filter.getFiltervalue() != null - && (filter.getFiltervalues() == null || filter.getFiltervalues().isEmpty())) { + final String sFilter = filter.getFiltervalue(); + final List<String> sFilters = filter.getFiltervalues(); + //if only single filter value is set + if (sFilter != null && (sFilters == null || sFilter.isEmpty())) { return "*".equals(filter.getFiltervalue()) ? null : filter; } else { List<String> list = new ArrayList<>(filter.getFiltervalues()); - if (filter.getFiltervalue() != null && !filter.getFiltervalue().isEmpty()) { - list.add(filter.getFiltervalue()); + if (sFilter != null && !sFilter.isEmpty()) { + list.add(sFilter); } if (list.size() == 1 && "*".equals(list.get(0))) { return null; diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java index 82f10b1e5..3e26d0935 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java @@ -27,6 +27,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.TimeZone; +import java.util.stream.Collectors; import org.eclipse.jdt.annotation.Nullable; import org.onap.ccsdk.features.sdnr.wt.common.database.data.DbFilter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.DBFilterKeyValuePair; @@ -46,12 +47,15 @@ public interface SqlQuery { static final String MARIADB_TIMESTAMP_REPLACER_MIN = "0000-00-00 00:00:00"; static final int MARIADB_TIMESTAMP_REPLACER_MIN_LENGTH = MARIADB_TIMESTAMP_REPLACER_MIN.length(); static final int MARIADB_TIMESTAMP_REPLACER_MAX_LENGTH = MARIADB_TIMESTAMP_REPLACER.length(); + static final boolean DEFAULT_IGNORE_CONTROLLERID = false; + static final boolean DEFAULT_IGNORE_ID_FIELD = false; public static String getWhereExpression(List<Filter> filters) { if (filters == null) { return ""; } StringBuilder sb = new StringBuilder(); + filters = filters.stream().filter(e -> !"*".equals(e.getFiltervalue())).collect(Collectors.toList()); if (!filters.isEmpty()) { sb.append(" WHERE (" + getFilterExpression(filters.get(0)) + ")"); @@ -64,7 +68,8 @@ public interface SqlQuery { public static String getFilterExpression(Filter filter) { String property = filter.getProperty(); - List<String> values = collectValues(filter.getFiltervalue(), filter.getFiltervalues()); + List<String> values = collectValues(filter.getFiltervalue(), filter.getFiltervalues()).stream() + .filter(e -> !"*".equals(e)).collect(Collectors.toList()); if (values.size() == 1) { return getFilterExpression(property, values.get(0)); } else if (values.size() > 1) { @@ -225,7 +230,7 @@ public interface SqlQuery { } private static String netconfToMariaDBTimestamp(String ts) { - if(ts==null) { + if (ts == null) { return null; } String v = ts.replace("T", " ").replace("Z", ""); diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/UpdateQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/UpdateQuery.java index b47b03042..dc81161ee 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/UpdateQuery.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/UpdateQuery.java @@ -44,10 +44,10 @@ public class UpdateQuery<T extends DataObject> implements SqlQuery { private String id; public UpdateQuery(Entity e, T object) { - this(e, object, null); + this(e, object, null, SqlQuery.DEFAULT_IGNORE_CONTROLLERID, SqlQuery.DEFAULT_IGNORE_ID_FIELD); } - public UpdateQuery(Entity e, T object, String controllerId) { + public UpdateQuery(Entity e, T object, String controllerId, boolean ignoreControllerId, boolean ignoreIdField) { this.entity = e; this.controllerId = controllerId; this.object = object; diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/UpsertQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/UpsertQuery.java index e6f1e13cb..39c505454 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/UpsertQuery.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/UpsertQuery.java @@ -32,6 +32,10 @@ public class UpsertQuery<T extends DataObject> extends InsertQuery<T> { super(e, object, controllerId); } + public UpsertQuery(Entity e, T object, String controllerId, boolean ignoreControllerId, boolean ignoreIdField) { + super(e, object, controllerId, ignoreControllerId, ignoreIdField); + + } @Override protected void appendAdditionalToQuery(StringBuilder sb, List<DBKeyValuePair<String>> keyValues) { diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestCRUDMariaDB.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestCRUDMariaDB.java index ad4ab6789..1dd9f725e 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestCRUDMariaDB.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestCRUDMariaDB.java @@ -105,6 +105,7 @@ public class TestCRUDMariaDB { e.printStackTrace(); fail("unable to read size"); } + try { data.close(); } catch (SQLException ignore) { } //create entry success = false; try { @@ -125,6 +126,7 @@ public class TestCRUDMariaDB { e.printStackTrace(); fail("unable to verify write"); } + try { data.close(); } catch (SQLException ignore) { } //update entry success = false; try { @@ -145,6 +147,7 @@ public class TestCRUDMariaDB { e.printStackTrace(); fail("unable to verify write"); } + try { data.close(); } catch (SQLException ignore) { } //delete entry success = false; try { @@ -161,6 +164,7 @@ public class TestCRUDMariaDB { e.printStackTrace(); fail("unable to verify delete. size>0"); } + try { data.close(); } catch (SQLException ignore) { } } @Test diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestMariaDataProvider.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestMariaDataProvider.java index b4e0584b0..c9cf27c68 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestMariaDataProvider.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestMariaDataProvider.java @@ -24,6 +24,8 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; import java.sql.SQLException; @@ -34,14 +36,17 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.SqlDBDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.DeleteQuery; import org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test.util.MariaDBTestBase; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper; import org.opendaylight.netconf.shaded.sshd.common.util.io.IoUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; @@ -57,6 +62,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateNetworkElementConnectionOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMaintenanceInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMaintenanceInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMediatorServerInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMediatorServerInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteNetworkElementConnectionInput; @@ -72,6 +80,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.MaintenanceEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; @@ -90,10 +99,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mDeviceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mLtpListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hDeviceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hLtpListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadStatusOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMaintenanceInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMaintenanceInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMediatorServerInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMediatorServerInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInput; @@ -102,6 +115,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.PaginationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.network.element.connection.list.output.Data; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; import ch.vorburger.exec.ManagedProcessException; @@ -112,6 +126,8 @@ public class TestMariaDataProvider { private static final String NODEID1 = "node1"; private static final String NODEID2 = "node2"; private static final String NODEID3 = "node3"; + private static final String NODEID4 = "node4"; + private static final String NODEID5 = "node5"; private static final String PROBLEM1 = "problem1"; private static final String TIME1 = "2021-05-25T05:12:55.0Z"; private static final String TIME2 = "2021-05-25T05:12:56.0Z"; @@ -121,6 +137,7 @@ public class TestMariaDataProvider { private static final String URI2 = "http://localhost:8181"; private static final String URI3 = "http://localhost:8181"; private static final String PATH = "https://samsung.com/3GPP/simulation/network-function/ves"; + private static final String USERNAME = "admin"; private static MariaDBTestBase testBase; private static SqlDBDataProvider dbProvider; private static SqlDBClient dbClient; @@ -176,12 +193,43 @@ public class TestMariaDataProvider { assertEquals(1, status.getData().get(0).getFaults().getMinors().intValue()); assertEquals(0, status.getData().get(0).getFaults().getWarnings().intValue()); + List<String> nodeList = dbProvider.getAllNodesWithCurrentAlarms(); + assertTrue(nodeList.contains(NODEID1)); + assertEquals(1,nodeList.size()); + faultCurrent1 = new FaultcurrentBuilder().setNodeId(NODEID1).setCounter(1).setObjectId("obj") .setProblem(PROBLEM1).setTimestamp(DateAndTime.getDefaultInstance(TIME1)) .setSeverity(SeverityType.NonAlarmed).setId(String.format("%s/%s", NODEID1, PROBLEM1)).build(); dbProvider.updateFaultCurrent(faultCurrent1); faultCurrents = dbProvider.readFaultCurrentList(createInput("node-id", NODEID1, 1, 20)); assertEquals(1, faultCurrents.getData().size()); + + + } + + @Test + public void testSerializeDeserialize() { + + try { + CreateNetworkElementConnectionOutputBuilder necon = dbProvider.createNetworkElementConnection( + new NetworkElementConnectionBuilder().setNodeId(NODEID1).setIsRequired(Boolean.TRUE).build()); + List<Data> netestList = + dbProvider.readNetworkElementConnectionList(createInput("node-id", NODEID1, 1, 20)).getData(); + + assertNotNull(necon); + assertEquals(1, netestList.size()); + assertTrue(netestList.get(0).getIsRequired()); + SqlDBReaderWriter<Data> dbrw = new SqlDBReaderWriter<>(dbClient, Entity.NetworkelementConnection, + MariaDBTestBase.SUFFIX, + Data.class, + CONTROLLERID); + Data e = dbrw.read(NODEID1); + assertNotNull(e); + + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } } @Test @@ -204,6 +252,7 @@ public class TestMariaDataProvider { dbProvider.writeFaultLog(fault2); faultlogs = dbProvider.readFaultLogList(createInput("node-id", NODEID1, 1, 20)); assertEquals(2, faultlogs.getData().size()); + } @Test @@ -211,28 +260,16 @@ public class TestMariaDataProvider { ReadCmlogListOutputBuilder cmlogs = dbProvider.readCMLogList(createInput(1, 20)); assertEquals(0, cmlogs.getData().size()); - CmlogEntity cm1 = new CmlogBuilder() - .setNodeId(NODEID2) - .setCounter(1) - .setTimestamp(DateAndTime.getDefaultInstance(TIME1)) - .setObjectId("obj") - .setNotificationType(CmNotificationType.NotifyMOIChanges) - .setNotificationId("1") - .setSourceIndicator(CmSourceIndicator.MANAGEMENTOPERATION) - .setPath(PATH) - .setValue("pnf-registration: true") - .build(); - CmlogEntity cm2 = new CmlogBuilder() - .setNodeId(NODEID2) - .setCounter(2) - .setTimestamp(DateAndTime.getDefaultInstance(TIME2)) - .setObjectId("obj") - .setNotificationType(CmNotificationType.NotifyMOIChanges) - .setNotificationId("2") - .setSourceIndicator(CmSourceIndicator.UNKNOWN) - .setPath(PATH) - .setValue("pnf-registration: false") - .build(); + CmlogEntity cm1 = + new CmlogBuilder().setNodeId(NODEID2).setCounter(1).setTimestamp(DateAndTime.getDefaultInstance(TIME1)) + .setObjectId("obj").setNotificationType(CmNotificationType.NotifyMOIChanges) + .setNotificationId("1").setSourceIndicator(CmSourceIndicator.MANAGEMENTOPERATION).setPath(PATH) + .setValue("pnf-registration: true").build(); + CmlogEntity cm2 = + new CmlogBuilder().setNodeId(NODEID2).setCounter(2).setTimestamp(DateAndTime.getDefaultInstance(TIME2)) + .setObjectId("obj").setNotificationType(CmNotificationType.NotifyMOIChanges) + .setNotificationId("2").setSourceIndicator(CmSourceIndicator.UNKNOWN).setPath(PATH) + .setValue("pnf-registration: false").build(); dbProvider.writeCMLog(cm1); dbProvider.writeCMLog(cm2); @@ -240,10 +277,10 @@ public class TestMariaDataProvider { assertEquals(2, cmlogs.getData().size()); List<CmlogEntity> cmLogEntityList = List.of(cm1, cm2); - assertEquals("node2",cmLogEntityList.get(0).getNodeId()); - assertEquals("obj",cmLogEntityList.get(0).getObjectId()); - assertEquals(CmNotificationType.NotifyMOIChanges,cmLogEntityList.get(0).getNotificationType()); - assertEquals("2",cmLogEntityList.get(1).getNotificationId()); + assertEquals("node2", cmLogEntityList.get(0).getNodeId()); + assertEquals("obj", cmLogEntityList.get(0).getObjectId()); + assertEquals(CmNotificationType.NotifyMOIChanges, cmLogEntityList.get(0).getNotificationType()); + assertEquals("2", cmLogEntityList.get(1).getNotificationId()); } @@ -383,6 +420,45 @@ public class TestMariaDataProvider { data = dbProvider.readMaintenanceList(createInput(1, 20)); assertEquals(3, data.getData().size()); + UpdateMaintenanceInput update1 = + new UpdateMaintenanceInputBuilder().setId(NODEID1).setNodeId(NODEID1).setActive(false).build(); + try { + dbProvider.updateMaintenance(update1); + } catch (IOException e) { + e.printStackTrace(); + fail("unable to update maintenance data"); + } + data = dbProvider.readMaintenanceList(createInput("active","false",1, 20)); + assertEquals(1, data.getData().size()); + DeleteMaintenanceInput delete1 = new DeleteMaintenanceInputBuilder().setId(NODEID1).build(); + try { + dbProvider.deleteMaintenance(delete1); + } catch (IOException e) { + e.printStackTrace(); + fail("unable to delete maintenance data"); + } + data = dbProvider.readMaintenanceList(createInput(1, 20)); + assertEquals(2, data.getData().size()); + try { + dbClient.delete(new DeleteQuery(Entity.Maintenancemode, null).toSql()); + } catch (SQLException e) { + e.printStackTrace(); + fail("problem clearing faultlog"); + } + final String nodeId = "maint_node1"; + HtDatabaseMaintenance maintenanceService = dbProvider.getHtDatabaseMaintenance(); + MaintenanceEntity e = maintenanceService.createIfNotExists(nodeId); + assertNotNull(e); + assertEquals(nodeId,e.getNodeId()); + MaintenanceEntity e2 = new CreateMaintenanceInputBuilder(e).setActive(true).build(); + e = maintenanceService.setMaintenance(e2); + assertNotNull(e); + assertEquals(nodeId,e.getNodeId()); + assertTrue(e.getActive()); + maintenanceService.deleteIfNotRequired(nodeId); + data = dbProvider.readMaintenanceList(createInput("node-id",nodeId,1, 20)); + assertEquals(0, data.getData().size()); + } @Test @@ -456,22 +532,26 @@ public class TestMariaDataProvider { NetworkElementConnectionEntity ne2 = new NetworkElementConnectionBuilder().setNodeId(NODEID2) .setHost("10.20.30.55").setPort(Uint32.valueOf(8300)).setIsRequired(false).setUsername("user") .setPassword("passwd").setStatus(ConnectionLogStatus.Connecting).build(); + NetworkElementConnectionEntity ne3 = new NetworkElementConnectionBuilder().setNodeId(NODEID3) + .setHost("10.20.30.55").setPort(Uint32.valueOf(8300)).setIsRequired(false).setUsername("user") + .setPassword("passwd").setStatus(ConnectionLogStatus.Connecting).build(); try { dbProvider.createNetworkElementConnection(ne1); dbProvider.createNetworkElementConnection(ne2); + dbProvider.updateNetworkConnection22(ne3, NODEID3); } catch (IOException e) { e.printStackTrace(); fail("problem creating neconnection"); } data = dbProvider.readNetworkElementConnectionList(createInput(1, 20)); - assertEquals(2, data.getData().size()); + assertEquals(3, data.getData().size()); NetworkElementConnectionEntity update1 = new NetworkElementConnectionBuilder() .setStatus(ConnectionLogStatus.Connected).setDeviceType(NetworkElementDeviceType.ORAN).build(); dbProvider.updateNetworkConnectionDeviceType(update1, NODEID1); data = dbProvider.readNetworkElementConnectionList(createInput("node-id", NODEID1, 1, 20)); assertEquals(1, data.getData().size()); assertEquals(NetworkElementDeviceType.ORAN, data.getData().get(0).getDeviceType()); - assertEquals(true, data.getData().get(0).isIsRequired()); + assertEquals(true, data.getData().get(0).getIsRequired()); UpdateNetworkElementConnectionInput update2 = new UpdateNetworkElementConnectionInputBuilder().setId(NODEID2) .setHost("10.20.55.44").setIsRequired(true).build(); try { @@ -483,7 +563,7 @@ public class TestMariaDataProvider { data = dbProvider.readNetworkElementConnectionList(createInput("node-id", NODEID2, 1, 20)); assertEquals(1, data.getData().size()); assertEquals("10.20.55.44", data.getData().get(0).getHost()); - assertEquals(true, data.getData().get(0).isIsRequired()); + assertEquals(true, data.getData().get(0).getIsRequired()); ReadStatusOutputBuilder status = null; try { @@ -493,10 +573,10 @@ public class TestMariaDataProvider { fail("failed to read status"); } assertEquals(1, status.getData().get(0).getNetworkElementConnections().getConnected().intValue()); - assertEquals(1, status.getData().get(0).getNetworkElementConnections().getConnecting().intValue()); + assertEquals(2, status.getData().get(0).getNetworkElementConnections().getConnecting().intValue()); assertEquals(0, status.getData().get(0).getNetworkElementConnections().getDisconnected().intValue()); assertEquals(0, status.getData().get(0).getNetworkElementConnections().getMounted().intValue()); - assertEquals(2, status.getData().get(0).getNetworkElementConnections().getTotal().intValue()); + assertEquals(3, status.getData().get(0).getNetworkElementConnections().getTotal().intValue()); assertEquals(0, status.getData().get(0).getNetworkElementConnections().getUnableToConnect().intValue()); assertEquals(0, status.getData().get(0).getNetworkElementConnections().getUndefined().intValue()); assertEquals(0, status.getData().get(0).getNetworkElementConnections().getUnmounted().intValue()); @@ -513,10 +593,40 @@ public class TestMariaDataProvider { data = dbProvider.readNetworkElementConnectionList(createInput("node-id", NODEID1, 1, 20)); assertEquals(0, data.getData().size()); data = dbProvider.readNetworkElementConnectionList(createInput(1, 20)); - assertEquals(1, data.getData().size()); + assertEquals(2, data.getData().size()); + } @Test + public void testUserdata() { + HtUserdataManager mgr = dbProvider.getUserManager(); + String userdata = mgr.getUserdata(USERNAME); + assertEquals("{}",userdata); + JSONObject o = new JSONObject(); + o.put("key1", false); + o.put("key2","value2"); + boolean result = mgr.setUserdata(USERNAME, o.toString()); + assertTrue(result); + userdata = mgr.getUserdata(USERNAME); + o = new JSONObject(userdata); + assertEquals(false,o.getBoolean("key1")); + assertEquals("value2",o.getString("key2")); + o = new JSONObject(); + o.put("enabled", true); + o.put("name","abcdef"); + result = mgr.setUserdata(USERNAME,"app1",o.toString()); + assertTrue(result); + userdata = mgr.getUserdata(USERNAME); + o = new JSONObject(userdata); + assertEquals(false,o.getBoolean("key1")); + assertEquals("value2",o.getString("key2")); + JSONObject app = o.getJSONObject("app1"); + assertNotNull(app); + assertEquals(true, app.getBoolean("enabled")); + assertEquals("abcdef", app.getString("name")); + + } + @Test public void testpm15m() { try { dbClient.delete(new DeleteQuery(Entity.Historicalperformance15min, null).toSql()); @@ -538,7 +648,7 @@ public class TestMariaDataProvider { assertEquals(10, data.getData().size()); ReadPmdata15mLtpListOutputBuilder ltpdata = null; try { - ltpdata = dbProvider.readPmdata15mLtpList(createInput("node-name","sim12600",1, 20)); + ltpdata = dbProvider.readPmdata15mLtpList(createInput("node-name", "sim12600", 1, 20)); } catch (IOException e) { e.printStackTrace(); fail("failed to read pmdata15m ltp list"); @@ -546,7 +656,7 @@ public class TestMariaDataProvider { assertEquals(3, ltpdata.getData().size()); ReadPmdata15mDeviceListOutputBuilder devicedata = null; try { - devicedata = dbProvider.readPmdata15mDeviceList(createInput(1,20)); + devicedata = dbProvider.readPmdata15mDeviceList(createInput(1, 20)); } catch (IOException e) { e.printStackTrace(); fail("failed to read pmdata15m devices list"); @@ -554,7 +664,6 @@ public class TestMariaDataProvider { assertEquals(1, devicedata.getData().size()); } - @Ignore @Test public void testpm24h() { try { @@ -573,9 +682,27 @@ public class TestMariaDataProvider { fail("failed to load pmdata24h"); } dbProvider.doWritePerformanceData(list); + data = dbProvider.readPmdata24hList(createInput(1, 20)); + assertEquals(1, data.getData().size()); + ReadPmdata24hLtpListOutputBuilder ltpdata = null; + try { + ltpdata = dbProvider.readPmdata24hLtpList(createInput("node-name", "test", 1, 20)); + } catch (IOException e) { + e.printStackTrace(); + fail("failed to read pmdata15m ltp list"); + } + assertEquals(1, ltpdata.getData().size()); + ReadPmdata24hDeviceListOutputBuilder devicedata = null; + try { + devicedata = dbProvider.readPmdata24hDeviceList(createInput(1, 20)); + } catch (IOException e) { + e.printStackTrace(); + fail("failed to read pmdata15m devices list"); + } + assertEquals(1, devicedata.getData().size()); } - private static EntityInput createInput(int page, int size) { + static EntityInput createInput(int page, int size) { return createInput(null, null, page, size); } @@ -597,7 +724,7 @@ public class TestMariaDataProvider { return String.join("\n", IoUtils.readAllLines(TestMariaDataProvider.class.getResourceAsStream(filename))); } - private static EntityInput createInput(String filter, String filterValue, int page, int size) { + static EntityInput createInput(String filter, String filterValue, int page, int size) { ReadFaultcurrentListInputBuilder builder = new ReadFaultcurrentListInputBuilder().setPagination( new PaginationBuilder().setPage(Uint64.valueOf(page)).setSize(Uint32.valueOf(size)).build()); if (filter != null && filterValue != null) { diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestQuerySyntax.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestQuerySyntax.java index 24347c7db..576a3825c 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestQuerySyntax.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestQuerySyntax.java @@ -22,12 +22,16 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.CountQuery; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery; +import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryInputBuilder; @@ -164,8 +168,8 @@ public class TestQuerySyntax { @Test public void testSelectForFilterValues() { EntityInput input = new ReadGuiCutThroughEntryInputBuilder() - .setFilter(Arrays.asList( - new FilterBuilder().setProperty("id").setFiltervalues(Arrays.asList("das", "das2")).build())) + .setFilter(YangToolsMapperHelper.toMap(Arrays.asList( + new FilterBuilder().setProperty("id").setFiltervalues(Arrays.asList("das", "das2")).build()))) .setPagination(new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1)).build()) .build(); SelectQuery query = new SelectQuery(TABLENAME1, input, CONTROLLERID); @@ -174,8 +178,8 @@ public class TestQuerySyntax { @Test public void testSelectForFilterValues2() { EntityInput input = new ReadGuiCutThroughEntryInputBuilder() - .setFilter(Arrays.asList( - new FilterBuilder().setProperty("id").setFiltervalue("*").build())) + .setFilter(YangToolsMapperHelper.toMap(Arrays.asList( + new FilterBuilder().setProperty("id").setFiltervalue("*").build()))) .setPagination(new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1)).build()) .build(); SelectQuery query = new SelectQuery(TABLENAME1, input, CONTROLLERID); @@ -185,12 +189,38 @@ public class TestQuerySyntax { @Test public void testSelectForFilterValues3() { EntityInput input = new ReadGuiCutThroughEntryInputBuilder() - .setFilter(Arrays.asList( - new FilterBuilder().setProperty("id").setFiltervalues(Arrays.asList("*","abc")).build())) + .setFilter(YangToolsMapperHelper.toMap(Arrays.asList( + new FilterBuilder().setProperty("id").setFiltervalues(Arrays.asList("*","abc")).build()))) .setPagination(new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1)).build()) .build(); SelectQuery query = new SelectQuery(TABLENAME1, input, CONTROLLERID); System.out.println(query.toSql()); assertFalse(query.toSql().contains("RLIKE")); } + @Test + public void testSelectForFilterValues4() { + EntityInput input = new ReadGuiCutThroughEntryInputBuilder() + .setFilter(YangToolsMapperHelper.toMap(Arrays.asList( + new FilterBuilder().setProperty("id").setFiltervalues(Arrays.asList("abc")).build(), + new FilterBuilder().setProperty("node-id").setFiltervalues(Arrays.asList("*")).build()))) + .setPagination(new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1)).build()) + .build(); + SelectQuery query = new SelectQuery(TABLENAME1, input, CONTROLLERID); + System.out.println(query.toSql()); + assertFalse(query.toSql().contains("RLIKE")); + } + @Test + public void testCount() { + CountQuery query = new CountQuery(Entity.Eventlog, TestMariaDataProvider.createInput(1, 20)); + String sQuery = query.toSql(); + assertNotNull(sQuery); + assertTrue(sQuery.contains("*") && sQuery.contains("COUNT") && sQuery.contains(Entity.Eventlog.getName())); + + query = new CountQuery(Entity.Eventlog, TestMariaDataProvider.createInput("node-id","abc",1, 20)); + sQuery = query.toSql(); + assertNotNull(sQuery); + assertTrue(sQuery.contains("node-id") && sQuery.contains("COUNT") && sQuery.contains(Entity.Eventlog.getName())); + + + } } diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/util/MariaDBTestBase.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/util/MariaDBTestBase.java index 3360d3ed8..aebd3328e 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/util/MariaDBTestBase.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/util/MariaDBTestBase.java @@ -34,6 +34,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.Env import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.SqlDBDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.Userdata; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper.UnableToMapClassException; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogEntity; @@ -60,6 +61,7 @@ public class MariaDBTestBase { private SqlDBConfig config; private static final Map<String, String> envDefaultValues = initEnvDefaultValues(); private static final String SDNRDBDATABASETEST = "test"; + public static final String SUFFIX = ""; public MariaDBTestBase() throws ManagedProcessException { this(new Random().nextInt(1000) + 50000); @@ -173,6 +175,7 @@ public class MariaDBTestBase { createTable(dbService, MaintenanceEntity.class, Entity.Maintenancemode, false); createTable(dbService, MediatorServerEntity.class, Entity.MediatorServer, true); createTable(dbService, NetworkElementConnectionEntity.class, Entity.NetworkelementConnection, false); + createTable(dbService, Userdata.class, Entity.Userdata, false, false); } public static boolean createTableOdl(SqlDBClient dbService) { @@ -181,11 +184,14 @@ public class MariaDBTestBase { System.out.println(createStatement); return dbService.createTable(createStatement); } - public static boolean createTable(SqlDBClient dbService, Class<?> cls, Entity entity, boolean autoIndex) { + return createTable(dbService, cls, entity, autoIndex, true); + } + public static boolean createTable(SqlDBClient dbService, Class<?> cls, Entity entity, boolean autoIndex, + boolean withControllerId) { String createStatement = null; try { - createStatement = SqlDBMapper.createTable(cls, entity, "", autoIndex); + createStatement = SqlDBMapper.createTable(cls, entity, SUFFIX, autoIndex,withControllerId); } catch (UnableToMapClassException e) { fail(e.getMessage()); } diff --git a/sdnr/wt/data-provider/dblib/src/test/resources/pmdata24h.json b/sdnr/wt/data-provider/dblib/src/test/resources/pmdata24h.json new file mode 100644 index 000000000..6b1f6b543 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/test/resources/pmdata24h.json @@ -0,0 +1,55 @@ +[ + { + "uuid-interface": "LP-MWPS-TTP-RADIO", + "granularity-period": "period-24-hours", + "suspect-interval-flag": false, + "layer-protocol-name": "MWPS", + "performance-data": { + "time-period": 86400, + "es": 0, + "ses": 0, + "cses": 0, + "unavailability": 0, + "tx-level-min": 3, + "tx-level-max": 3, + "tx-level-avg": 3, + "rx-level-min": -44, + "rx-level-max": -45, + "rx-level-avg": -44, + "time2-states": 0, + "time4-states-s": 0, + "time4-states": 0, + "time8-states": -1, + "time16-states-s": -1, + "time16-states": 0, + "time32-states": -1, + "time64-states": 86400, + "time128-states": -1, + "time256-states": -1, + "time512-states": -1, + "time512-states-l": -1, + "time1024-states": -1, + "time1024-states-l": -1, + "time2048-states": -1, + "time2048-states-l": -1, + "time4096-states": -1, + "time4096-states-l": -1, + "time8192-states": -1, + "time8192-states-l": -1, + "snir-min": -99, + "snir-max": -99, + "snir-avg": -99, + "xpd-min": -99, + "xpd-max": -99, + "xpd-avg": -99, + "rf-temp-min": -99, + "rf-temp-max": -99, + "rf-temp-avg": -99, + "defect-blocks-sum": -1 + }, + "radio-signal-id": "Test8", + "scanner-id": "PM_RADIO_24H_1", + "time-stamp": "2017-03-01T00:00:00.0+00:00", + "node-name": "test" + } +]
\ No newline at end of file |