diff options
author | Jakub Dominik <j.dominik@samsung.com> | 2021-10-14 15:12:55 +0200 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2021-11-18 13:19:44 +0000 |
commit | 98aeaac496ac868a97ce9096c1c51ce9a133992a (patch) | |
tree | e3e4a52f786f4dbe271485366f0a0c8d74edc85f /sdnr/wt/data-provider | |
parent | 5d3bfaac4bc7a8b7b030757e1f35795667915a2b (diff) |
Extend SDNC persistent service to store CM
Extend SDNC persistent service to store received CM events into Elasticsearch and MariaDB
Issue-ID: CCSDK-3497
Signed-off-by: Jakub Dominik <j.dominik@samsung.com>
Change-Id: I39983e59ef6512ad6c3864d47aebe1d615897146
Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider')
48 files changed, 1680 insertions, 281 deletions
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/DatabaseDataProvider.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/DatabaseDataProvider.java index 9d4beb71b..20b86e661 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/DatabaseDataProvider.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/DatabaseDataProvider.java @@ -5,6 +5,8 @@ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,6 +29,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMediatorserver; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput; 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.CreateMediatorServerInput; @@ -40,6 +43,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.DeleteNetworkElementConnectionOutputBuilder; 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.NetworkElementConnectionEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListOutputBuilder; @@ -72,6 +76,8 @@ public interface DatabaseDataProvider { ReadFaultlogListOutputBuilder readFaultLogList(EntityInput input); + ReadCmlogListOutputBuilder readCMLogList(EntityInput input); + ReadMaintenanceListOutputBuilder readMaintenanceList(EntityInput input); ReadMediatorServerListOutputBuilder readMediatorServerList(EntityInput input); @@ -129,4 +135,6 @@ public interface DatabaseDataProvider { HtDatabaseMediatorserver getHtDatabaseMediatorServer(); + HtUserdataManager getUserManager(); + } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBConfig.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBConfig.java index 8c7e7b1cb..ecf5f4e4a 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBConfig.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBConfig.java @@ -39,8 +39,8 @@ public class SqlDBConfig implements Configuration { private static final String DEFAULT_VALUE_DBURL = "${SDNRDBURL}"; private static final String DEFAULT_VALUE_DBUSERNAME = "${SDNRDBUSERNAME}"; private static final String DEFAULT_VALUE_DBPASSWORD = "${SDNRDBPASSWORD}"; - private static final String DEFAULT_VALUE_CONTROLLERID = DatabaseIdGenerator.getControllerId(); - private static final String DEFAULT_VALUE_DBSUFFIX = "-v6"; + private static final String DEFAULT_VALUE_CONTROLLERID = "${SDNRCONTROLLERID}"; + private static final String DEFAULT_VALUE_DBSUFFIX = "-v7"; private final ConfigurationFileRepresentation configuration; @@ -99,6 +99,12 @@ public class SqlDBConfig implements Configuration { DEFAULT_VALUE_CONTROLLERID); configuration.setPropertyIfNotAvailable(SECTION_MARKER_MARIADB, PROPERTY_KEY_DBSUFFIX, DEFAULT_VALUE_DBSUFFIX); + String v = this.configuration.getProperty(SECTION_MARKER_MARIADB, PROPERTY_KEY_CONTROLLERID); + // if is set to "null" then it is valid, otherwise if not set or env is empty generate one + if (!"null".equals(v) && (v == null || v.isEmpty())) { + this.setControllerId(DatabaseIdGenerator.getControllerId()); + } + } 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 new file mode 100644 index 000000000..60f28d95c --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/HtUserdataManagerBase.java @@ -0,0 +1,126 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class HtUserdataManagerBase implements HtUserdataManager { + + private static final Logger LOG = LoggerFactory.getLogger(HtUserdataManagerBase.class); + + private static final String USERDATA_DEFAULTS_FILENAME = "etc/userdata-defaults.json"; + private static final JSONObject USERDATA_DEFAULTS_CONTENT = loadDefaults(); + + protected static JSONObject loadDefaults() { + File f = new File(USERDATA_DEFAULTS_FILENAME); + String content; + JSONObject o = null; + if (f.exists()) { + try { + content = Files.readString(f.toPath()); + o = new JSONObject(content); + } catch (IOException e) { + LOG.warn("problem loading defaults: ", e); + } catch (JSONException e) { + LOG.warn("problem parsing defaults: ", e); + } + } + return o; + } + + protected abstract String readUserdata(String username, String defaultValue); + + @Override + public String getUserdata(String username) { + String json = this.readUserdata(username, "{}"); + if (USERDATA_DEFAULTS_CONTENT != null) { + JSONObject merge = mergeData(new JSONObject(json), USERDATA_DEFAULTS_CONTENT); + json = merge.toString(); + } + return json; + } + + @Override + public String getUserdata(String username, String key) { + JSONObject o = new JSONObject(this.getUserdata(username)); + return o.has(key) ? o.get(key).toString() : "{}"; + } + + @Override + public boolean setUserdata(String username, String key, String data) { + JSONObject o = new JSONObject(); + o.put(key, new JSONObject(data)); + return this.setUserdata(username, o.toString()); + } + + @Override + public boolean removeUserdata(String username, String key) { + JSONObject o = new JSONObject(this.getUserdata(username)); + if (o.has(key)) { + o.remove(key); + return this.setUserdata(username, o.toString()); + } + return true; + } + + protected static JSONObject mergeData(JSONObject o, String key, JSONObject subObject) { + if (!o.has(key)) { + o.put(key, subObject); + } else { + JSONObject tmp = new JSONObject(); + tmp.put(key, subObject); + o = mergeData(tmp, o); + } + return o; + } + + protected static JSONObject mergeData(JSONObject source, JSONObject target) throws JSONException { + String[] keys = JSONObject.getNames(source); + if (keys == null) { + return target; + } + for (String key : keys) { + Object value = source.get(key); + if (!target.has(key)) { + // new value for "key": + target.put(key, value); + } else { + // existing value for "key" - recursively deep merge: + if (value instanceof JSONObject) { + JSONObject valueJson = (JSONObject) value; + mergeData(valueJson, target.getJSONObject(key)); + } else { + target.put(key, value); + } + } + } + return target; + } + +} 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 9dd1adb50..79d963751 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,130 +21,48 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import org.json.JSONException; -import org.json.JSONObject; -import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; -import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; -import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HtUserdataManagerImpl implements HtUserdataManager { - - private static final Logger LOG = LoggerFactory.getLogger(HtUserdataManagerImpl.class); - - private static final String USERDATA_DEFAULTS_FILENAME = "etc/userdata-defaults.json"; - private static final JSONObject USERDATA_DEFAULTS_CONTENT = loadDefaults(); - - private static JSONObject loadDefaults() { - File f = new File(USERDATA_DEFAULTS_FILENAME); - String content; - JSONObject o = null; - if (f.exists()) { - try { - content = Files.readString(f.toPath()); - o = new JSONObject(content); - } catch (IOException e) { - LOG.warn("problem loading defaults: ", e); - } catch (JSONException e) { - LOG.warn("problem parsing defaults: ", e); - } - } - return o; - } - - - private final HtDatabaseClient dbClient; - - public HtUserdataManagerImpl(HtDatabaseClient rawClient) { - this.dbClient = rawClient; - } - - @Override - public String getUserdata(String username) { - SearchResult<SearchHit> result = this.dbClient.doReadByQueryJsonData(Entity.Userdata.getName(), - QueryBuilders.matchQuery("_id", username)); - String json = result.getHits().size() > 0 ? result.getHits().get(0).getSourceAsString() : "{}"; - if (USERDATA_DEFAULTS_CONTENT != null) { - JSONObject merge = mergeData(new JSONObject(json), USERDATA_DEFAULTS_CONTENT); - json = merge.toString(); - } - return json; - } - - @Override - public String getUserdata(String username, String key) { - JSONObject o = new JSONObject(this.getUserdata(username)); - return o.has(key) ? o.get(key).toString() : "{}"; +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 { + + private final SqlDBReaderWriterUserdata rw; + + public HtUserdataManagerImpl(SqlDBReaderWriterUserdata rw) { + this.rw = rw; } @Override public boolean setUserdata(String username, String data) { - JSONObject o = new JSONObject(this.getUserdata(username)); - JSONObject merge = mergeData(o, new JSONObject(data)); - return this.dbClient.doWriteRaw(Entity.Userdata.getName(), username, merge.toString()) != null; - } - - @Override - public boolean setUserdata(String username, String key, String data) { - JSONObject o = new JSONObject(this.getUserdata(username)); - o = mergeData(o, key, new JSONObject(data)); - return this.dbClient.doWriteRaw(Entity.Userdata.getName(), username, o.toString()) != null; + return this.rw.write(new UserdataBuilder().setId(username).setValue(data).build(), username) != null; } @Override public boolean removeUserdata(String username) { - return this.dbClient.doRemove(Entity.Userdata.getName(), username); + return this.rw.remove(username) > 0; } @Override - public boolean removeUserdata(String username, String key) { - JSONObject o = new JSONObject(this.getUserdata(username)); - if (o.has(key)) { - o.remove(key); - return this.setUserdata(username, o.toString()); - } - return true; - } - - private static JSONObject mergeData(JSONObject o, String key, JSONObject subObject) { - if (!o.has(key)) { - o.put(key, subObject); - } else { - JSONObject tmp = new JSONObject(); - tmp.put(key, subObject); - o = mergeData(tmp, o); - } - return o; - } - - private static JSONObject mergeData(JSONObject source, JSONObject target) throws JSONException { - String[] keys = JSONObject.getNames(source); - if (keys == null) { - return target; - } - for (String key : keys) { - Object value = source.get(key); - if (!target.has(key)) { - // new value for "key": - target.put(key, value); - } else { - // existing value for "key" - recursively deep merge: - if (value instanceof JSONObject) { - JSONObject valueJson = (JSONObject) value; - mergeData(valueJson, target.getJSONObject(key)); - } else { - target.put(key, value); - } - } + 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 target; + return 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 4165c85a0..b6df73b89 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 @@ -5,6 +5,8 @@ * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,11 +35,13 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.H import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.HtDatabaseMaintenanceService; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriterUserdata; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBStatusReader; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.DeleteQuery; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMediatorserver; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput; 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.CreateMediatorServerInput; @@ -54,6 +58,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.MaintenanceEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.MediatorServerEntity; 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.ReadCmlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListOutputBuilder; @@ -95,6 +100,8 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa private final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.mediator.server.list.output.Data> mediatorserverRW; private final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> maintenanceRW; private final SqlDBStatusReader readStatus; + private final HtUserdataManager usermanager; + public SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> getMaintenanceReaderWriter() { return this.maintenanceRW; @@ -107,6 +114,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa public SqlDBDataProvider(SqlDBConfig config) { this(config, true); } + public SqlDBDataProvider(SqlDBConfig config, boolean initControllerId) { super(config); @@ -128,7 +136,9 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa } }; this.dbMaintenanceService = new HtDatabaseMaintenanceService(this); - if(initControllerId) { + this.usermanager = new HtUserdataManagerImpl(new SqlDBReaderWriterUserdata(this.dbClient, + Entity.Userdata, config.getDbSuffix(), this.dbClient.getDatabaseName(), this.controllerId)); + if (initControllerId) { try { this.setControllerId(); } catch (SQLException e) { @@ -169,6 +179,19 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa } @Override + public ReadCmlogListOutputBuilder readCMLogList(EntityInput input) { + ReadCmlogListOutputBuilder outputBuilder = new ReadCmlogListOutputBuilder(); + QueryResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.Data> + result = + this.eventRWCMLog.getData(input); + outputBuilder.setData(result.getResult()); + outputBuilder.setPagination( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.PaginationBuilder( + result.getPagination()).build()); + return outputBuilder; + } + + @Override public ReadMaintenanceListOutputBuilder readMaintenanceList(EntityInput input) { ReadMaintenanceListOutputBuilder outputBuilder = new ReadMaintenanceListOutputBuilder(); QueryResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> result = @@ -480,18 +503,17 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa return true; } LOG.info("set controllerId {}", this.controllerId); - String query = String.format("SELECT * FROM `%s` WHERE `id`='%s';", this.controllerTableName, - this.controllerId); + String query = + String.format("SELECT * FROM `%s` WHERE `id`='%s';", this.controllerTableName, this.controllerId); LOG.trace(query); ResultSet data = this.dbClient.read(query); - if (!data.next()) { - query = String.format("INSERT INTO `%s` (`id`,`desc`) VALUES ('%s','%s')", - this.controllerTableName, this.controllerId, ""); + if (data == null || !data.next()) { + query = String.format("INSERT INTO `%s` (`id`,`desc`) VALUES ('%s','%s')", this.controllerTableName, + this.controllerId, ""); LOG.trace(query); return this.dbClient.write(query); - } - else { + } else { LOG.trace("controllerId already set"); } return true; @@ -505,5 +527,10 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa return this.controllerId; } + @Override + public HtUserdataManager getUserManager() { + return this.usermanager; + } + } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/Userdata.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/Userdata.java new file mode 100644 index 000000000..658b112bd --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/Userdata.java @@ -0,0 +1,135 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data; + +import com.google.common.base.MoreObjects; +import java.util.Objects; +import javax.annotation.processing.Generated; +import org.opendaylight.yangtools.yang.binding.Augmentable; +import org.opendaylight.yangtools.yang.binding.CodeHelpers; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * + * <p> + * This class represents the following YANG schema fragment defined in module <b>data-provider</b> + * + * <pre> + * container userdata { + * leaf id { + * type string; + * } + * leaf value { + * type string; + * } + * } + * </pre> + * + * The schema path to identify an instance is <i>data-provider/userdata</i> + * + * <p> + * To create instances of this class use {@link UserdataBuilder}. + * + * @see UserdataBuilder + * + */ +@Generated("mdsal-binding-generator") +public interface Userdata extends Augmentable<Userdata>, DataObject { + + /** + * Default implementation of {@link Object#hashCode()} contract for this interface. Implementations of this + * interface are encouraged to defer to this method to get consistent hashing results across all implementations. + * + * @param obj Object for which to generate hashCode() result. + * @return Hash code value of data modeled by this interface. + * @throws NullPointerException if {@code obj} is null + */ + static int bindingHashCode(final Userdata obj) { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(obj.getId()); + result = prime * result + Objects.hashCode(obj.getValue()); + result = prime * result + obj.augmentations().hashCode(); + return result; + } + + /** + * Default implementation of {@link Object#equals(Object)} contract for this interface. Implementations of this + * interface are encouraged to defer to this method to get consistent equality results across all implementations. + * + * @param thisObj Object acting as the receiver of equals invocation + * @param obj Object acting as argument to equals invocation + * @return True if thisObj and obj are considered equal + * @throws NullPointerException if {@code thisObj} is null + */ + static boolean bindingEquals(final Userdata thisObj, final Object obj) { + if (thisObj == obj) { + return true; + } + final Userdata other = CodeHelpers.checkCast(Userdata.class, obj); + if (other == null) { + return false; + } + if (!Objects.equals(thisObj.getId(), other.getId())) { + return false; + } + if (!Objects.equals(thisObj.getValue(), other.getValue())) { + return false; + } + return thisObj.augmentations().equals(other.augmentations()); + } + + /** + * Default implementation of {@link Object#toString()} contract for this interface. Implementations of this + * interface are encouraged to defer to this method to get consistent string representations across all + * implementations. + * + * @param obj Object for which to generate toString() result. + * @return {@link String} value of data modeled by this interface. + * @throws NullPointerException if {@code obj} is null + */ + static String bindingToString(final Userdata obj) { + final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper("Userdata"); + CodeHelpers.appendValue(helper, "id", obj.getId()); + CodeHelpers.appendValue(helper, "value", obj.getValue()); + CodeHelpers.appendValue(helper, "augmentation", obj.augmentations().values()); + return helper.toString(); + } + + /** + * Return id, or {@code null} if it is not present. + * + * @return {@code java.lang.String} id, or {@code null} if it is not present. + * + */ + String getId(); + + /** + * Return value, or {@code null} if it is not present. + * + * @return {@code java.lang.String} value, or {@code null} if it is not present. + * + */ + String getValue(); + +} + diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/UserdataBuilder.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/UserdataBuilder.java new file mode 100644 index 000000000..bb1268cc9 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/UserdataBuilder.java @@ -0,0 +1,207 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import javax.annotation.processing.Generated; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.AbstractAugmentable; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * Class that builds {@link UserdataBuilder} instances. Overall design of the class is that of a + * <a href="https://en.wikipedia.org/wiki/Fluent_interface">fluent interface</a>, where method chaining is used. + * + * <p> + * In general, this class is supposed to be used like this template: + * + * <pre> + * <code> + * UserdataBuilder createTarget(int fooXyzzy, int barBaz) { + * return new UserdataBuilderBuilder() + * .setFoo(new FooBuilder().setXyzzy(fooXyzzy).build()) + * .setBar(new BarBuilder().setBaz(barBaz).build()) + * .build(); + * } + * </code> + * </pre> + * + * <p> + * This pattern is supported by the immutable nature of UserdataBuilder, as instances can be freely passed around + * without worrying about synchronization issues. + * + * <p> + * As a side note: method chaining results in: + * <ul> + * <li>very efficient Java bytecode, as the method invocation result, in this case the Builder reference, is on the + * stack, so further method invocations just need to fill method arguments for the next method invocation, which is + * terminated by {@link #build()}, which is then returned from the method</li> + * <li>better understanding by humans, as the scope of mutable state (the builder) is kept to a minimum and is very + * localized</li> + * <li>better optimization oportunities, as the object scope is minimized in terms of invocation (rather than method) + * stack, making <a href="https://en.wikipedia.org/wiki/Escape_analysis">escape analysis</a> a lot easier. Given enough + * compiler (JIT/AOT) prowess, the cost of th builder object can be completely eliminated</li> + * </ul> + * + * @see UserdataBuilder + * @see Builder + * + */ +@Generated("mdsal-binding-generator") +public class UserdataBuilder implements Builder<Userdata> { + + private String _id; + private String _value; + + + Map<Class<? extends Augmentation<Userdata>>, Augmentation<Userdata>> augmentation = Collections.emptyMap(); + + public UserdataBuilder() {} + + + + public UserdataBuilder(Userdata base) { + Map<Class<? extends Augmentation<Userdata>>, Augmentation<Userdata>> aug = base.augmentations(); + if (!aug.isEmpty()) { + this.augmentation = new HashMap<>(aug); + } + this._id = base.getId(); + this._value = base.getValue(); + } + + + public String getId() { + return _id; + } + + public String getValue() { + return _value; + } + + @SuppressWarnings({"unchecked", "checkstyle:methodTypeParameterName"}) + public <E$$ extends Augmentation<Userdata>> E$$ augmentation(Class<E$$> augmentationType) { + return (E$$) augmentation.get(Objects.requireNonNull(augmentationType)); + } + + + public UserdataBuilder setId(final String value) { + this._id = value; + return this; + } + + public UserdataBuilder setValue(final String value) { + this._value = value; + return this; + } + + /** + * Add an augmentation to this builder's product. + * + * @param augmentation augmentation to be added + * @return this builder + * @throws NullPointerException if {@code augmentation} is null + */ + public UserdataBuilder addAugmentation(Augmentation<Userdata> augmentation) { + Class<? extends Augmentation<Userdata>> augmentationType = augmentation.implementedInterface(); + if (!(this.augmentation instanceof HashMap)) { + this.augmentation = new HashMap<>(); + } + + this.augmentation.put(augmentationType, augmentation); + return this; + } + + /** + * Remove an augmentation from this builder's product. If this builder does not track such an augmentation type, + * this method does nothing. + * + * @param augmentationType augmentation type to be removed + * @return this builder + */ + public UserdataBuilder removeAugmentation(Class<? extends Augmentation<Userdata>> augmentationType) { + if (this.augmentation instanceof HashMap) { + this.augmentation.remove(augmentationType); + } + return this; + } + + @Override + public Userdata build() { + return new UserdataImpl(this); + } + + private static final class UserdataImpl extends AbstractAugmentable<Userdata> implements Userdata { + + private final String _id; + private final String _value; + + UserdataImpl(UserdataBuilder base) { + super(base.augmentation); + this._id = base.getId(); + this._value = base.getValue(); + } + + @Override + public String getId() { + return _id; + } + + @Override + public String getValue() { + return _value; + } + + private int hash = 0; + private volatile boolean hashValid = false; + + @Override + public int hashCode() { + if (hashValid) { + return hash; + } + + final int result = Userdata.bindingHashCode(this); + hash = result; + hashValid = true; + return result; + } + + @Override + public boolean equals(Object obj) { + return Userdata.bindingEquals(this, obj); + } + + @Override + public String toString() { + return Userdata.bindingToString(this); + } + + @Override + public Class<? extends DataObject> implementedInterface() { + return Userdata.class; + } + } +} 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 2b07dfae2..6244894e5 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 @@ -60,7 +60,7 @@ public class DatabaseIdGenerator { return UUID.randomUUID().toString(); } - public static String getFaultcurrentId(String nodeId, String objectId, String problemName) { + public static String extractUuid(String objectId) { String uuId; Matcher matcher = FAULTPATTERN.matcher(objectId); @@ -69,6 +69,12 @@ public class DatabaseIdGenerator { } else { uuId = objectId; } + return uuId; + } + + 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 84786b0cd..88aaa583d 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 @@ -5,6 +5,8 @@ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -37,6 +39,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlD 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.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; @@ -73,6 +76,7 @@ public class HtDatabaseEventsService implements DataProvider { protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.network.element.connection.list.output.Data> networkelementConnectionRW; protected final SqlDBReaderWriterPm<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data> pm15mRW; protected final SqlDBReaderWriterPm<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._24h.list.output.Data> pm24hRW; + protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.Data> eventRWCMLog; protected final String controllerTableName; public HtDatabaseEventsService(SqlDBConfig config) { @@ -117,6 +121,10 @@ public class HtDatabaseEventsService implements DataProvider { 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.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); + } @Override @@ -136,6 +144,11 @@ public class HtDatabaseEventsService implements DataProvider { } @Override + public void writeCMLog(CmlogEntity cm) { + this.eventRWCMLog.write(cm, cm.getId()); + } + + @Override public void updateFaultCurrent(FaultcurrentEntity fault) { final String id = fault.getId() != null ? fault.getId() : DatabaseIdGenerator.getFaultcurrentId(fault); if (FaultEntityManager.isManagedAsCurrentProblem(fault)) { @@ -220,6 +233,7 @@ public class HtDatabaseEventsService implements DataProvider { removed += this.eventlogRW.remove(filter); removed += this.eventRWFaultLog.remove(filter); + removed += this.eventRWCMLog.remove(filter); return removed; } 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 new file mode 100644 index 000000000..2c849ac67 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database; + +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.Userdata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; + +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); + } + + + +} 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 6afcae077..2b3f9f3fa 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 @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.eclipse.jdt.annotation.Nullable; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; @@ -35,9 +36,13 @@ 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.Pagination; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Sortorder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.SortorderKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class SelectQuery implements SqlQuery { + private static final Logger LOG = LoggerFactory.getLogger(SelectQuery.class); + private static final long DEFAULT_PAGESIZE = 20; private static final long DEFAULT_PAGE = 1; private final String tableName; @@ -78,7 +83,7 @@ public class SelectQuery implements SqlQuery { Map<FilterKey, Filter> filter = input != null ? input.getFilter() : null; if (filter != null && filter.size() > 0) { for (Filter f : filter.values()) { - this.addFilter(f.getProperty(), f.getFiltervalue()); + this.addFilter(f); } } if (controllerId != null) { @@ -101,8 +106,35 @@ public class SelectQuery implements SqlQuery { } public void addFilter(String property, String filtervalue) { - this.filters.add(new FilterBuilder().setProperty(property).setFiltervalue(filtervalue).build()); + this.addFilter(new FilterBuilder().setProperty(property).setFiltervalue(filtervalue).build()); + } + private static Filter cleanFilter(Filter filter) { + if (filter.getFiltervalue() != null + && (filter.getFiltervalues() == null || filter.getFiltervalues().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 (list.size() == 1 && "*".equals(list.get(0))) { + return null; + } ; + return new FilterBuilder().setProperty(filter.getProperty()).setFiltervalue(filter.getFiltervalue()) + .setFiltervalues( + filter.getFiltervalues().stream().filter(e -> !"*".equals(e)).collect(Collectors.toList())) + .build(); + } + } + + public void addFilter(Filter filter) { + Filter tmp = cleanFilter(filter); + if (tmp == null) { + LOG.debug("ignore unneccessary filter for {}", filter); + } else { + this.filters.add(tmp); + } } public void addSortOrder(String col, String order) { diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java index 1dd9516e6..70b683a1a 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/DBKeyValuePair.java @@ -52,8 +52,15 @@ public class DBKeyValuePair<T> implements SqlDBFilter { @Override public String getFilterExpression() { - if (isNumericValue(this.value)) { - return String.format("`%s`=%d", this.key, this.value); + // remove isNumericValue and add cast to remove sonar issue + if (this.getValue() instanceof Long) { + return String.format("`%s`=%d", this.key, (Long)this.value); + } else if (this.getValue() instanceof Integer) { + return String.format("`%s`=%d", this.key, (Integer)this.value); + } else if (this.getValue() instanceof Byte) { + return String.format("`%s`=%d", this.key, (Byte)this.value); + } else if (this.getValue() instanceof BigInteger) { + return String.format("`%s`=%d", this.key, (BigInteger)this.value); } else { return String.format("`%s`='%s'", this.key, this.value); } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RangeSqlDBFilter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RangeSqlDBFilter.java index c4a5d8abc..83cd94964 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RangeSqlDBFilter.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/RangeSqlDBFilter.java @@ -21,6 +21,7 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters; +import java.math.BigInteger; import org.eclipse.jdt.annotation.Nullable; public class RangeSqlDBFilter extends DBKeyValuePair<Object> implements SqlDBFilter { @@ -34,8 +35,15 @@ public class RangeSqlDBFilter extends DBKeyValuePair<Object> implements SqlDBFil @Override public String getFilterExpression() { - if (isNumericValue(this.getValue())) { - return String.format("`%s`%s%d", this.getKey(), this.comparator, this.getValue()); + // remove isNumericValue and add cast to remove sonar issue + if (this.getValue() instanceof Long) { + return String.format("`%s`%s%d", this.getKey(), this.comparator, (Long)this.getValue()); + } else if (this.getValue() instanceof Integer) { + return String.format("`%s`%s%d", this.getKey(), this.comparator, (Integer)this.getValue()); + } else if (this.getValue() instanceof Byte) { + return String.format("`%s`%s%d", this.getKey(), this.comparator, (Byte)this.getValue()); + } else if (this.getValue() instanceof BigInteger) { + return String.format("`%s`%s%d", this.getKey(), this.comparator, (BigInteger)this.getValue()); } else { return String.format("`%s`%s'%s'", this.getKey(), this.comparator, this.getValue()); } diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestConfig.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestConfig.java new file mode 100644 index 000000000..676be4178 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestConfig.java @@ -0,0 +1,133 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import com.google.common.io.Files; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig; + +public class TestConfig { + + + private static final String TEST_CONFIG1 = "test.properties"; + private static final String TEST_CONFIG2 = "test2.properties"; + private static final String TEST_CONFIG3 = "test3.properties"; + protected static final String SDNR_CONTROLLERID_ENV_VALUE = "903f3091-24f6-11ec-9cc3-0242ac130003"; + private static final String CONTENT_CONTROLLER_NULL = "dbType=${SDNRDBTYPE}\n" + + "\n" + + "[mariadb]\n" + + "url=${SDNRDBURL}\n" + + "username=${SDNRDBUSERNAME}\n" + + "password=${SDNRDBPASSWORD}\n" + + "controllerId=null\n" + + "suffix=-v6"; + + @Test + public void testEnvControllerId() { + + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(TEST_CONFIG1); + Section.setEnvGetter(new EnvGetter() { + + @Override + public String getenv(String substring) { + if("SDNRCONTROLLERID".equals(substring)) { + return SDNR_CONTROLLERID_ENV_VALUE; + } + return ""; + } + }); + SqlDBConfig config = new SqlDBConfig(cfg); + assertEquals(SDNR_CONTROLLERID_ENV_VALUE, config.getControllerId()); + } + + @Test + public void testGeneratedControllerId() { + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(TEST_CONFIG2); + Section.setEnvGetter(new EnvGetter() { + + @Override + public String getenv(String substring) { + return ""; + } + }); + SqlDBConfig config = new SqlDBConfig(cfg); + final String controllerId = config.getControllerId(); + assertNotNull(controllerId); + assertFalse(controllerId.isBlank()); + final String controllerId2 = config.getControllerId(); + assertEquals(controllerId, controllerId2); + } + + @Test + public void testNullControllerId() throws IOException { + Files.asCharSink(new File(TEST_CONFIG3), StandardCharsets.UTF_8).write(CONTENT_CONTROLLER_NULL); + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(TEST_CONFIG3); + Section.setEnvGetter(new EnvGetter() { + + @Override + public String getenv(String substring) { + return ""; + } + }); + SqlDBConfig config = new SqlDBConfig(cfg); + final String controllerId = config.getControllerId(); + assertNull(controllerId); + final String controllerId2 = config.getControllerId(); + assertNull(controllerId2); + } + + @Before + @After + public void after() throws InterruptedException, IOException { + + delete(new File(TEST_CONFIG1)); + delete(new File(TEST_CONFIG2)); + delete(new File(TEST_CONFIG3)); + + } + + private static void delete(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) { + delete(c); + } + } + if (f.exists()) { + if (!f.delete()) { + throw new FileNotFoundException("Failed to delete file: " + f); + } + } + } +} 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 da7450089..b4e0584b0 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 @@ -5,6 +5,8 @@ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -43,6 +45,10 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test.util.MariaDBTestB 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; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmNotificationType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmSourceIndicator; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogBuilder; +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.ConnectionlogBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity; @@ -70,6 +76,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.NetworkElementConnectionEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; 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.ReadCmlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListInputBuilder; @@ -113,6 +120,7 @@ public class TestMariaDataProvider { private static final String URI1 = "http://localhost:8181"; 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 MariaDBTestBase testBase; private static SqlDBDataProvider dbProvider; private static SqlDBClient dbClient; @@ -199,6 +207,47 @@ public class TestMariaDataProvider { } @Test + public void testCMlog() { + 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(); + + dbProvider.writeCMLog(cm1); + dbProvider.writeCMLog(cm2); + cmlogs = dbProvider.readCMLogList(createInput("node-id", NODEID2, 1, 20)); + 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()); + + } + + @Test public void testConnectionlog() { try { dbClient.delete(new DeleteQuery(Entity.Connectionlog, null).toSql()); diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java index 7a37345f2..2316e444a 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java @@ -22,6 +22,8 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.DatabaseIdGenerator; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; @@ -49,6 +51,11 @@ public class TestObjectIds { @Test public void testGenerator() { + assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, "toto[layerProtocol="+OBJECTID1+"]", PROBLEMNAME1)); + assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, "[layerProtocol="+OBJECTID1+"]", PROBLEMNAME1)); + assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, "[layerPtoto[layerProtocol="+OBJECTID1+"]", PROBLEMNAME1)); + assertNotEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, "[layerProtocol="+OBJECTID1+"]aaa", PROBLEMNAME1)); + assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, OBJECTID1, PROBLEMNAME1)); assertEquals(INVENTORY_ID1, DatabaseIdGenerator .getInventoryId(new InventoryBuilder().setNodeId(NODEID1).setUuid(EQUIPMENT_UUID1).build())); 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 758b72f9c..24347c7db 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 @@ -21,16 +21,22 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test; +import static org.junit.Assert.assertFalse; 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.SelectQuery; 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; 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.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.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.common.Uint64; public class TestQuerySyntax { @@ -154,4 +160,37 @@ public class TestQuerySyntax { final String sql = query.toSql(); assertTrue(sql.contains("`timestamp`<='2022-01-01 00:00:00.000'")); } + + @Test + public void testSelectForFilterValues() { + EntityInput input = new ReadGuiCutThroughEntryInputBuilder() + .setFilter(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); + System.out.println(query.toSql()); + } + @Test + public void testSelectForFilterValues2() { + EntityInput input = new ReadGuiCutThroughEntryInputBuilder() + .setFilter(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); + System.out.println(query.toSql()); + assertFalse(query.toSql().contains("RLIKE")); + } + @Test + public void testSelectForFilterValues3() { + EntityInput input = new ReadGuiCutThroughEntryInputBuilder() + .setFilter(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")); + } } 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 b065519f8..3360d3ed8 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 @@ -5,6 +5,8 @@ * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -34,6 +36,7 @@ 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.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; 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; @@ -163,6 +166,7 @@ public class MariaDBTestBase { createTable(dbService, FaultcurrentEntity.class, Entity.Faultcurrent, false); createTable(dbService, FaultlogEntity.class, Entity.Faultlog, true); createTable(dbService, GuicutthroughEntity.class, Entity.Guicutthrough, false); + createTable(dbService, CmlogEntity.class, Entity.Cmlog, true); createTable(dbService, Pmdata15mEntity.class, Entity.Historicalperformance15min, false); createTable(dbService, Pmdata24hEntity.class, Entity.Historicalperformance24h, false); createTable(dbService, InventoryEntity.class, Entity.Inventoryequipment, false); diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java index 128138ee3..8a5e91c63 100644 --- a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java @@ -4,6 +4,8 @@ * ================================================================================================= * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. * ================================================================================================= + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * @@ -19,6 +21,7 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.model; import java.util.List; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +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.ConnectionlogEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentEntity; @@ -38,6 +41,8 @@ public interface DataProvider extends ArchiveCleanProvider { void writeFaultLog(FaultlogEntity fault); + void writeCMLog(CmlogEntity cm); + void updateFaultCurrent(FaultcurrentEntity fault); /** diff --git a/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang b/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang index be2c638e2..8b905f49e 100644 --- a/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang +++ b/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang @@ -28,6 +28,8 @@ module data-provider { Copyright 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + Update Copyright 2021 Samsung Electronics Intellectual Property. + All rights reserved. Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License. @@ -75,6 +77,10 @@ module data-provider { description "faultlog information"; } + enum cmlog { + description + "CMlog information"; + } enum historicalperformance15min { description "performance data"; @@ -267,6 +273,69 @@ module data-provider { "According to ITU-T M.3160"; } + typedef cm-notification-type { + type enumeration { + enum notifyMOICreation { + description + "notification type"; + } + enum notifyMOIDeletion { + description + "notification type"; + } + enum notifyMOIAttributeValueChanges { + description + "notification type"; + } + enum notifyMOIChanges { + description + "notification type"; + } + } + } + + typedef cm-source-indicator { + type enumeration { + enum RESOURCE_OPERATION { + description + "source indicator type"; + } + enum MANAGEMENT_OPERATION { + description + "source indicator type"; + } + enum SON_OPERATION { + description + "source indicator type"; + } + enum UNKNOWN { + description + "source indicator type"; + } + } + } + + typedef cm-operation { + type enumeration { + enum CREATE { + description + "source operation type"; + } + enum DELETE { + description + "source operation type"; + } + enum REPLACE { + description + "source operation type"; + } + enum NULL { + description + "source operation type for other than notifyMOIChanges notification type"; + } + } + } + typedef source-type { type enumeration { enum Ves { @@ -409,6 +478,41 @@ module data-provider { } } + grouping cm { + description + "CM event of an object"; + leaf notification-type { + type cm-notification-type; + description + "The reported CM notification type."; + } + leaf notification-id { + type string; + description + "CM notification id"; + } + leaf source-indicator { + type cm-source-indicator; + description + "CM source indicator."; + } + leaf path { + type string; + description + "CM path."; + } + leaf operation { + type cm-operation; + description + "CM operation."; + } + leaf value { + type string; + description + "CM JSON output value"; + } + } + grouping attribute-change { description "update change of an attribute"; @@ -463,6 +567,21 @@ module data-provider { uses faultlog-entity; } + grouping cmlog-entity { + description + "Changed cm indication"; + uses source-reference; + uses object-change-reference; + uses cm; + uses entity-id; + } + + container cmlog { + description + "builder"; + uses cmlog-entity; + } + grouping eventlog-entity { description "One change event of devices"; @@ -1543,6 +1662,26 @@ module data-provider { } } + rpc read-cmlog-list { + description + "Get list of CM entries according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses cmlog-entity; + description + "The output data as list of cm entities."; + } + } + } + rpc read-eventlog-list { description "Get list of event log entities according to filter"; diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/FaultEntityManager.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/FaultEntityManager.java index 36ab39845..64156dc07 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/FaultEntityManager.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/FaultEntityManager.java @@ -24,14 +24,13 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nonnull; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.DatabaseIdGenerator; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Fault; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; public class FaultEntityManager { - private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]"); - /** * The leading indication for notification or events that are not in the currentProblem data of the ONF Coremodel */ @@ -68,14 +67,7 @@ public class FaultEntityManager { */ public static String genSpecificEsId(String nodeName, String objectId, String problemName) { - String uuId; - - Matcher matcher = pattern.matcher(objectId); - if (matcher.matches() && matcher.groupCount() == 1) { - uuId = matcher.group(1); - } else { - uuId = objectId; - } + String uuId = DatabaseIdGenerator.extractUuid(objectId); StringBuffer strBuf = new StringBuffer(); strBuf.append(nodeName); diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java index ea3296acb..13438ef15 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java @@ -5,6 +5,8 @@ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -44,6 +46,8 @@ 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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogBuilder; +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.ConnectionlogBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity; @@ -87,6 +91,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid private EsDataObjectReaderWriter2<InventoryEntity> eventRWEquipment; private EsDataObjectReaderWriter2<FaultcurrentEntity> eventRWFaultCurrentDB; private EsDataObjectReaderWriter2<FaultlogEntity> eventRWFaultLogDB; + private EsDataObjectReaderWriter2<CmlogEntity> eventRWFCMLogDB; private EsDataObjectReaderWriter2<ConnectionlogEntity> eventRWConnectionLogDB; private final EsDataObjectReaderWriter2<NetworkElementConnectionEntity> networkelementConnectionDB; private final EsDataObjectReaderWriter2<GuicutthroughEntity> guiCutThroughDB; @@ -119,6 +124,9 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid eventRWFaultLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultlog, FaultlogEntity.class, FaultlogBuilder.class); + eventRWFCMLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Cmlog, CmlogEntity.class, + CmlogBuilder.class); + eventRWConnectionLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Connectionlog, ConnectionlogEntity.class, ConnectionlogBuilder.class); @@ -179,6 +187,18 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid eventRWFaultLogDB.write(fault, null); } + //-- CM log + + @Override + public void writeCMLog(CmlogEntity cm) { + if (assertIfClientNull(cm)) { + return; + } + + LOG.debug("Write CM to cmlog: {}", cm.toString()); + eventRWFCMLogDB.write(cm, null); + } + // -- Fault current @Override @@ -491,6 +511,10 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); removed += eventRWFaultLogDB.remove(queryFaultLog); + + QueryBuilder queryCMLog = EsCMLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); + removed += eventRWFCMLogDB.remove(queryCMLog); + return removed; } @@ -506,6 +530,9 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); numberOfElements += eventRWFaultLogDB.doReadAll(queryFaultLog).getTotal(); + QueryBuilder queryCMLog = EsCMLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); + numberOfElements += eventRWFCMLogDB.doReadAll(queryCMLog).getTotal(); + return numberOfElements; } @@ -565,6 +592,18 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid } } + private static class EsCMLogDevicemanager { + /** + * Get older Elements + * + * @param netconfTimeStamp to identify query elements older than this timestamp. + * @return QueryBuilder for related elements + */ + public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { + return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp); + } + } + public static class EsFaultCurrent { /** * @param nodeName name of the node diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/impl/ElasticSearchDataProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/impl/ElasticSearchDataProvider.java index 53b21e0ed..38ea8044e 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/impl/ElasticSearchDataProvider.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/impl/ElasticSearchDataProvider.java @@ -5,6 +5,8 @@ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -39,6 +41,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data. import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMediatorserver; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput; 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.CreateMediatorServerInput; @@ -56,6 +59,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.MaintenanceEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.MediatorServerEntity; 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.ReadCmlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListOutputBuilder; @@ -92,6 +96,7 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { private final HtDatabaseClient dbClient; private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultcurrent.list.output.Data> eventRWFaultCurrent; private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultlog.list.output.Data> eventRWFaultLog; + private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.Data> eventRWCMLog; private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.mediator.server.list.output.Data> mediatorserverRW; private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> maintenanceRW; private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.gui.cut.through.entry.output.Data> guicutthroughRW; @@ -105,6 +110,7 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { private final DataObjectAcessorStatus readStatus; private final HtDatabaseEventsService databaseService; private final HtDatabaseMaintenanceService databaseMaintenanceService; + private final HtUserdataManager usermanager; private final HtDatabaseMediatorserver dbMediatorServerService = new HtDatabaseMediatorserver() { @@ -114,6 +120,7 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { } }; + @Override public HtDatabaseClient getRawClient() { return this.dbClient; @@ -163,6 +170,10 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultlog.list.output.Data.class, doFullsizeRequests); + this.eventRWCMLog = new DataObjectAcessorWithId<>(dbClient, Entity.Cmlog, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.Data.class, + doFullsizeRequests); + this.connnectionlogRW = new DataObjectAcessorWithId<>(dbClient, Entity.Connectionlog, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.Data.class, doFullsizeRequests); @@ -188,6 +199,7 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { this.databaseService = new HtDatabaseEventsService(dbClient, this); this.databaseMaintenanceService = new HtDatabaseMaintenanceService(dbClient); + this.usermanager = new HtUserdataManagerImpl(this.dbClient); } /*------------------------- @@ -222,6 +234,19 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { } @Override + public ReadCmlogListOutputBuilder readCMLogList(EntityInput input) { + ReadCmlogListOutputBuilder outputBuilder = new ReadCmlogListOutputBuilder(); + QueryResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.Data> result = + this.eventRWCMLog.getData(input); + outputBuilder.setData(result.getResult().getHits()); + outputBuilder.setPagination( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.PaginationBuilder( + result.getPagination()).build()); + return outputBuilder; + } + + + @Override public ReadMaintenanceListOutputBuilder readMaintenanceList(EntityInput input) { ReadMaintenanceListOutputBuilder outputBuilder = new ReadMaintenanceListOutputBuilder(); QueryResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> result = @@ -393,7 +418,7 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { } CreateNetworkElementConnectionOutputBuilder builder = new CreateNetworkElementConnectionOutputBuilder(); builder.setId(id).setNodeId(input.getNodeId()).setHost(input.getHost()).setPort(input.getPort()) - .setUsername(input.getUsername()).setPassword(input.getPassword()).setIsRequired(input.isIsRequired()) + .setUsername(input.getUsername()).setPassword(input.getPassword()).setIsRequired(input.getIsRequired()) .setCoreModelCapability(input.getCoreModelCapability()).setDeviceType(input.getDeviceType()); return builder; } @@ -516,5 +541,10 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { return dbMediatorServerService; } + @Override + public HtUserdataManager getUserManager() { + return this.usermanager; + } + } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/impl/HtUserdataManagerImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/impl/HtUserdataManagerImpl.java index 9dbdb136a..7b7dccc96 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/impl/HtUserdataManagerImpl.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/impl/HtUserdataManagerImpl.java @@ -21,44 +21,15 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import org.json.JSONException; import org.json.JSONObject; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.HtUserdataManagerBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HtUserdataManagerImpl implements HtUserdataManager { - - private static final Logger LOG = LoggerFactory.getLogger(HtUserdataManagerImpl.class); - - private static final String USERDATA_DEFAULTS_FILENAME = "etc/userdata-defaults.json"; - private static final JSONObject USERDATA_DEFAULTS_CONTENT = loadDefaults(); - - private static JSONObject loadDefaults() { - File f = new File(USERDATA_DEFAULTS_FILENAME); - String content; - JSONObject o = null; - if (f.exists()) { - try { - content = Files.readString(f.toPath()); - o = new JSONObject(content); - } catch (IOException e) { - LOG.warn("problem loading defaults: ", e); - } catch (JSONException e) { - LOG.warn("problem parsing defaults: ", e); - } - } - return o; - } +public class HtUserdataManagerImpl extends HtUserdataManagerBase { private final HtDatabaseClient dbClient; @@ -67,84 +38,23 @@ public class HtUserdataManagerImpl implements HtUserdataManager { } @Override - public String getUserdata(String username) { + protected String readUserdata(String username, String defaultValue) { + SearchResult<SearchHit> result = this.dbClient.doReadByQueryJsonData(Entity.Userdata.getName(), QueryBuilders.matchQuery("_id", username)); - String json = result.getHits().size() > 0 ? result.getHits().get(0).getSourceAsString() : "{}"; - if (USERDATA_DEFAULTS_CONTENT != null) { - JSONObject merge = mergeData(new JSONObject(json), USERDATA_DEFAULTS_CONTENT); - json = merge.toString(); - } - return json; - } - - @Override - public String getUserdata(String username, String key) { - JSONObject o = new JSONObject(this.getUserdata(username)); - return o.has(key) ? o.get(key).toString() : "{}"; + return result.getHits().size() > 0 ? result.getHits().get(0).getSourceAsString() : defaultValue; } @Override public boolean setUserdata(String username, String data) { JSONObject o = new JSONObject(this.getUserdata(username)); - JSONObject merge = mergeData(o, new JSONObject(data)); + JSONObject merge = mergeData(new JSONObject(data), o); return this.dbClient.doWriteRaw(Entity.Userdata.getName(), username, merge.toString()) != null; } @Override - public boolean setUserdata(String username, String key, String data) { - JSONObject o = new JSONObject(this.getUserdata(username)); - o = mergeData(o, key, new JSONObject(data)); - return this.dbClient.doWriteRaw(Entity.Userdata.getName(), username, o.toString()) != null; - } - - @Override public boolean removeUserdata(String username) { return this.dbClient.doRemove(Entity.Userdata.getName(), username); } - @Override - public boolean removeUserdata(String username, String key) { - JSONObject o = new JSONObject(this.getUserdata(username)); - if (o.has(key)) { - o.remove(key); - return this.setUserdata(username, o.toString()); - } - return true; - } - - private static JSONObject mergeData(JSONObject o, String key, JSONObject subObject) { - if (!o.has(key)) { - o.put(key, subObject); - } else { - JSONObject tmp = new JSONObject(); - tmp.put(key, subObject); - o = mergeData(tmp, o); - } - return o; - } - - private static JSONObject mergeData(JSONObject source, JSONObject target) throws JSONException { - String[] keys = JSONObject.getNames(source); - if (keys == null) { - return target; - } - for (String key : keys) { - Object value = source.get(key); - if (!target.has(key)) { - // new value for "key": - target.put(key, value); - } else { - // existing value for "key" - recursively deep merge: - if (value instanceof JSONObject) { - JSONObject valueJson = (JSONObject) value; - mergeData(valueJson, target.getJSONObject(key)); - } else { - target.put(key, value); - } - } - } - return target; - } - } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java index cd75ca2a8..310444fd6 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java @@ -120,7 +120,7 @@ public class AboutHttpServlet extends HttpServlet { final String mdsalVersion = SystemInfo.getMdSalVersion(UNKNOWN); this.data.put(PLACEHOLDER_ONAP_RELEASENAME, ODLVersionLUT.getONAPReleaseName(ccsdkVersion, UNKNOWN)); this.data.put(PLACEHOLDER_ODL_RELEASENAME, ODLVersionLUT.getOdlVersion(mdsalVersion, UNKNOWN)); - this.data.put(PLACEHOLDER_BUILD_TIMESTAMP, props != null ? props.getBuildDate().toString() : ""); + this.data.put(PLACEHOLDER_BUILD_TIMESTAMP, props != null ? String.valueOf(props.getBuildDate()) : ""); this.data.put(PLACEHOLDER_PACAKGE_VERSION, this.getManifestValue("Bundle-Version")); this.data.put(PLACEHOLDER_CCSDK_VERSION, ccsdkVersion); this.data.put(PLACEHOLDER_ONAP_RELEASEVERSION, SystemInfo.getOnapVersion(UNKNOWN)); diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java index 0e43cd251..5211030eb 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java @@ -32,6 +32,9 @@ public class ODLVersionLUT { if (onapCCSDKVersion == null) { return def; } + if (onapCCSDKVersion.startsWith("2.3.")) { + return "ONAP Jakarta"; + } if (onapCCSDKVersion.startsWith("2.2.")) { return "ONAP Istanbul"; } @@ -63,6 +66,7 @@ public class ODLVersionLUT { } if(odlMdsalVersionLUT==null) { odlMdsalVersionLUT = new HashMap<>(); + odlMdsalVersionLUT.put("7.0.9","silicon-SR2 (0.14.2)"); odlMdsalVersionLUT.put("7.0.7","silicon-SR1 (0.14.1)"); odlMdsalVersionLUT.put("7.0.6","silicon-SR0 (0.14.0)"); odlMdsalVersionLUT.put("6.0.8","aluminium-SR3 (0.13.3)"); diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFileProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFileProvider.java index c6758e240..797e8d72b 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFileProvider.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFileProvider.java @@ -27,6 +27,8 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; import java.nio.file.Path; import java.text.ParseException; import java.util.ArrayList; @@ -53,10 +55,12 @@ public class YangFileProvider { private static final int BUFFER_SIZE = 1024; private final Path mainSourcePath; + private final Path basePath; private final List<Path> additionalSources; - public YangFileProvider(String path) { - this.mainSourcePath = new File(path).toPath(); + public YangFileProvider(String path, String primaryPath) { + this.mainSourcePath = new File(primaryPath).toPath(); + this.basePath = new File(path).toPath(); this.additionalSources = new ArrayList<>(); } @@ -83,7 +87,17 @@ public class YangFileProvider { LOG.warn("unable to handle yangfile {}: {}", fn, e); } } - + List<String> filesInSeperateSubfolders = this.getSubFolderYangfiles(); + for (String file : filesInSeperateSubfolders) { + try { + yangfile = new YangFilename(file); + if (yangfile.getModule().equals(module)) { + list.add(yangfile); + } + } catch (ParseException e) { + LOG.warn("unable to handle yangfile {}: {}", file, e); + } + } for (Path addPath : this.additionalSources) { files = addPath.toFile().list(yangFilenameFilter); for (String file : files) { @@ -100,6 +114,30 @@ public class YangFileProvider { return list; } + private List<String> getSubFolderYangfiles() { + + return this.getSubFolderYangfiles(new ArrayList<>(), this.basePath); + } + + private List<String> getSubFolderYangfiles(List<String> list, Path root) { + try (DirectoryStream<Path> stream = Files.newDirectoryStream(root)) { + for (Path path : stream) { + if (path.toFile().isDirectory()) { + this.getSubFolderYangfiles(list, path); + } else { + + if (yangFilenameFilter.accept(root.toFile(), path.toString())) { + list.add(path.toAbsolutePath().toString()); + } + + } + } + } catch (IOException e) { + LOG.warn("unable to scan directory {} for yang files", root); + } + return list; + } + /** * get yang file from source with specified version or least newer one if version is null then the latest one * @@ -201,5 +239,4 @@ public class YangFileProvider { public boolean hasFileOrNewerForModule(String module, String version) throws ParseException { return this.getYangFile(module, version) != null; } - } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFilename.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFilename.java index eb4961a66..70cddee58 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFilename.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFilename.java @@ -29,7 +29,7 @@ import java.util.regex.Pattern; public class YangFilename { - private static final String REGEX = "([^\\/]*)@([0-9]{4}-[0-9]{2}-[0-9]{2}).yang"; + private static final String REGEX = "([^\\/]{1,2048})@([0-9]{4}-[0-9]{2}-[0-9]{2}).yang"; private static final Pattern pattern = Pattern.compile(REGEX, Pattern.MULTILINE); private final String filename; private final Matcher matcher; diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangSchemaHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangSchemaHttpServlet.java index 83518ecb2..86f67b1de 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangSchemaHttpServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangSchemaHttpServlet.java @@ -23,28 +23,26 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.http.yangschema; import java.io.IOException; import java.text.ParseException; - import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class YangSchemaHttpServlet extends HttpServlet { /** - * + * */ private static final long serialVersionUID = 1L; private static final Logger LOG = LoggerFactory.getLogger(YangSchemaHttpServlet.class); - - private static final String schemaCachePath = "cache/schema/"; + private static final String CACHEPATH = "cache/"; + private static final String SCHEMACACHEPATH_PRIMARY = CACHEPATH+"schema/"; private final YangFileProvider fileProvider; public YangSchemaHttpServlet() { - this.fileProvider = new YangFileProvider(schemaCachePath); + this.fileProvider = new YangFileProvider(CACHEPATH, SCHEMACACHEPATH_PRIMARY); } @Override diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java index 5a99c8ab3..251ba90f2 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java @@ -5,6 +5,8 @@ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -64,6 +66,8 @@ 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.DeleteMediatorServerOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteNetworkElementConnectionInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteNetworkElementConnectionOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListInput; @@ -146,12 +150,12 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab this.mediatorServerServlet = mediatorServerServlet; if (this.dbConfig.getDbType() == SdnrDbType.ELASTICSEARCH) { this.dataProvider = new ElasticSearchDataProvider(this.dbConfig.getEsConfig()); - } else { + } else { this.dataProvider = new SqlDBDataProvider(this.dbConfig.getMariadbConfig()); } + this.dbUserManager = this.dataProvider.getUserManager(); this.dataProvider.waitForYellowDatabaseStatus(DATABASE_TIMEOUT_MS, TimeUnit.MILLISECONDS); mediatorServerServlet.setDataProvider(this.dataProvider.getHtDatabaseMediatorServer()); - this.dbUserManager = new HtUserdataManagerImpl(this.dataProvider.getRawClient()); // Register ourselves as the REST API RPC implementation LOG.info("Register RPC Service {}", DataProviderServiceImpl.class.getSimpleName()); this.rpcReg = rpcProviderService.registerRpcImplementation(DataProviderService.class, this); @@ -213,6 +217,14 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab } @Override + public ListenableFuture<RpcResult<ReadCmlogListOutput>> readCmlogList(ReadCmlogListInput input) { + LOG.debug("RPC Request: readCMlogList with input {}", input); + RpcResultBuilder<ReadCmlogListOutput> result = + read(() -> DataProviderServiceImpl.this.dataProvider.readCMLogList(input)); + return result.buildFuture(); + } + + @Override public ListenableFuture<RpcResult<ReadMaintenanceListOutput>> readMaintenanceList(ReadMaintenanceListInput input) { LOG.debug("RPC Request: readMaintenanceList with input {}", input); RpcResultBuilder<ReadMaintenanceListOutput> result = @@ -427,7 +439,9 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab private ReadTlsKeyEntryOutputBuilder readTlsKeys(ReadTlsKeyEntryInput input) { Optional<Keystore> result = Optional.empty(); - try (ReadTransaction transaction = this.dataBroker.newReadOnlyTransaction()) { + // The implicite close is not handled correctly by underlaying opendaylight netconf service + ReadTransaction transaction = this.dataBroker.newReadOnlyTransaction(); + try { result = transaction.read(LogicalDatastoreType.CONFIGURATION, KEYSTORE_IIF).get(); } catch (ExecutionException e) { LOG.warn("problem reading netconf-keystore: ", e); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java index c407859d5..d59a0784f 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java @@ -5,6 +5,8 @@ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -47,6 +49,9 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmNotificationType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmOperation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmSourceIndicator; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceOutputBuilder; @@ -66,6 +71,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.Faultlog; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutputBuilder; @@ -588,6 +596,92 @@ public class TestCRUDforDatabase { } @Test + public void testCMLog() { + System.out.println("Starting CM log test..."); + String dbId = clearAndCreateCMEntity("1", Entity.Cmlog.getName(), + "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateCmlogInput"); + // ==READ=========================== + System.out.println("try to read entry"); + + ReadCmlogListInput readinput = new ReadCmlogListInputBuilder() + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + + ReadCmlogListOutputBuilder readResult = null; + try { + readResult = dbProvider.readCMLogList(readinput); + + } catch (Exception e) { + fail("CM log not read: " + e.getMessage()); + } + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.cmlog.list.output.Data> + data = readResult.getData(); + + assertNotNull(data); + assertEquals("1", dbId); + assertEquals(1, data.size()); + assertEquals("node-1", data.get(0).getNodeId()); + assertEquals(1, data.get(0).getCounter().intValue()); + assertEquals(CmNotificationType.NotifyMOIChanges, data.get(0).getNotificationType()); + assertEquals("123", data.get(0).getNotificationId()); + assertEquals(CmSourceIndicator.MANAGEMENTOPERATION, data.get(0).getSourceIndicator()); + assertEquals(CmOperation.REPLACE, data.get(0).getOperation()); + assertEquals("pnf-registration:true", data.get(0).getValue()); + + //== UPDATE ================================ + System.out.println("try to update entry"); + + dbRawProvider.doUpdateOrCreate(Entity.Cmlog.getName(), "1", + "{'node-id': 'test4657-78','operation': 'CREATE', 'notification-id': '1'}"); + + System.out.println("try to search entry 1"); + readinput = new ReadCmlogListInputBuilder() + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("node-id").setFiltervalue("test").build())) + .setPagination(getPagination(20, 1)).build(); + + //== VERIFY UPDATE ================================ + readResult = dbProvider.readCMLogList(readinput); + data = readResult.getData(); + + assertNotNull(data); + System.out.println(data); + assertEquals(0, data.size()); + + System.out.println("try to search entry 2"); + readinput = new ReadCmlogListInputBuilder() + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("node-id").setFiltervalue("test*").build())) + .setPagination(getPagination(20, 1)).build(); + + readResult = dbProvider.readCMLogList(readinput); + data = readResult.getData(); + + assertEquals(1, data.size()); + assertEquals("test4657-78", data.get(0).getNodeId()); + assertEquals("CREATE", data.get(0).getOperation().toString()); + assertEquals("1", data.get(0).getNotificationId()); + + //== DELETE ================================ + + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.Cmlog.getName(), dbId); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + //== VERIFY DELETE =========================== + System.out.println("verify entries deleted"); + readResult = dbProvider + .readCMLogList(new ReadFaultlogListInputBuilder().setPagination(getPagination(20, 1)).build()); + data = readResult.getData(); + assertEquals(0, data.size()); + } + + @Test public void testFaultCurrent() { System.out.println("Starting faultCurrent test..."); String dbId = null; @@ -1459,6 +1553,45 @@ public class TestCRUDforDatabase { return dbId; } + private String clearAndCreateCMEntity(String initialDbId, String entityType, String implementedInterface) { + // ==CLEAR BEFORE TEST============================ + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(entityType, QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + return createCMEntity(initialDbId, entityType, implementedInterface); + } + + private String createCMEntity(String initialDbId, String entityType, String implementedInterface) { + // ==CREATE============================ + System.out.println("try to create entry"); + String dbId = null; + + try { + dbId = dbRawProvider.doUpdateOrCreate(entityType, initialDbId, + "{\n" + "\"timestamp\": \"2019-10-28T11:55:58.3Z\",\n" + + "\" object-id\": \"LP-MWPS-RADIO\",\n" + + "\"node-id\": \"node-1\",\n" + + "\"counter\": 1,\n" + + "\"notification-type\": \"" + CmNotificationType.NotifyMOIChanges.toString() + "\",\n" + + "\"notification-id\": 123,\n" + + "\"source-indicator\": \"" + CmSourceIndicator.MANAGEMENTOPERATION.toString() + "\",\n" + + "\" path\": \"https://samsung.com/3GPP/simulation/network-function/ves=1\",\n" + + "\"operation\": \"" + CmOperation.REPLACE.toString() + "\",\n" + + "\"value\": \"pnf-registration:true\",\n" + + "\"implemented-interface\": \"" + implementedInterface + "\"\n" + + "}"); + + } catch (Exception e) { + fail("Problem creating CM log entry" + e.getMessage()); + } + + return dbId; + } + + private String createPerformanceData(String initialDbId, GranularityPeriodType timeInterval, String scannerId, String uuidInterface, String nodename) { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java index dc5e049fd..0db019005 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java @@ -5,6 +5,8 @@ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -38,12 +40,18 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.entity.FaultEntityManager; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.entity.HtDatabaseEventsService; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmNotificationType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmOperation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmSourceIndicator; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogBuilder; +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.ConnectionlogBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity; @@ -77,6 +85,7 @@ public class TestEventService { private static final String NODEID = "node1"; private static final String NODEID2 = "node2"; + private static final String NODEID3 = "node3"; private static final String OBJECTREFID1 = "objid1"; private static final String OBJECTREFID2 = "objid2"; @@ -122,6 +131,19 @@ public class TestEventService { assertTrue(nodeIds.size() == 1); } + + @Test + public void testGenSpecificEsId() { + String objectRefOld = FaultEntityManager.genSpecificEsId(createFault(NODEID, "[layerProtocol="+OBJECTREFID1+"]", "abc", SeverityType.Major)); + assertEquals(String.format("%s/%s/%s", NODEID, OBJECTREFID1, "abc"), objectRefOld); + String objectRefOld2 = FaultEntityManager.genSpecificEsId(createFault(NODEID2, "[layerProtocol="+OBJECTREFID2+"]", "abcde", SeverityType.Major)); + assertEquals(String.format("%s/%s/%s", NODEID2, OBJECTREFID2, "abcde"), objectRefOld2); + String objectRef = FaultEntityManager.genSpecificEsId(createFault(NODEID, OBJECTREFID1, "abc", SeverityType.Major)); + assertEquals(String.format("%s/%s/%s", NODEID, OBJECTREFID1, "abc"), objectRef); + String objectRef2 = FaultEntityManager.genSpecificEsId(createFault(NODEID2, OBJECTREFID2, "abcde", SeverityType.Major)); + assertEquals(String.format("%s/%s/%s", NODEID2, OBJECTREFID2, "abcde"), objectRef2); + } + private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, SeverityType severity) { return createFault(nodeId, objectRefId, problem, severity, NetconfTimeStampImpl.getConverter().getTimeStamp()); @@ -146,6 +168,7 @@ public class TestEventService { service.doIndexClean(now); clearDbEntity(Entity.Eventlog); clearDbEntity(Entity.Faultlog); + clearDbEntity(Entity.Cmlog); TestCRUDforDatabase.trySleep(1000); service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "abc", 1)); service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "avasvas", 2)); @@ -153,19 +176,27 @@ public class TestEventService { service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 1)); service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 2)); service.writeFaultLog(createFaultLog(NODEID2, OBJECTREFID2, "problem", SeverityType.Major, 1)); + + service.writeCMLog(createCMLog(NODEID3, 1, CmNotificationType.NotifyMOIChanges, + "1", CmSourceIndicator.MANAGEMENTOPERATION, CmOperation.CREATE, "value")); + TestCRUDforDatabase.trySleep(100); now = new Date(); long numOlds = service.getNumberOfOldObjects(now); - assertEquals(5, numOlds); + assertEquals(6, numOlds); TestCRUDforDatabase.trySleep(100); service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 3)); service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 5)); service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 6)); + + service.writeCMLog(createCMLog(NODEID3, 2, CmNotificationType.NotifyMOIChanges, + "2", CmSourceIndicator.SONOPERATION, CmOperation.REPLACE, "value2")); + numOlds = service.getNumberOfOldObjects(now); - assertEquals(5, numOlds); + assertEquals(6, numOlds); now = new Date(); numOlds = service.getNumberOfOldObjects(now); - assertEquals(8, numOlds); + assertEquals(10, numOlds); service.doIndexClean(now); numOlds = service.getNumberOfOldObjects(now); assertEquals(0, numOlds); @@ -292,6 +323,31 @@ public class TestEventService { /** * @param nodeId + * @param counter + * @param notificationType + * @param notificationId + * @param sourceIndicator + * @param operation + * @param value + * @return + */ + private static CmlogEntity createCMLog(String nodeId, int counter, CmNotificationType notificationType, + String notificationId, CmSourceIndicator sourceIndicator, + CmOperation operation, String value) { + return new CmlogBuilder() + .setNodeId(nodeId) + .setCounter(counter) + .setNotificationType(notificationType) + .setNotificationId(notificationId) + .setSourceIndicator(sourceIndicator) + .setOperation(operation) + .setValue(value) + .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()) + .build(); + } + + /** + * @param nodeId * @param objectId * @param problem * @param severity diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java index 3fcbdb84c..ce4044780 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java @@ -21,11 +21,11 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; import org.apache.sshd.common.util.io.IoUtils; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; @@ -35,7 +35,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; public class TestUserdata { - private static final String USERNAME = "admin"; + private static final String USERNAME = "admin132"; private static HtDatabaseClient dbRawProvider; private static HtUserdataManagerImpl userDbProvider; @@ -55,17 +55,18 @@ public class TestUserdata { } } - @Ignore @Test public void test1() { String fullContent = ""; + boolean success = false; try { fullContent = getFileContent("/userdata/full.json"); - userDbProvider.setUserdata(USERNAME, fullContent); + success = userDbProvider.setUserdata(USERNAME, fullContent); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); } + assertTrue("problem writing data into db",success); trySleep(2000); @@ -89,6 +90,6 @@ public class TestUserdata { } private static String getFileContent(String filename) throws IOException { - return String.join("\n", IoUtils.readAllLines(TestTree.class.getResourceAsStream(filename))); + return String.join("\n", IoUtils.readAllLines(TestUserdata.class.getResourceAsStream(filename))); } } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java index f3171d3b1..adcb523c0 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java @@ -54,6 +54,8 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.yangschema.YangSchemaHt public class TestYangProvider { private static final String TESTPATH = "cache/schema/"; + private static final String TESTPATH_BASE = "cache/"; + private static final String TESTPATH_SEPERATE_1 = TESTPATH_BASE+"abc1/"; @BeforeClass @@ -76,7 +78,9 @@ public class TestYangProvider { new File(TESTPATH + new YangFilename("module4", "2010-05-01").getFilename()).createNewFile(); new File(TESTPATH + new YangFilename("module5", "2010-01-11").getFilename()).createNewFile(); new File(TESTPATH + new YangFilename("module6", "2010-01-01").getFilename()).createNewFile(); - } catch (IOException | ParseException e) { + Files.createDirectories(new File(TESTPATH_SEPERATE_1).toPath(), attr); + new File(TESTPATH_SEPERATE_1 + new YangFilename("module7", "2011-01-01").getFilename()).createNewFile(); + } catch (IOException | ParseException e) { } } @@ -93,17 +97,18 @@ public class TestYangProvider { @Test public void testExisting() { - YangFileProvider provider = new YangFileProvider(TESTPATH); + YangFileProvider provider = new YangFileProvider(TESTPATH_BASE, TESTPATH); assertTrue(provider.hasFileForModule("module1", "2010-01-01")); assertTrue(provider.hasFileForModule("module2")); assertTrue(provider.hasFileForModule("module3")); assertFalse(provider.hasFileForModule("module5", "2010-01-01")); + assertTrue(provider.hasFileForModule("module7")); } @Test public void testRevision() throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - YangFileProvider provider = new YangFileProvider(TESTPATH); + YangFileProvider provider = new YangFileProvider(TESTPATH_BASE, TESTPATH); YangFilename f1 = provider.getFileForModule("module1", "2010-01-01"); assertEquals("module1", f1.getModule()); assertEquals(sdf.parse("2010-01-01"), f1.getRevision()); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/MariaDBTestBase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/MariaDBTestBase.java index 276bcf4a1..18efde235 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/MariaDBTestBase.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/MariaDBTestBase.java @@ -5,6 +5,8 @@ * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -34,6 +36,7 @@ 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.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; 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; @@ -127,6 +130,7 @@ public class MariaDBTestBase { createTable(dbService, EventlogEntity.class, Entity.Eventlog, true); createTable(dbService, FaultcurrentEntity.class, Entity.Faultcurrent, false); createTable(dbService, FaultlogEntity.class, Entity.Faultlog, true); + createTable(dbService, CmlogEntity.class, Entity.Cmlog, true); createTable(dbService, GuicutthroughEntity.class, Entity.Guicutthrough, true); createTable(dbService, Pmdata15mEntity.class, Entity.Historicalperformance15min, false); createTable(dbService, Pmdata24hEntity.class, Entity.Historicalperformance24h, false); diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/ReleaseInformation.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/ReleaseInformation.java index 6e5bdc522..5e6520c08 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/ReleaseInformation.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/ReleaseInformation.java @@ -40,6 +40,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtRel import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin.GuilinReleaseInformation; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.honolulu.HonoluluReleaseInformation; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.istanbul.IstanbulReleaseInformation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.jakarta.JakartaReleaseInformation; public abstract class ReleaseInformation { @@ -175,6 +176,8 @@ public abstract class ReleaseInformation { return new HonoluluReleaseInformation(); case ISTANBUL_R1: return new IstanbulReleaseInformation(); + case JAKARTA_R1: + return new JakartaReleaseInformation(); default: return null; } diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ComponentName.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ComponentName.java index 956f74b2d..c01e37abd 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ComponentName.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ComponentName.java @@ -5,6 +5,8 @@ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,7 +31,7 @@ public enum ComponentName { "inventorytoplevel"), MAINTENANCE("maintenance"), MEDIATOR_SERVER( "mediator-server"), REQUIRED_NETWORKELEMENT( "required-networkelement"), GUICUTTHROUGH( - "guicutthrough"), USERDATA("userdata"); + "guicutthrough"), USERDATA("userdata"),CMLOG("cmlog"); private final String value; diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo7.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo7.java index 58b98c2aa..87fc07ef9 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo7.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo7.java @@ -30,7 +30,9 @@ public class DatabaseInfo7 extends DatabaseInfo { public DatabaseInfo7(String alias, String doctype, String mapping) { super(alias, alias, doctype, mapping); } - + public DatabaseInfo7(String alias, String doctype, String mapping, String settingsformat) { + super(alias, alias, doctype, mapping, settingsformat); + } public DatabaseInfo7(String index, String alias, String doctype, String mapping, String settingsformat) { super(index, alias, doctype, mapping, settingsformat); } diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/Release.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/Release.java index 22338e89a..12cbe4f1f 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/Release.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/Release.java @@ -34,9 +34,12 @@ public enum Release { GUILIN_R1("guilin-R1", "-v4", new DatabaseVersion(7,1,1), new DatabaseVersion(7,6,1)), HONOLULU_R1("honolulu-R1", "-v5", new DatabaseVersion(7,1,1), new DatabaseVersion(8,0,0), false), ISTANBUL_R1("istanbul-R1", "-v6", new DatabaseVersion(7,1,1), new DatabaseVersion(8,0,0), false, - new DatabaseVersion(10,2,7), new DatabaseVersion(10,6,0), false); + new DatabaseVersion(10,2,7), new DatabaseVersion(10,6,0), false), + JAKARTA_R1("jakarta-R1", "-v7", new DatabaseVersion(7,1,1), new DatabaseVersion(8,0,0), false, + new DatabaseVersion(10,2,7), new DatabaseVersion(10,6,0), false); - public static final Release CURRENT_RELEASE = Release.ISTANBUL_R1; + + public static final Release CURRENT_RELEASE = Release.JAKARTA_R1; private final String value; private final String dbSuffix; diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ReleaseGroup.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ReleaseGroup.java index 58e8d2055..91ad437f9 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ReleaseGroup.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ReleaseGroup.java @@ -34,9 +34,10 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.SdnrDbType; public enum ReleaseGroup { EL_ALTO(Release.EL_ALTO), FRANKFURT(Release.FRANKFURT_R1, Release.FRANKFURT_R2), GUILIN( - Release.GUILIN_R1), HONOLULU(Release.HONOLULU_R1), ISTANBUL(Release.ISTANBUL_R1); + Release.GUILIN_R1), HONOLULU(Release.HONOLULU_R1), ISTANBUL(Release.ISTANBUL_R1), + JAKARTA(Release.JAKARTA_R1); - public static final ReleaseGroup CURRENT_RELEASE = ISTANBUL; + public static final ReleaseGroup CURRENT_RELEASE = JAKARTA; private final List<Release> releases; diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/database/MariaDbDataMigrationProvider.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/database/MariaDbDataMigrationProvider.java index 55ba66ba6..ff93079a4 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/database/MariaDbDataMigrationProvider.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/database/MariaDbDataMigrationProvider.java @@ -161,8 +161,9 @@ public class MariaDbDataMigrationProvider implements DataMigrationProviderServic boolean componentsSucceeded = true; for (ComponentName c : ri.getComponents()) { ComponentData data = new ComponentData(c); - SearchResult<SearchHit> result = null;//this.dbClient.doReadAllJsonData(ri.getAlias(c), ri.getDataType(c), false); - data.addAll(result.getHits()); + // TODO : check why doReadAllJsonData are comment + //SearchResult<SearchHit> result = null;//this.dbClient.doReadAllJsonData(ri.getAlias(c), ri.getDataType(c), false); + //data.addAll(result.getHits()); container.addComponent(c, data); } try { diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/istanbul/IstanbulReleaseInformation.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/istanbul/IstanbulReleaseInformation.java index 0dcd3ae3c..8a0aeb05e 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/istanbul/IstanbulReleaseInformation.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/istanbul/IstanbulReleaseInformation.java @@ -21,9 +21,12 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.istanbul; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterSettingsRequest; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterSettingsResponse; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName; @@ -35,13 +38,17 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.honolulu.HonoluluReleaseInformation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class IstanbulReleaseInformation extends ReleaseInformation { - private static final String TIMEZONE_TYPE_FORMAT = + private final Logger LOG = LoggerFactory.getLogger(IstanbulReleaseInformation.class); + + public static final String TIMEZONE_TYPE_FORMAT = "CHAR(6) DEFAULT NULL CHECK (`%s` regexp '^[+-]\\\\d\\\\d:\\\\d\\\\d$')"; - private static final String TABLENAME_CONTROLLER_FORMAT = "controller%s"; - private static final String TABLEMAPPING_CONTROLLER = + public static final String TABLENAME_CONTROLLER_FORMAT = "controller%s"; + public static final String TABLEMAPPING_CONTROLLER = "`id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,`desc` VARCHAR(255) CHARACTER SET utf8 ,primary key(id)"; private static final String TABLEMAPPING_CONNECTIONLOG_FORMAT = "`id` int(11) NOT NULL AUTO_INCREMENT,\n" + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + "`timestamp` DATETIME(3) ,\n" @@ -93,7 +100,7 @@ public class IstanbulReleaseInformation extends ReleaseInformation { private static final String TABLEMAPPING_INVENTORY_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n" + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + "`version` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`type-name` VARCHAR(255) CHARACTER SET utf8 ,\n" - + "`date` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`description` VARCHAR(255) CHARACTER SET utf8 ,\n" + + "`date` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`description` VARCHAR(1024) CHARACTER SET utf8 ,\n" + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`uuid` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`part-type-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`model-identifier` VARCHAR(255) CHARACTER SET utf8 ,\n" @@ -103,7 +110,7 @@ public class IstanbulReleaseInformation extends ReleaseInformation { + "primary key(id),foreign key(`controller-id`) references `controller%s`(id)"; private static final String TABLEMAPPING_MAINTENANCE_FORMAT = "`id` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\n" + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + "`active` BOOLEAN ,\n" - + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`description` VARCHAR(255) CHARACTER SET utf8 ,\n" + + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`description` VARCHAR(1024) CHARACTER SET utf8 ,\n" + "`problem` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`start` DATETIME(3) ,\n" + "`start-tz` " + String.format(TIMEZONE_TYPE_FORMAT, "start-tz") + " ,\n" + "`end` DATETIME(3) ,\n" + "`end-tz` " + String.format(TIMEZONE_TYPE_FORMAT, "end-tz") + " ,\n" @@ -132,7 +139,7 @@ public class IstanbulReleaseInformation extends ReleaseInformation { super(Release.ISTANBUL_R1, createDBMap(), createMariaDBMap(Release.ISTANBUL_R1.getDBSuffix())); } - private static Map<ComponentName, MariaDBTableInfo> createMariaDBMap(String suffix) { + public static Map<ComponentName, MariaDBTableInfo> createMariaDBMap(String suffix) { Map<ComponentName, MariaDBTableInfo> map = new HashMap<>(); map.put(ComponentName.CONNECTIONLOG, new MariaDBTableInfo(Entity.Connectionlog.getName(), TABLEMAPPING_CONNECTIONLOG_FORMAT)); @@ -158,7 +165,7 @@ public class IstanbulReleaseInformation extends ReleaseInformation { return map; } - private static Map<ComponentName, DatabaseInfo> createDBMap() { + public static Map<ComponentName, DatabaseInfo> createDBMap() { Map<ComponentName, DatabaseInfo> map = HonoluluReleaseInformation.createDBMap(); map.put(ComponentName.USERDATA, new DatabaseInfo7("userdata", "userdata", "{}")); map.put(ComponentName.REQUIRED_NETWORKELEMENT, new DatabaseInfo7("networkelement-connection", @@ -168,7 +175,10 @@ public class IstanbulReleaseInformation extends ReleaseInformation { + "\"core-model-capability\": {\"type\": \"keyword\"},\"device-type\": {\"type\": \"keyword\"}," + "\"device-function\": {\"type\": \"keyword\"},\"is-required\": {\"type\": \"boolean\"}," + "\"status\": {\"type\": \"keyword\"},\"tls-key\": {\"type\": \"keyword\"}," - + "\"mount-method\": {\"type\":\"keyword\"}}")); + + "\"mount-method\": {\"type\":\"keyword\"}}", + "{\"index\":{\"max_result_window\": 20000,\"number_of_shards\":%d,\"number_of_replicas\":%d}," + +"\"analysis\":{\"analyzer\":{\"content\":{\"type\":\"custom\",\"tokenizer\":\"whitespace\"}}}}" + )); return map; } @@ -182,7 +192,13 @@ public class IstanbulReleaseInformation extends ReleaseInformation { @Override public boolean runPreInitCommands(HtDatabaseClient dbClient) { - return true; + ClusterSettingsResponse response = null; + try { + response = dbClient.setupClusterSettings(new ClusterSettingsRequest(false).maxCompilationsPerMinute(400)); + } catch (IOException e) { + LOG.warn("problem setting up cluster: {}", e); + } + return response == null ? false : response.isAcknowledged(); } @Override diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/jakarta/JakartaReleaseInformation.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/jakarta/JakartaReleaseInformation.java new file mode 100644 index 000000000..03033edad --- /dev/null +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/jakarta/JakartaReleaseInformation.java @@ -0,0 +1,123 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= +c * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.jakarta; + +import java.io.IOException; +import java.util.Map; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterSettingsRequest; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterSettingsResponse; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo7; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.MariaDBTableInfo; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.istanbul.IstanbulReleaseInformation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JakartaReleaseInformation extends ReleaseInformation { + + private static final String TABLENAME_CONTROLLER_FORMAT = IstanbulReleaseInformation.TABLENAME_CONTROLLER_FORMAT; + private static final String TABLEMAPPING_CONTROLLER = IstanbulReleaseInformation.TABLEMAPPING_CONTROLLER; + private static final String TIMEZONE_TYPE_FORMAT = IstanbulReleaseInformation.TIMEZONE_TYPE_FORMAT; + private final Logger LOG = LoggerFactory.getLogger(JakartaReleaseInformation.class); + + private static final String TABLEMAPPING_CMLOG_FORMAT = + "`id` int(11) NOT NULL AUTO_INCREMENT,\n" + "`controller-id` VARCHAR(40) CHARACTER SET utf8 NOT NULL,\n" + + "`source-type` VARCHAR(100) CHARACTER SET utf8 ,\n" + + "`object-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`timestamp` DATETIME(3) ,\n" + + "`timestamp-tz` " + String.format(TIMEZONE_TYPE_FORMAT, "timestamp-tz") + + " ,\n" + "`node-id` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`counter` INTEGER ,\n" + + "`notification-type` VARCHAR(100) CHARACTER SET utf8 ,\n" + + "`notification-id` VARCHAR(40) CHARACTER SET utf8 ,\n" + + "`source-indicator` VARCHAR(100) CHARACTER SET utf8 ,\n" + + "`path` VARCHAR(255) CHARACTER SET utf8 ,\n" + "`operation` VARCHAR(100) CHARACTER SET utf8 ,\n" + + "`value` VARCHAR(255) CHARACTER SET utf8 ,\n" + "primary key(id)"; + + public JakartaReleaseInformation() { + super(Release.JAKARTA_R1, createDBMap(), createMariaDBMap()); + } + + private static Map<ComponentName, DatabaseInfo> createDBMap() { + Map<ComponentName, DatabaseInfo> map = IstanbulReleaseInformation.createDBMap(); + map.put(ComponentName.CMLOG, new DatabaseInfo7("cmlog", "cmlog", + "{\"node-id\": {\"type\": \"keyword\"},\"counter\": {\"type\": \"long\"}," + + "\"notification-id\": {\"type\": \"date\"},\"notification-type\": {\"type\": \"keyword\"}," + + "\"object-id\": {\"type\": \"long\"},\"operation\":{\"type\": \"keyword\"}," + + "\"path\": {\"type\": \"long\"},\"source-indicator\":{\"type\": \"keyword\"}," + + "\"source-type\": {\"type\": \"long\"},\"timestamp\":{\"type\": \"keyword\"}," + + "\"value\":{\"type\": \"keyword\"}}")); + return map; + } + + private static Map<ComponentName, MariaDBTableInfo> createMariaDBMap() { + Map<ComponentName, MariaDBTableInfo> map = + IstanbulReleaseInformation.createMariaDBMap(Release.JAKARTA_R1.getDBSuffix()); + map.put(ComponentName.CMLOG, new MariaDBTableInfo(Entity.Cmlog.getName(), TABLEMAPPING_CMLOG_FORMAT)); + return map; + } + + @Override + public SearchHitConverter getConverter(Release dst, ComponentName comp) { + if (dst == Release.JAKARTA_R1) { + return new KeepDataSearchHitConverter(comp); + } + return null; + } + + @Override + public boolean runPreInitCommands(HtDatabaseClient dbClient) { + ClusterSettingsResponse response = null; + try { + response = dbClient.setupClusterSettings(new ClusterSettingsRequest(false).maxCompilationsPerMinute(400)); + } catch (IOException e) { + LOG.warn("problem setting up cluster: {}", e); + } + return response == null ? false : response.isAcknowledged(); + } + + @Override + public boolean runPostInitCommands(HtDatabaseClient dbClient) { + return true; + } + + @Override + public boolean runPreInitCommands(SqlDBClient dbClient) { + boolean success = dbClient.createTable( + String.format(TABLENAME_CONTROLLER_FORMAT, this.getReleas().getDBSuffix()), TABLEMAPPING_CONTROLLER); + return success; + } + + @Override + public boolean runPostInitCommands(SqlDBClient dbClient) { + return true; + } + +} diff --git a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/MariaDBTestBase.java b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/MariaDBTestBase.java index 264f1203c..6fd4a40a4 100644 --- a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/MariaDBTestBase.java +++ b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/MariaDBTestBase.java @@ -5,6 +5,8 @@ * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,6 +37,7 @@ 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.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; 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; @@ -136,6 +139,7 @@ public class MariaDBTestBase { createTable(dbService, EventlogEntity.class, Entity.Eventlog, true); createTable(dbService, FaultcurrentEntity.class, Entity.Faultcurrent, false); createTable(dbService, FaultlogEntity.class, Entity.Faultlog, true); + createTable(dbService, CmlogEntity.class, Entity.Cmlog, true); createTable(dbService, GuicutthroughEntity.class, Entity.Guicutthrough, true); createTable(dbService, Pmdata15mEntity.class, Entity.Historicalperformance15min, false); createTable(dbService, Pmdata24hEntity.class, Entity.Historicalperformance24h, false); diff --git a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestBaseReleaseInformation.java b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestBaseReleaseInformation.java new file mode 100644 index 000000000..143611f36 --- /dev/null +++ b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestBaseReleaseInformation.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup; + +import static org.junit.Assert.assertNotNull; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName; + +public class TestBaseReleaseInformation { + + protected void assertValidComponents(ReleaseInformation ri) { + + assertNotNull(ri.getComponents()); + assertNotNull(ri.getConverter(ri.getReleas(),ComponentName.FAULTCURRENT)); + } +} diff --git a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestHonoluluReleaseInformation.java b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestHonoluluReleaseInformation.java new file mode 100644 index 000000000..727d116fd --- /dev/null +++ b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestHonoluluReleaseInformation.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.honolulu.HonoluluReleaseInformation; + +public class TestHonoluluReleaseInformation extends TestBaseReleaseInformation{ + + @Test + public void test() { + this.assertValidComponents(new HonoluluReleaseInformation()); + } + +} diff --git a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestJakartaReleaseInformation.java b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestJakartaReleaseInformation.java new file mode 100644 index 000000000..6258e31c2 --- /dev/null +++ b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestJakartaReleaseInformation.java @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import java.util.Set; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.jakarta.JakartaReleaseInformation; + +public class TestJakartaReleaseInformation { + + @Test + public void testReleaseInformation() { + JakartaReleaseInformation ri = new JakartaReleaseInformation(); + Set<ComponentName> components = ri.getComponents(); + assertTrue(components.contains(ComponentName.USERDATA)); + assertTrue(components.contains(ComponentName.REQUIRED_NETWORKELEMENT)); + assertTrue(components.contains(ComponentName.CMLOG)); + assertEquals("userdata", ri.getAlias(ComponentName.USERDATA)); + assertEquals("networkelement-connection", ri.getAlias(ComponentName.REQUIRED_NETWORKELEMENT)); + assertEquals("cmlog", ri.getAlias(ComponentName.CMLOG)); + assertEquals("cmlog-v7", ri.getIndex(ComponentName.CMLOG)); + } + +} diff --git a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestMariaDBIstanbul.java b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestMariaDBJakarta.java index 072ce2f6b..d657704fb 100644 --- a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestMariaDBIstanbul.java +++ b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestMariaDBJakarta.java @@ -34,7 +34,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.SdnrDbType; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; import ch.vorburger.exec.ManagedProcessException; -public class TestMariaDBIstanbul { +public class TestMariaDBJakarta { private static final String MARIADB_USERNAME = "sdnrdb"; private static final String MARIADB_PASSWORD = "sdnrdb"; @@ -78,7 +78,7 @@ public class TestMariaDBIstanbul { e.printStackTrace(); fail(e.getMessage()); } - boolean success = provider.initDatabase(Release.ISTANBUL_R1, 1, 1, "", false, 1000); + boolean success = provider.initDatabase(Release.JAKARTA_R1, 1, 1, "", false, 1000); assertTrue("init database failed",success); try { dbProvider.setControllerId(); |