diff options
Diffstat (limited to 'sdnr/wt/data-provider')
65 files changed, 1784 insertions, 751 deletions
diff --git a/sdnr/wt/data-provider/dblib/pom.xml b/sdnr/wt/data-provider/dblib/pom.xml index ffaad4dcb..719760c62 100644 --- a/sdnr/wt/data-provider/dblib/pom.xml +++ b/sdnr/wt/data-provider/dblib/pom.xml @@ -22,13 +22,14 @@ ~ ============LICENSE_END======================================================= ~ --> + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> - <version>2.5.3</version> + <version>2.5.4-SNAPSHOT</version> <relativePath/> </parent> diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java index b93145cbb..dc1241156 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/SqlDBClient.java @@ -63,7 +63,6 @@ public class SqlDBClient { private static final String SELECT_VERSION_QUERY = "SELECT @@version as version"; private static final String DBNAME_DEFAULT = "sdnrdb"; - private static final int DEFAULT_POOLSIZE = 50; private final String dbConnectionString; private final String dbName; private final String dbHost; @@ -306,7 +305,8 @@ public class SqlDBClient { } public Connection getConnection() throws SQLException { - return DriverManager.getConnection(this.dbConnectionString); + return this.connectionPool.getConnection(); + //return DriverManager.getConnection(this.dbConnectionString); } public boolean delete(String query) throws SQLException { diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/PropertyList.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/PropertyList.java new file mode 100644 index 000000000..d2321fc2b --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/PropertyList.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 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.ArrayList; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; +import org.opendaylight.yangtools.yang.binding.DataObject; + +@SuppressWarnings("serial") +public class PropertyList extends ArrayList<SqlPropertyInfo> { + + + public PropertyList(Class<? extends DataObject> clazz){ + super(SqlDBMapper.getProperties(clazz)); + } + +} 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 cb66fc6fb..d00941d86 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 @@ -28,7 +28,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.concurrent.TimeUnit; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.HtDatabaseEventsService; @@ -39,9 +38,11 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlD 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.DatabaseDataProvider; 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.onap.ccsdk.features.sdnr.wt.dataprovider.model.InventoryTreeProvider; 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; @@ -64,6 +65,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.ReadFaultcurrentListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMediatorServerListOutputBuilder; @@ -101,6 +103,7 @@ 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.maintenance.list.output.Data> maintenanceRW; private final SqlDBStatusReader readStatus; private final HtUserdataManager usermanager; + private final InventoryTreeProvider inventoryTreeProvider; public SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> getMaintenanceReaderWriter() { @@ -145,6 +148,8 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa LOG.warn("problem setting controllerId: ", e); } } + this.inventoryTreeProvider = new SqlDbInventoryTreeProvider(this.dbClient, this.getControllerId()); + } @@ -242,6 +247,17 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa } @Override + public ReadInventoryDeviceListOutputBuilder readInventoryDeviceList(EntityInput input) { + ReadInventoryDeviceListOutputBuilder outputBuilder = new ReadInventoryDeviceListOutputBuilder(); + QueryResult<String> result = this.equipmentRW.getDataDeviceList(input); + outputBuilder.setPagination( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.device.list.output.PaginationBuilder( + result.getPagination()).build()); + outputBuilder.setData(result.getResultSet()); + return outputBuilder; + } + + @Override public ReadConnectionlogListOutputBuilder readConnectionlogList(EntityInput input) { ReadConnectionlogListOutputBuilder outputBuilder = new ReadConnectionlogListOutputBuilder(); QueryResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.Data> result = @@ -504,7 +520,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa } LOG.info("set controllerId {}", this.controllerId); String query = - String.format("SELECT * FROM `%s` WHERE `id`='%s';", this.controllerTableName, this.controllerId); + String.format("SELECT * FROM `%s` WHERE `id`='%s'", this.controllerTableName, this.controllerId); LOG.trace(query); ResultSet data = this.dbClient.read(query); @@ -515,6 +531,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa try { if(data!=null){data.close();} } catch (SQLException ignore) { } return this.dbClient.write(query); } else { + this.controllerId = data.getString(0); LOG.trace("controllerId already set"); } return true; @@ -533,5 +550,10 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa return this.usermanager; } + @Override + public InventoryTreeProvider getInventoryTreeProvider() { + return this.inventoryTreeProvider; + } + } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDbInventoryTreeProvider.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDbInventoryTreeProvider.java new file mode 100644 index 000000000..425007016 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDbInventoryTreeProvider.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.BaseInventoryTreeProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListInputBuilder; +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.Sortorder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.SortorderBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.SortorderKey; + +public class SqlDbInventoryTreeProvider extends BaseInventoryTreeProvider { + private final SqlDBReaderWriter<Inventory> dbReader; + + public SqlDbInventoryTreeProvider(SqlDBClient dbClient, String controllerId) { + this.dbReader = new SqlDBReaderWriter<>(dbClient, Entity.Inventoryequipment, "", Inventory.class, controllerId); + } + + @Override + protected List<String> getAllNodeIds() { + return this.dbReader.readAll(INVENTORY_PROPERTY_NODEID); + } + + @Override + protected List<InventoryEntity> search(String filter, String sortOrderProperty, SortOrder sortOrder) { + return new ArrayList<>(this.dbReader.searchAll(Inventory.class, null, filter)); + } + + @Override + protected List<InventoryEntity> search(String filter, String nodeId, String parentUuid, String uuid, + String sortOrderProperty, SortOrder sortOrder) { + List<Filter> filters = new ArrayList<>(); + if (nodeId != null) { + filters.add(new FilterBuilder().setProperty(INVENTORY_PROPERTY_NODEID).setFiltervalue(nodeId).build()); + } + EntityInput input = new ReadInventoryListInputBuilder() + .setFilter(YangHelper2.getListOrMap(FilterKey.class, filters)).build(); + return new ArrayList<>(this.dbReader.searchAll(Inventory.class, input, filter)); + } + + @Override + protected List<InventoryEntity> getItemsForNodes(List<String> nodeIds, String sortOrderProperty, + SortOrder sortOrder) { + Map<FilterKey, Filter> nodeFilter = new HashMap<>(); + Filter filter = new FilterBuilder().setProperty(INVENTORY_PROPERTY_NODEID) + .setFiltervalues(nodeIds.stream().collect(Collectors.toSet())).build(); + nodeFilter.put(filter.key(), filter); + Map<SortorderKey, Sortorder> so = new HashMap<>(); + Sortorder soItem = new SortorderBuilder().setProperty(sortOrderProperty) + .setSortorder(YangHelper2.getSortOrder(sortOrder)).build(); + so.put(soItem.key(), soItem); + EntityInput input = new ReadInventoryListInputBuilder().setFilter(nodeFilter).setSortorder(so).build(); + return new ArrayList<>(this.dbReader.readAll(Inventory.class, input)); + } +} diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlPropertyInfo.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlPropertyInfo.java new file mode 100644 index 000000000..76e5d70fe --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlPropertyInfo.java @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 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.lang.reflect.Method; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; + +public class SqlPropertyInfo { + + private final Class<?> javaType; + private final String name; + private final String sqlType; + + public SqlPropertyInfo(Method method) throws SqlDBMapper.UnableToMapClassException { + this.name = SqlDBMapper.getColumnName(method); + this.javaType = method.getReturnType(); + this.sqlType = SqlDBMapper.getDBType(this.javaType); + } + + public SqlPropertyInfo(String name, Class<?> javaType, String sqlType){ + this.name =name; + this.javaType = javaType; + this.sqlType = sqlType; + } + + public boolean isSqlStringType(){ + return String.class.equals(this.javaType); + } + + public String getName() { + return this.name; + } + + public String getSqlType() { + return sqlType; + } +} 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 index bb1268cc9..b10aaaa60 100644 --- 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 @@ -26,7 +26,6 @@ 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; @@ -71,7 +70,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject; * */ @Generated("mdsal-binding-generator") -public class UserdataBuilder implements Builder<Userdata> { +public class UserdataBuilder { private String _id; private String _value; @@ -148,7 +147,7 @@ public class UserdataBuilder implements Builder<Userdata> { return this; } - @Override + public Userdata build() { return new UserdataImpl(this); } 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 776c91fe5..09baa3775 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 @@ -35,6 +35,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriterFault; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriterInventory; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBReaderWriterPm; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; @@ -68,12 +69,12 @@ public class HtDatabaseEventsService implements DataProvider { private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();; protected final SqlDBClient dbClient; - protected final String controllerId; + protected String controllerId; protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.Data> connectionlogRW; protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.eventlog.list.output.Data> eventlogRW; protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultlog.list.output.Data> eventRWFaultLog; protected final SqlDBReaderWriterFault<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultcurrent.list.output.Data> eventRWFaultCurrent; - protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data> equipmentRW; + protected final SqlDBReaderWriterInventory<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data> equipmentRW; protected final SqlDBReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.gui.cut.through.entry.output.Data> guicutthroughRW; 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; @@ -101,7 +102,7 @@ public class HtDatabaseEventsService implements DataProvider { this.eventRWFaultCurrent = new SqlDBReaderWriterFault<>(dbClient, Entity.Faultcurrent, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.faultcurrent.list.output.Data.class, this.controllerId); - this.equipmentRW = new SqlDBReaderWriter<>(dbClient, Entity.Inventoryequipment, config.getDbSuffix(), + this.equipmentRW = new SqlDBReaderWriterInventory<>(dbClient, Entity.Inventoryequipment, config.getDbSuffix(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data.class, this.controllerId); this.guicutthroughRW = new SqlDBReaderWriter<>(dbClient, diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java index 1c24636db..8167c7bbf 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java @@ -34,7 +34,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; - +import java.util.stream.Collectors; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.SqlPropertyInfo; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.DBKeyValuePair; import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper; import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper; @@ -91,8 +92,7 @@ public class SqlDBMapper { } public static <T> String createTable(Class<T> clazz, Entity e, String suffix, boolean autoIndex, - boolean withControllerId) - throws UnableToMapClassException { + boolean withControllerId) throws UnableToMapClassException { StringBuilder sb = new StringBuilder(); sb.append("CREATE TABLE IF NOT EXISTS `" + e.getName() + suffix + "` (\n"); if (autoIndex) { @@ -101,7 +101,7 @@ public class SqlDBMapper { } else { sb.append("`" + ID_DBCOL + "` " + STRING_DBTYPE + " " + getColumnOptions(ID_DBCOL, STRING_DBTYPE) + ",\n"); } - if(withControllerId) { + if (withControllerId) { sb.append("`" + ODLID_DBCOL + "` " + ODLID_DBTYPE + " " + getColumnOptions(ODLID_DBCOL, ODLID_DBTYPE) + ",\n"); } for (Method method : getFilteredMethods(clazz, true)) { @@ -115,7 +115,7 @@ public class SqlDBMapper { sb.append("`" + colName + "` " + dbType + " " + options + ",\n"); } sb.append("primary key(" + ID_DBCOL + ")"); - if(withControllerId) { + if (withControllerId) { sb.append(",foreign key(`" + ODLID_DBCOL + "`) references " + TABLENAME_CONTROLLER + "(" + ID_DBCOL + ")"); } @@ -138,6 +138,12 @@ public class SqlDBMapper { return options.toString(); } + /** + * + * @param clazz Class to scan for methods for their properties + * @param getterOrSetter true for using only getters, false using setters + * @return + */ public static List<Method> getFilteredMethods(Class<?> clazz, boolean getterOrSetter) { Method[] methods = clazz.getMethods(); List<Method> list = new ArrayList<>(); @@ -220,7 +226,7 @@ public class SqlDBMapper { return convertCamelToKebabCase(camelName); } - private static String getDBType(Class<?> valueType) throws UnableToMapClassException { + public static String getDBType(Class<?> valueType) throws UnableToMapClassException { String type = mariaDBTypeMap.getOrDefault(valueType, null); if (type == null) { if (implementsInterface(valueType, DataObject.class) || implementsInterface(valueType, List.class) @@ -292,6 +298,16 @@ public class SqlDBMapper { return result.toString(); } + public static List<SqlPropertyInfo> getProperties(Class<? extends DataObject> clazz) { + return getFilteredMethods(clazz, true).stream().map(e -> { + try { + return new SqlPropertyInfo(e); + } catch (UnableToMapClassException ex) { + throw new RuntimeException(ex); + } + }).collect(Collectors.toList()); + } + public static class UnableToMapClassException extends Exception { private static final long serialVersionUID = 1L; @@ -307,11 +323,12 @@ public class SqlDBMapper { } public static String escape(String o) { - return o.replace("'", "\'"); + return o.replace("'", "\\'"); } public static boolean isComplex(Class<?> valueType) { - return DataObject.class.isAssignableFrom(valueType) || List.class.isAssignableFrom(valueType); + return DataObject.class.isAssignableFrom(valueType) || List.class.isAssignableFrom(valueType) + || Set.class.isAssignableFrom(valueType); } public static Object getNumericValue(Object value, Class<?> valueType) { @@ -353,15 +370,15 @@ public class SqlDBMapper { } @SuppressWarnings("unchecked") - public static <S,T> List<T> read(ResultSet data, Class<T> clazz, String column) + public static <S, T> List<T> read(ResultSet data, Class<T> clazz, String column) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SQLException, InstantiationException, SecurityException, NoSuchMethodException, JsonProcessingException { - if(data==null) { + if (data == null) { return Arrays.asList(); } S builder = findPOJOBuilder(clazz); - if(builder==null && column==null) { - throw new InstantiationException("unable to find builder for class "+clazz.getName()); + if (builder == null && column == null) { + throw new InstantiationException("unable to find builder for class " + clazz.getName()); } List<T> list = new ArrayList<>(); @@ -387,13 +404,14 @@ public class SqlDBMapper { } @SuppressWarnings("unchecked") - private static <S,T> T callBuild(S builder) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Method method = builder.getClass().getMethod("build"); - return (T) method.invoke(builder); - } + private static <S, T> T callBuild(S builder) throws NoSuchMethodException, SecurityException, + IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method method = builder.getClass().getMethod("build"); + return (T) method.invoke(builder); + } - @SuppressWarnings("unchecked") - private static <S,T> S findPOJOBuilder(Class<T> ac) throws InstantiationException, IllegalAccessException, + @SuppressWarnings("unchecked") + private static <S, T> S findPOJOBuilder(Class<T> ac) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, NoSuchMethodException { try { String builder = null; @@ -407,7 +425,7 @@ public class SqlDBMapper { } if (builder != null) { Class<?> innerBuilder = YangToolsMapperHelper.findClass(builder); - //Class<Builder<T>> builderClass = (Class<Builder<T>>) innerBuilder; + // Class<Builder<T>> builderClass = (Class<Builder<T>>) innerBuilder; return (S) innerBuilder.getDeclaredConstructor().newInstance(); } } catch (ClassNotFoundException e) { @@ -464,9 +482,9 @@ public class SqlDBMapper { } else if (dstType.equals(Long.class)) { return value; } else if (dstType.equals(Integer.class)) { - return (int)value; + return (int) value; } else if (dstType.equals(Byte.class)) { - return (byte)value; + return (byte) value; } return null; } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReader.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReader.java new file mode 100644 index 000000000..9798d12f8 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReader.java @@ -0,0 +1,210 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 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 com.fasterxml.jackson.core.JsonProcessingException; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.PropertyList; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SqlQuery; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.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.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class SqlDBReader<T extends DataObject> { + private static final Logger LOG = LoggerFactory.getLogger(SqlDBReader.class); + + protected final Entity entity; + private final Class<T> clazz; + protected final SqlDBClient dbService; + protected final String controllerId; + protected final String tableName; + protected final boolean ignoreControllerId; + protected final PropertyList propertyList; + public SqlDBReader(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, + String controllerId) { + this(dbService, e, dbSuffix, clazz, controllerId, false); + } + + public SqlDBReader(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, + String controllerId, boolean ignoreControllerId) { + this.dbService = dbService; + this.entity = e; + this.clazz = clazz; + this.tableName = this.entity.getName() + dbSuffix; + this.controllerId = controllerId; + this.ignoreControllerId = ignoreControllerId; + this.propertyList = new PropertyList(clazz); + } + + public long count(List<Filter> filter) throws SQLException { + String query; + if (filter == null || filter.isEmpty()) { + // query = String.format("SELECT table_rows FROM `information_schema`.`tables` " + // + "WHERE `table_schema` = '%s' AND `table_name` = '%s'", this.dbName, this.tableName); + query = String.format("SELECT COUNT(`id`) FROM `%s`", this.tableName); + } else { + query = String.format("SELECT COUNT(`id`) FROM `%s` %s", this.tableName, + SqlQuery.getWhereExpression(filter)); + } + ResultSet data = this.dbService.read(query); + if (data == null) { + return 0; + } + long cnt = 0; + if (data.next()) { + cnt = data.getLong(1); + } + try { + data.close(); + } catch (SQLException ignore) { + } + return cnt; + } + + public long count(List<Filter> list, String controllerId) throws SQLException { + if (list == null) { + list = new ArrayList<>(); + } + Optional<Filter> cFilter = + list.stream().filter(e -> SqlDBMapper.ODLID_DBCOL.equals(e.getProperty())).findFirst(); + if (!cFilter.isEmpty()) { + list.remove(cFilter.get()); + } + if (controllerId != null) { + list.add( + new FilterBuilder().setProperty(SqlDBMapper.ODLID_DBCOL).setFiltervalue(this.controllerId).build()); + } + return this.count(list); + } + + public QueryResult<T> getData(EntityInput input) { + SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } + try { + ResultSet data = this.dbService.read(query.toSql()); + List<T> mappedData = SqlDBMapper.read(data, clazz); + final Map<FilterKey, Filter> filter = input.getFilter(); + try { + if (data != null) { + data.close(); + } + } catch (SQLException ignore) { + } + long total = this.count(filter != null ? new ArrayList<>(filter.values()) : null, this.controllerId); + return new QueryResult<T>(mappedData, query.getPage(), query.getPageSize(), total); + } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { + LOG.warn("problem reading data {}: ", this.entity, e); + } + return QueryResult.createEmpty(); + } + + public <S extends DataObject> List<S> readAll(Class<S> clazz) { + SelectQuery query = new SelectQuery(this.tableName, this.controllerId); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } + return this.readAll(clazz, query); + } + + public <S extends DataObject> List<S> readAll(Class<S> clazz, EntityInput input) { + SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId); + return this.readAll(clazz, query); + } + public <S extends DataObject> List<S> searchAll(Class<S> clazz, EntityInput input, String searchTerm) { + SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId); + if(searchTerm!=null && !searchTerm.isEmpty()) { + query.setAllPropertyFilter(searchTerm, this.propertyList); + } + return this.readAll(clazz, query); + } + public <S extends DataObject> List<S> readAll(Class<S> clazz, SelectQuery query) { + try { + ResultSet data = this.dbService.read(query.toSql()); + List<S> mappedData = SqlDBMapper.read(data, clazz); + try { + data.close(); + } catch (SQLException ignore) { + } + return mappedData; + } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { + LOG.warn("problem reading all data{}: ", this.entity, e); + } + return null; + } + + public List<String> readAll(String key) { + SelectQuery query = new SelectQuery(this.tableName, key, this.controllerId).groupBy(key); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } + try { + ResultSet data = this.dbService.read(query.toSql()); + List<String> mappedData = SqlDBMapper.read(data, String.class, key); + try { + data.close(); + } catch (SQLException ignore) { + } + return mappedData; + } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { + LOG.warn("problem reading all data {} for key: ", this.entity, key, e); + } + return null; + } + + public T read(String id) { + SelectQuery query = + new SelectQuery(this.tableName, this.controllerId).addFilter(SqlDBMapper.ID_DBCOL, id); + if (LOG.isTraceEnabled()) { + LOG.trace("query={}", query.toSql()); + } + T item = null; + try { + ResultSet data = this.dbService.read(query.toSql()); + List<T> mappedData = SqlDBMapper.read(data, clazz); + item = mappedData.size() > 0 ? mappedData.get(0) : null; + } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { + LOG.warn("problem reading data {}: ", this.entity, e); + } + return item; + } +} diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java index 56a986e55..0df2dc5d6 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java @@ -21,128 +21,39 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database; -import com.fasterxml.jackson.core.JsonProcessingException; -import java.lang.reflect.InvocationTargetException; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Optional; import org.eclipse.jdt.annotation.Nullable; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.DeleteQuery; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.InsertQuery; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SqlQuery; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.UpdateQuery; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.UpsertQuery; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.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.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SqlDBReaderWriter<T extends DataObject> { +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.List; - private static final Logger LOG = LoggerFactory.getLogger(SqlDBReaderWriter.class); +public class SqlDBReaderWriter<T extends DataObject> extends SqlDBReader<T> { - protected final Entity entity; - private final Class<T> clazz; - protected final SqlDBClient dbService; - protected final String controllerId; - protected final String tableName; - private final boolean ignoreControllerId; + private static final Logger LOG = LoggerFactory.getLogger(SqlDBReaderWriter.class); public SqlDBReaderWriter(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String controllerId) { - this(dbService, e, dbSuffix, clazz, controllerId, false); + super(dbService, e, dbSuffix, clazz, controllerId); } public SqlDBReaderWriter(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String controllerId, boolean ignoreControllerId) { - this.dbService = dbService; - this.entity = e; - this.clazz = clazz; - this.tableName = this.entity.getName() + dbSuffix; - this.controllerId = controllerId; - this.ignoreControllerId = ignoreControllerId; - } - - public long count(List<Filter> filter) throws SQLException { - String query; - if (filter == null || filter.isEmpty()) { - // query = String.format("SELECT table_rows FROM `information_schema`.`tables` " - // + "WHERE `table_schema` = '%s' AND `table_name` = '%s'", this.dbName, this.tableName); - query = String.format("SELECT COUNT(`id`) FROM `%s`", this.tableName); - } else { - query = String.format("SELECT COUNT(`id`) FROM `%s` %s", this.tableName, - SqlQuery.getWhereExpression(filter)); - } - ResultSet data = this.dbService.read(query); - if(data==null) { - return 0; - } - long cnt = 0; - if (data.next()) { - cnt = data.getLong(1); - } - try { - data.close(); - } catch (SQLException ignore) { - } - return cnt; - } - - public long count(List<Filter> list, String controllerId) throws SQLException { - if (list == null) { - list = new ArrayList<>(); - } - Optional<Filter> cFilter = - list.stream().filter(e -> SqlDBMapper.ODLID_DBCOL.equals(e.getProperty())).findFirst(); - if (!cFilter.isEmpty()) { - list.remove(cFilter.get()); - } - if (controllerId != null) { - list.add( - new FilterBuilder().setProperty(SqlDBMapper.ODLID_DBCOL).setFiltervalue(this.controllerId).build()); - } - return this.count(list); - } - - public QueryResult<T> getData(EntityInput input) { - SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId); - if (LOG.isTraceEnabled()) { - LOG.trace("query={}", query.toSql()); - } - try { - ResultSet data = this.dbService.read(query.toSql()); - List<T> mappedData = SqlDBMapper.read(data, clazz); - final Map<FilterKey, Filter> filter = input.getFilter(); - try { - if(data!=null) { - data.close(); - } - } catch (SQLException ignore) { - } - long total = this.count(filter != null ? new ArrayList<>(filter.values()) : null, this.controllerId); - return new QueryResult<T>(mappedData, query.getPage(), query.getPageSize(), total); - } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { - LOG.warn("problem reading data {}: ", this.entity, e); - } - return QueryResult.createEmpty(); + super(dbService, e, dbSuffix, clazz, controllerId, ignoreControllerId); } - - public <S extends DataObject> String write(S object, String id) { if (id == null) { return this.writeWithoutId(object); @@ -309,62 +220,4 @@ public class SqlDBReaderWriter<T extends DataObject> { public int remove(@Nullable String id) { return this.remove(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(id).build())); } - - public <S extends DataObject> List<S> readAll(Class<S> clazz) { - SelectQuery query = new SelectQuery(this.tableName); - if (LOG.isTraceEnabled()) { - LOG.trace("query={}", query.toSql()); - } - try { - ResultSet data = this.dbService.read(query.toSql()); - List<S> mappedData = SqlDBMapper.read(data, clazz); - try { - data.close(); - } catch (SQLException ignore) { - } - return mappedData; - } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { - LOG.warn("problem reading all data{}: ", this.entity, e); - } - return null; - } - - public List<String> readAll(String key) { - SelectQuery query = new SelectQuery(this.tableName, key, this.controllerId).groupBy(key); - if (LOG.isTraceEnabled()) { - LOG.trace("query={}", query.toSql()); - } - try { - ResultSet data = this.dbService.read(query.toSql()); - List<String> mappedData = SqlDBMapper.read(data, String.class, key); - try { - data.close(); - } catch (SQLException ignore) { - } - return mappedData; - } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { - LOG.warn("problem reading all data {} for key: ", this.entity, key, e); - } - return null; - } - - public T read(String id) { - SelectQuery query = - new SelectQuery(this.tableName, this.controllerId).addFilter(SqlDBMapper.ID_DBCOL, id); - if (LOG.isTraceEnabled()) { - LOG.trace("query={}", query.toSql()); - } - T item = null; - try { - ResultSet data = this.dbService.read(query.toSql()); - List<T> mappedData = SqlDBMapper.read(data, clazz); - item = mappedData.size()>0? mappedData.get(0): null; - } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { - LOG.warn("problem reading data {}: ", this.entity, e); - } - return item; - } } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterInventory.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterInventory.java new file mode 100644 index 000000000..5ed44cb29 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterInventory.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 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 com.fasterxml.jackson.core.JsonProcessingException; +import java.lang.reflect.InvocationTargetException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult; +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.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SqlDBReaderWriterInventory<T extends DataObject> extends SqlDBReaderWriter<T> { + + private final Logger LOG = LoggerFactory.getLogger(SqlDBReaderWriterInventory.class); + + private static final String KEY = "node-id"; + + private static final FilterKey FILTERKEY = new FilterKey(KEY); + + public SqlDBReaderWriterInventory(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, + String controllerId) { + super(dbService, e, dbSuffix, clazz, controllerId); + } + + /** + * get aggregated devices list + * + * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name') + * @return + */ + public QueryResult<String> getDataDeviceList(EntityInput input) { + + SelectQuery query = new SelectQuery(this.tableName, KEY, this.controllerId).groupBy(KEY); + query.setPagination(input.getPagination()); + Map<FilterKey, Filter> filter = input.getFilter(); + if (filter != null) { + for (Filter f : filter.values()) { + query.addFilter(f.getProperty(), f.getFiltervalue()); + } + } + + try { + ResultSet data = this.dbService.read(query.toSql()); + List<String> mappedData = SqlDBMapper.read(data, String.class, KEY); + try { data.close(); } catch (SQLException ignore) { } + Map<FilterKey, Filter> inpFilter = input.getFilter(); + long total = this.count(inpFilter != null ? new ArrayList<>(inpFilter.values()) : null, this.controllerId); + return new QueryResult<>(mappedData, query.getPage(), query.getPageSize(), total); + } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) { + LOG.warn("problem reading device list: ", e); + } + return null; + } + + +} diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java index 258cd160f..398e9501a 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriterUserdata.java @@ -30,8 +30,4 @@ public class SqlDBReaderWriterUserdata extends SqlDBReaderWriter<Userdata> { public SqlDBReaderWriterUserdata(SqlDBClient dbService, Entity e, String dbSuffix) { super(dbService, e, dbSuffix, Userdata.class, null, true); } - - - - } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java index f52fbd55a..c505816ef 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/InsertQuery.java @@ -107,7 +107,7 @@ public class InsertQuery<T extends DataObject> implements SqlQuery { } if (this.id != null && !cols.contains("`id`")) { cols.add("`id`"); - args.add("'" + this.id + "'"); + args.add("'" + SqlDBMapper.escape(this.id) + "'"); } if (!this.ignoreControllerId) { args.add("'" + this.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 a4df26bae..48165f1bf 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 @@ -28,7 +28,9 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.PropertyList; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.SqlDBSearchFilter; 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.SortOrder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter; @@ -49,10 +51,12 @@ public class SelectQuery implements SqlQuery { private final String tableName; private final List<Filter> filters; private final List<String> sortExpressions; + private final String controllerId; private long page; private long pageSize; private final List<String> fields; private final List<String> groups; + private SqlDBSearchFilter allPropertyFilter; public SelectQuery(String tableName) { this(tableName, (String)null); @@ -68,6 +72,8 @@ public class SelectQuery implements SqlQuery { this.groups = new ArrayList<>(); this.page = DEFAULT_PAGE; this.pageSize = DEFAULT_PAGESIZE; + this.controllerId = controllerId; + this.allPropertyFilter = null; if (controllerId != null) { this.addFilter(SqlDBMapper.ODLID_DBCOL, controllerId); } @@ -146,7 +152,9 @@ public class SelectQuery implements SqlQuery { public void addSortOrder(String col, String order) { this.sortExpressions.add(String.format("`%s` %s", col, order)); } - + public void setAllPropertyFilter(String filter, PropertyList propertyList) { + this.allPropertyFilter = new SqlDBSearchFilter(propertyList, filter); + } public void setPagination(long page, long pageSize) { this.page = page; this.pageSize = pageSize; @@ -175,7 +183,7 @@ public class SelectQuery implements SqlQuery { } else { sb.append(String.format("SELECT `%s` FROM `%s`", String.join("`,`", this.fields), this.tableName)); } - sb.append(SqlQuery.getWhereExpression(this.filters)); + sb.append(SqlQuery.getWhereExpression(this.filters, this.controllerId, this.allPropertyFilter)); if (this.groups.size() > 0) { sb.append(String.format(" GROUP BY `%s`", String.join("`,`", this.groups))); } @@ -198,5 +206,27 @@ public class SelectQuery implements SqlQuery { this.groups.add(group); return this; } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SelectQuery [tableName="); + builder.append(tableName); + builder.append(", filters="); + builder.append(filters); + builder.append(", sortExpressions="); + builder.append(sortExpressions); + builder.append(", page="); + builder.append(page); + builder.append(", pageSize="); + builder.append(pageSize); + builder.append(", fields="); + builder.append(fields); + builder.append(", groups="); + builder.append(groups); + builder.append("]"); + return builder.toString(); + } + + } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java index c954faadb..89638cc8b 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SqlQuery.java @@ -36,6 +36,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlD import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.DBFilterKeyValuePair; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.RangeSqlDBFilter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.RegexSqlDBFilter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.SqlDBSearchFilter; 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.entity.input.Filter; @@ -58,26 +59,32 @@ public interface SqlQuery { return getWhereExpression(filters, null); } public static String getWhereExpression(Collection<Filter> filters, String controllerId) { + return getWhereExpression(filters, controllerId, null); + } + public static String getWhereExpression(Collection<Filter> filters, String controllerId, SqlDBSearchFilter allPropertyFilter) { if (filters == null && controllerId == null) { return ""; } StringBuilder sb = new StringBuilder(); List<String> filters2 = filters != null - ? filters.stream().filter(e -> !"*".equals(e.getFiltervalue())).map(e -> getFilterExpression(e)) + ? filters.stream().filter(e -> !isFilterEmpty(e)).map(e -> getFilterExpression(e)) .collect(Collectors.toList()) : new ArrayList<>(); - if(controllerId!=null) { + if (controllerId != null) { filters2.add(getFilterExpression(SqlDBMapper.ODLID_DBCOL, controllerId)); } - if (!filters2.isEmpty() ) { + if(allPropertyFilter!=null){ + filters2.add(allPropertyFilter.getFilterExpression(true)); + } + if (!filters2.isEmpty()) { sb.append(" WHERE "); sb.append(StringUtil.join(" AND ", filters2)); } return sb.toString(); } - public static String getFilterExpression(Filter filter) { + private static String getFilterExpression(Filter filter) { String property = filter.getProperty(); List<String> values = collectValues(filter.getFiltervalue(), filter.getFiltervalues()).stream() .filter(e -> !"*".equals(e)).collect(Collectors.toList()); @@ -95,7 +102,7 @@ public interface SqlQuery { return null; } - public static String getFilterExpression(String property, String value) { + private static String getFilterExpression(String property, String value) { String filter = null; if (DbFilter.hasSearchParams(value)) { if (TIMESTAMPPROPERTYNAMES.contains(property.toLowerCase())) { @@ -118,7 +125,7 @@ public interface SqlQuery { return new DBFilterKeyValuePair(property, value).getFilterExpression(); } - static List<String> collectValues(String filtervalue, Set<String> filtervalues) { + private static List<String> collectValues(String filtervalue, Set<String> filtervalues) { if (filtervalues == null) { return Arrays.asList(filtervalue); } @@ -367,4 +374,18 @@ public interface SqlQuery { return upperEnd; } + + private static boolean isFilterEmpty(Filter filter) { + @Nullable Set<String> filtervalues = filter.getFiltervalues(); + @Nullable String filtervalue = filter.getFiltervalue(); + + List<String> allValues = filtervalues == null ? new ArrayList<>() : new ArrayList<>(filtervalues); + if (filtervalue != null) { + allValues.add(filtervalue); + } + + return allValues.isEmpty() || allValues.contains("*"); + } + + } 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 70b683a1a..7ea393da5 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 @@ -23,6 +23,8 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filter import java.math.BigInteger; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; + public class DBKeyValuePair<T> implements SqlDBFilter { private final String key; @@ -62,7 +64,7 @@ public class DBKeyValuePair<T> implements SqlDBFilter { } 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); + return String.format("`%s`='%s'", this.key, SqlDBMapper.escape(this.value)); } } } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java index 2997c7040..3ff2bdbea 100644 --- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBFilter.java @@ -25,4 +25,8 @@ public interface SqlDBFilter { public String getFilterExpression(); + default String getFilterExpression(boolean enclose) { + return enclose ? String.format("(%s)", this.getFilterExpression()) : this.getFilterExpression(); + } + } diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBSearchFilter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBSearchFilter.java new file mode 100644 index 000000000..db5f2cb3b --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/filters/SqlDBSearchFilter.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 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.query.filters; + +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.PropertyList; + +import java.util.List; +import java.util.stream.Collectors; + +public class SqlDBSearchFilter implements SqlDBFilter { + private final PropertyList propertyList; + private final String filter; + + public SqlDBSearchFilter(PropertyList propertyList, String filter) { + this.propertyList = propertyList; + this.filter = filter; + } + + @Override + public String getFilterExpression() { + List<String> tmp = this.propertyList.stream() + .map(e -> new RegexSqlDBFilter(e.getName(), this.filter).getFilterExpression()) + .collect(Collectors.toList()); + return String.join(" OR ", tmp); + } +} 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 33703042e..5942321cf 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 @@ -23,14 +23,13 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import ch.vorburger.exec.ManagedProcessException; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -38,6 +37,10 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; @@ -80,6 +83,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.MaintenanceEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionEntity; @@ -92,6 +96,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.ReadFaultcurrentListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMediatorServerListOutputBuilder; @@ -118,7 +123,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.network.element.connection.list.output.Data; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; -import ch.vorburger.exec.ManagedProcessException; public class TestMariaDataProvider { @@ -390,8 +394,47 @@ public class TestMariaDataProvider { dbProvider.writeInventory(NODEID1, list); data = dbProvider.readInventoryList(createInput(1, 50)); assertEquals(22, data.getData().size()); + ReadInventoryDeviceListOutputBuilder data2 = dbProvider.readInventoryDeviceList(createInput(1, 20)); + assertEquals(2, data2.getData().size()); + assertTrue(data2.getData().contains("sim1") && data2.getData().contains("sim2")); data = dbProvider.readInventoryList(createInput("tree-level", "0", 1, 50)); assertEquals(5, data.getData().size()); + + try { + dbProvider.writeInventory("sim3", loadListFile("/inventory2.json", Inventory.class)); + } catch (IOException e) { + fail("problem loading inventory data2"); + } + data2 = dbProvider.readInventoryDeviceList(createInput(1, 20)); + assertEquals(3, data2.getData().size()); + assertTrue(data2.getData().contains("sim1") && data2.getData().contains("sim2") && + data2.getData().contains("sim3")); + } + + @Test + public void testInventoryWithComplexTypes() { + try { + dbClient.delete(new DeleteQuery(Entity.Inventoryequipment, null).toSql()); + } catch (SQLException e) { + e.printStackTrace(); + fail("problem clearing inventoryequipment"); + } + ReadInventoryListOutputBuilder data = dbProvider.readInventoryList(createInput(1, 20)); + assertEquals(0, data.getData().size()); + try { + Inventory inventory = new InventoryBuilder() + .setContainedHolder(new HashSet<>( + Arrays.asList("STM1-1", "Radio-2A", "LAN-3-SFP", "Radio-1A", "STM1-2", "LAN-4-SFP"))) + .setSerial("14209652001003620").setDescription("INDOOR UNIT ALCPlus2e") + .setTreeLevel(Uint32.valueOf(0)).setNodeId("NTS_ONF14").build(); + dbProvider.writeInventory(NODEID1, new ArrayList<Inventory>(Arrays.asList(inventory))); + } catch (Exception e) { + e.printStackTrace(); + fail("problem loading inventory data"); + + } + data = dbProvider.readInventoryList(createInput(1, 50)); + assertEquals(1, data.getData().size()); } @Test diff --git a/sdnr/wt/data-provider/dblib/src/test/resources/inventory2.json b/sdnr/wt/data-provider/dblib/src/test/resources/inventory2.json new file mode 100644 index 000000000..b13220f28 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/test/resources/inventory2.json @@ -0,0 +1,364 @@ +[ + { + "description": "WS/p8.module/a2.module#5", + "date": "2013-04-13T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "a2.module-1.1.5.5", + "parent-uuid": "CARD-1.1.5.0", + "contained-holder": [ + "SUBRACK-1.55.0.0" + ], + "tree-level": 2, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "310330015", + "part-type-id": "3EM23141AD01", + "model-identifier": "CRPQABVFAA", + "type-name": "a2.module" + }, + { + "description": "WS/DS1", + "date": "2007-08-27T00:00:00.0Z", + "version": "p1.module", + "node-id": "sim3", + "uuid": "CARD-1.1.7.0", + "parent-uuid": "SHELF-1.1.0.0", + "contained-holder": [], + "tree-level": 1, + "manufacturer-identifier": "CIT", + "serial": "serial-number-s3s", + "part-type-id": "part-number-s3s", + "model-identifier": "model-id-s3s", + "type-name": "p1.module_A" + }, + { + "description": "MWR#55Ch#1/a2.moduletraff", + "date": "2013-04-13T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "a2.module-1.55.1.2", + "parent-uuid": "IDU-1.55.0.0", + "contained-holder": [], + "tree-level": 1, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "310330015", + "part-type-id": "3EM23141AD01", + "model-identifier": "CRPQABVFAA", + "type-name": "a2.module" + }, + { + "description": "MWR#65Ch#1/a2.moduletraff", + "date": "2013-04-13T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "a2.module-1.65.1.2", + "parent-uuid": "IDU-1.65.0.0", + "contained-holder": [], + "tree-level": 1, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "310330008", + "part-type-id": "3EM23141AD01", + "model-identifier": "CRPQABVFAA", + "type-name": "a2.module" + }, + { + "description": "WS-8", + "date": "2017-09-09T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "SHELF-1.1.0.0", + "parent-uuid": "network-element", + "contained-holder": [ + "SLOT-1.1.1.0", + "SLOT-1.1.2.0", + "SLOT-1.1.3.0", + "SLOT-1.1.4.0", + "SLOT-1.1.5.0", + "SLOT-1.1.6.0", + "SLOT-1.1.7.0", + "SLOT-1.1.8.0", + "SLOT-1.1.9.0" + ], + "tree-level": 0, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "Serial1", + "part-type-id": "Partnumber", + "model-identifier": "model-id", + "type-name": "WS-8" + }, + { + "description": "WS/CORE-MAIN/a2.module#5", + "date": "2005-11-09T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "a2.module-1.1.1.5", + "parent-uuid": "CARD-1.1.1.0", + "contained-holder": [ + "SUBRACK-1.15.0.0" + ], + "tree-level": 2, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "0003548168", + "part-type-id": "3FE25774AA01", + "model-identifier": "VAUIAEYAAA", + "type-name": "a2.module" + }, + { + "description": "WS/CORE-MAIN/a2.module#8", + "date": "2010-02-05T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "a2.module-1.1.1.8", + "parent-uuid": "CARD-1.1.1.0", + "contained-holder": [ + "SUBRACK-1.18.0.0" + ], + "tree-level": 2, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "01T441601301", + "part-type-id": "1AB376720002", + "model-identifier": "NGI7AMLMAA", + "type-name": "a2.module" + }, + { + "description": "WS/p8.module/a2.module#5", + "date": "2013-04-13T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "a2.module-1.1.6.5", + "parent-uuid": "CARD-1.1.6.0", + "contained-holder": [ + "SUBRACK-1.65.0.0" + ], + "tree-level": 2, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "310330008", + "part-type-id": "3EM23141AD01", + "model-identifier": "CRPQABVFAA", + "type-name": "a2.module" + }, + { + "description": "MWR-hyper Dir#5.6-Ch#1", + "date": "", + "version": "extrem-hyper", + "node-id": "sim3", + "uuid": "ODU-1.56.0.0", + "parent-uuid": "network-element", + "contained-holder": [ + "PORT-1.56.1.2", + "PORT-1.56.1.3", + "PORT-1.56.1.4" + ], + "tree-level": 0, + "manufacturer-identifier": "", + "serial": "", + "part-type-id": "", + "model-identifier": "", + "type-name": "MWR-hyper" + }, + { + "description": "MWR#56Ch#1/a2.moduletraff", + "date": "2017-09-09T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "a2.module-1.56.1.2", + "parent-uuid": "ODU-1.56.0.0", + "contained-holder": [], + "tree-level": 1, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "Serial1", + "part-type-id": "Partnumber", + "model-identifier": "model-id", + "type-name": "a2.module" + }, + { + "description": "MWR-ng Dir#6.5-Ch#1", + "date": "2014-01-16T00:00:00.0Z", + "version": "MWR-ng", + "node-id": "sim3", + "uuid": "IDU-1.65.0.0", + "parent-uuid": "network-element", + "contained-holder": [ + "PORT-1.65.1.4", + "PORT-1.65.1.2" + ], + "tree-level": 0, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "WAUZZI", + "part-type-id": "3DB76047BAAA02", + "model-identifier": "model-id-s3s", + "type-name": "MWR-ng" + }, + { + "description": "MWR#55Ch#0/RxDiv", + "date": "2014-01-08T00:00:00.0Z", + "version": "2017", + "node-id": "sim3", + "uuid": "CARD-1.65.1.4", + "parent-uuid": "IDU-1.65.0.0", + "contained-holder": [], + "tree-level": 1, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "Serie2017-13", + "part-type-id": "partNo2017-12", + "model-identifier": "model-id-s3s", + "type-name": "RxDiv" + }, + { + "description": "WS/p8.module", + "date": "2013-11-23T00:00:00.0Z", + "version": "234", + "node-id": "sim3", + "uuid": "CARD-1.1.6.0", + "parent-uuid": "SHELF-1.1.0.0", + "contained-holder": [ + "PORT-1.1.6.5", + "PORT-1.1.6.7", + "PORT-1.1.6.6", + "PORT-1.1.6.8" + ], + "tree-level": 1, + "manufacturer-identifier": "SAN", + "serial": "serial-number-124", + "part-type-id": "part-number-12", + "model-identifier": "model-id-12", + "type-name": "p8.module" + }, + { + "description": "WS/DS3", + "date": "2008-10-21T00:00:00.0Z", + "version": "unknown", + "node-id": "sim3", + "uuid": "CARD-1.1.8.0", + "parent-uuid": "SHELF-1.1.0.0", + "contained-holder": [], + "tree-level": 1, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "sd-dsa-eqw", + "part-type-id": "unknown", + "model-identifier": "model-id-s3s", + "type-name": "p4.module" + }, + { + "description": "WS/wind", + "date": "2007-02-19T00:00:00.0Z", + "version": "wind", + "node-id": "sim3", + "uuid": "CARD-1.1.9.0", + "parent-uuid": "SHELF-1.1.0.0", + "contained-holder": [], + "tree-level": 1, + "manufacturer-identifier": "CIT", + "serial": "proto-type", + "part-type-id": "party-yea", + "model-identifier": "model-id-s3s", + "type-name": "wind" + }, + { + "description": "MWR#55Ch#1/RxDiv", + "date": "2014-01-07T00:00:00.0Z", + "version": "2017", + "node-id": "sim3", + "uuid": "CARD-1.55.1.4", + "parent-uuid": "IDU-1.55.0.0", + "contained-holder": [], + "tree-level": 1, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "Serie2017-12", + "part-type-id": "partNo2017-12", + "model-identifier": "model-id-s3s", + "type-name": "RxDiv" + }, + { + "description": "WS/CORE-MAIN/a2.module#7", + "date": "2009-01-19T00:00:00.0Z", + "version": "a2.module-newest", + "node-id": "sim3", + "uuid": "a2.module-1.1.1.7", + "parent-uuid": "CARD-1.1.1.0", + "contained-holder": [ + "SUBRACK-1.17.0.0" + ], + "tree-level": 2, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "91T403003322", + "part-type-id": "1AB187280031", + "model-identifier": "mod2", + "type-name": "a2.module" + }, + { + "description": "MWR-ng Dir#5.5-Ch#1", + "date": "2014-01-15T00:00:00.0Z", + "version": "MWR-ng", + "node-id": "sim3", + "uuid": "IDU-1.55.0.0", + "parent-uuid": "network-element", + "contained-holder": [ + "PORT-1.55.1.2", + "PORT-1.55.1.4" + ], + "tree-level": 0, + "manufacturer-identifier": "ONF-Wireless-Transport", + "serial": "Serie2017-14", + "part-type-id": "3DB76047BAAA02", + "model-identifier": "model-id-s3s", + "type-name": "MWR-ng" + }, + { + "description": "WS/CORE-MAIN", + "date": "2015-08-17T00:00:00.0Z", + "version": "123", + "node-id": "sim3", + "uuid": "CARD-1.1.1.0", + "parent-uuid": "SHELF-1.1.0.0", + "contained-holder": [ + "PORT-1.1.1.6", + "PORT-1.1.1.5", + "PORT-1.1.1.8", + "PORT-1.1.1.7" + ], + "tree-level": 1, + "manufacturer-identifier": "SAN", + "serial": "asdf-asdasd-asd", + "part-type-id": "part-number-2", + "model-identifier": "model-id-2", + "type-name": "latest" + }, + { + "description": "WS/p8.module", + "date": "2013-10-21T00:00:00.0Z", + "version": "234", + "node-id": "sim3", + "uuid": "CARD-1.1.5.0", + "parent-uuid": "SHELF-1.1.0.0", + "contained-holder": [ + "PORT-1.1.5.6", + "PORT-1.1.5.5", + "PORT-1.1.5.8", + "PORT-1.1.5.7" + ], + "tree-level": 1, + "manufacturer-identifier": "SAN", + "serial": "africa", + "part-type-id": "part-number-12", + "model-identifier": "model-id-12", + "type-name": "p8.module" + }, + { + "description": "WS/p8.module/a2.module#6", + "date": "", + "version": "", + "node-id": "sim3", + "uuid": "a2.module-1.1.5.6", + "parent-uuid": "CARD-1.1.5.0", + "contained-holder": [ + "SUBRACK-1.56.0.0" + ], + "tree-level": 2, + "manufacturer-identifier": "", + "serial": "", + "part-type-id": "", + "model-identifier": "", + "type-name": "a2.module" + } +]
\ No newline at end of file diff --git a/sdnr/wt/data-provider/feature/pom.xml b/sdnr/wt/data-provider/feature/pom.xml index 0204097e6..d28c03782 100644 --- a/sdnr/wt/data-provider/feature/pom.xml +++ b/sdnr/wt/data-provider/feature/pom.xml @@ -22,13 +22,14 @@ ~ ============LICENSE_END======================================================= ~ --> + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>single-feature-parent</artifactId> - <version>2.5.3</version> + <version>2.5.4-SNAPSHOT</version> <relativePath/> </parent> diff --git a/sdnr/wt/data-provider/installer/pom.xml b/sdnr/wt/data-provider/installer/pom.xml index b61ff667a..69086ecb8 100755 --- a/sdnr/wt/data-provider/installer/pom.xml +++ b/sdnr/wt/data-provider/installer/pom.xml @@ -22,13 +22,14 @@ ~ ============LICENSE_END======================================================= ~ --> + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-lite</artifactId> - <version>2.5.3</version> + <version>2.5.4-SNAPSHOT</version> <relativePath/> </parent> diff --git a/sdnr/wt/data-provider/model/pom.xml b/sdnr/wt/data-provider/model/pom.xml index c683a7a05..56526ef50 100644 --- a/sdnr/wt/data-provider/model/pom.xml +++ b/sdnr/wt/data-provider/model/pom.xml @@ -22,13 +22,14 @@ ~ ============LICENSE_END======================================================= ~ --> + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> - <version>2.5.3</version> + <version>2.5.4-SNAPSHOT</version> <relativePath/> </parent> @@ -71,6 +72,11 @@ <artifactId>jackson-databind</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <scope>provided</scope> + </dependency> </dependencies> <build> diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/BaseInventoryTreeProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/BaseInventoryTreeProvider.java new file mode 100644 index 000000000..3d7f82ebd --- /dev/null +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/BaseInventoryTreeProvider.java @@ -0,0 +1,206 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 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.model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeChildObject; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryEntity; +import org.opendaylight.yangtools.yang.common.Uint32; + +public abstract class BaseInventoryTreeProvider implements InventoryTreeProvider { + + private static final String INVENTORY_PROPERTY_TREELEVEL = "tree-level"; + protected static final String INVENTORY_PROPERTY_NODEID = "node-id"; + protected static final String INVENTORY_PROPERTY_UUID = "uuid"; + protected static final String INVENTORY_PROPERTY_PARENTUUID = "parent-uuid"; + + protected abstract List<String> getAllNodeIds(); + + protected abstract List<InventoryEntity> search(String filter, String sortOrderProperty, SortOrder sortOrder); + + protected abstract List<InventoryEntity> search(String filter, String nodeId, String parentUuid, String uuid, + String sortOrderProperty, SortOrder sortOrder); + + protected abstract List<InventoryEntity> getItemsForNodes(List<String> nodeIds, String sortOrderProperty, + SortOrder sortOrder); + + + @Override + public DataTreeObject readInventoryTree(List<String> tree, String filter) throws IOException { + + //root nodes will be node-information -> below inventory + if (tree == null || tree.size() <= 0) { + return this.readInventoryTreeWithNode(filter); + } + //root node will be inventory on tree-level if sliced treePath + else { + return this.readInventoryTreeForNode(tree.get(0), tree.subList(0, tree.size() - 1), filter); + } + + } + + /** + * Provide inventory list for a node, starting from element described by path + * @param nodeId node + * @param path describing element + * @param filter + * @return Inventory tree + */ + private DataTreeObject readInventoryTreeForNode(String nodeId, List<String> path, String filter) + throws IOException { + DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID); + //get parent uuid of path + final String parentUuid = path.size() > 1 ? path.get(path.size() - 2) : null; + //get uuid of path + final String uuid = path.size() > 0 ? path.get(path.size() - 1) : null; + List<InventoryEntity> matches = + this.search(filter, nodeId, parentUuid, uuid, INVENTORY_PROPERTY_TREELEVEL, SortOrder.ASCENDING); + //tree.a(subtreePath); + List<InventoryEntity> others = + this.search((String) null, nodeId, null, null, INVENTORY_PROPERTY_TREELEVEL, SortOrder.ASCENDING); + if (matches.size() > 0) { + int treeLevelToStart = (path == null || path.size() <= 0) ? 0 : path.size() - 1; + //build tree + //fill root elems + for (InventoryEntity hit : matches) { + if (hit.getTreeLevel().longValue() == treeLevelToStart) { + tree.put(hit.getId(), + new DataTreeChildObject(hit.getUuid(), true) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + for (InventoryEntity hit : others) { + if (hit.getTreeLevel().longValue() == treeLevelToStart) { + tree.putIfNotExists(hit.getId(), + new DataTreeChildObject(hit.getUuid(), false) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + //fill child elems + for (InventoryEntity hit : matches) { + if (hit.getTreeLevel().longValue() > treeLevelToStart) { + tree.put(hit.getTreeLevel().longValue() - treeLevelToStart - 1, hit.getId(), + new DataTreeChildObject(hit.getUuid(), true) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + for (InventoryEntity hit : others) { + if (hit.getTreeLevel().longValue() > treeLevelToStart) { + tree.putIfNotExists(hit.getTreeLevel().longValue() - treeLevelToStart - 1, hit.getId(), + new DataTreeChildObject(hit.getUuid(), false) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + tree.removeUnmatchedPaths(); + } + return tree; + } + + /** + * node will be root elements inventory information below from level-1 + * + * @param filter + * @return + * @throws IOException + */ + private DataTreeObject readInventoryTreeWithNode(String filter) throws IOException { + DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID); + + List<InventoryEntity> matches = this.search(filter, INVENTORY_PROPERTY_TREELEVEL, SortOrder.ASCENDING); + List<InventoryEntity> others = null; + if (matches.size() > 0) { + if (filter != null) { + //find all parents up to tree-level 0 + String nodeId = ""; + List<String> alreadyInList = new ArrayList<>(); + for (InventoryEntity hit : matches) { + nodeId = hit.getNodeId(); + if (alreadyInList.contains(nodeId)) { + continue; + } + alreadyInList.add(nodeId); + tree.put(nodeId, + new DataTreeChildObject(nodeId, false).setProperty(INVENTORY_PROPERTY_UUID, nodeId)); + + } + others = this.getItemsForNodes(alreadyInList, INVENTORY_PROPERTY_TREELEVEL, SortOrder.ASCENDING); + } else { + List<String> nodeIds = this.getAllNodeIds(); + for (String node : nodeIds) { + tree.put(node, new DataTreeChildObject(node, false).setProperty(INVENTORY_PROPERTY_UUID, node)); + } + } + + //build tree + //fill root elems + for (InventoryEntity hit : matches) { + if (hit.getTreeLevel() == Uint32.ZERO) { + tree.put(0, hit.getId(), + new DataTreeChildObject(hit.getUuid(), true) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getNodeId())); + } + } + if (others != null) { + for (InventoryEntity hit : others) { + if (hit.getTreeLevel() == Uint32.ZERO) { + tree.putIfNotExists(0, hit.getId(), + new DataTreeChildObject(hit.getUuid(), false) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getNodeId())); + } + } + } + //fill child elements + for (InventoryEntity hit : matches) { + long treeLevel = hit.getTreeLevel().longValue(); + if (treeLevel > 0) { + tree.put(treeLevel, hit.getId(), + new DataTreeChildObject(hit.getUuid(), true) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + if (others != null) { + for (InventoryEntity hit : others) { + long treeLevel = hit.getTreeLevel().longValue(); + if (treeLevel > 0) { + tree.putIfNotExists(treeLevel, hit.getId(), + new DataTreeChildObject(hit.getUuid(), false) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + } + tree.removeUnmatchedPaths(); + } + return tree; + } +} 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/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DatabaseDataProvider.java index fbd105aa1..97b8b0de5 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/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DatabaseDataProvider.java @@ -21,15 +21,11 @@ * ============LICENSE_END========================================================= * */ -package org.onap.ccsdk.features.sdnr.wt.dataprovider.database; +package org.onap.ccsdk.features.sdnr.wt.dataprovider.model; import java.io.IOException; import java.util.concurrent.TimeUnit; 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; @@ -48,8 +44,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.ReadEventlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultlogListOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMediatorServerListOutputBuilder; @@ -138,4 +134,8 @@ public interface DatabaseDataProvider { HtUserdataManager getUserManager(); + InventoryTreeProvider getInventoryTreeProvider(); + + ReadInventoryDeviceListOutputBuilder readInventoryDeviceList(EntityInput input); + } diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/InventoryTreeProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/InventoryTreeProvider.java new file mode 100644 index 000000000..e9523418a --- /dev/null +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/InventoryTreeProvider.java @@ -0,0 +1,31 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 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.model; + +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeObject; + +import java.io.IOException; +import java.util.List; + +public interface InventoryTreeProvider { + public DataTreeObject readInventoryTree(List<String> tree, String filter) throws IOException; +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeChildObject.java index 05e6d2f13..227020505 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeChildObject.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= * */ -package org.onap.ccsdk.features.sdnr.wt.dataprovider.http; +package org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types; import java.util.ArrayList; import java.util.HashMap; @@ -31,23 +31,15 @@ import org.json.JSONObject; public class DataTreeChildObject { private final String label; -// private final String ownSeverity; -// private final String childrenSeveritySummary; - private final boolean isMatch; + private final boolean isSearchMatch; private final Map<String, DataTreeChildObject> children; private final Map<String, Object> properties; - public boolean isMatch() { - return this.isMatch; - } - public DataTreeChildObject(String label, boolean isMatch, Map<String, DataTreeChildObject> children, String ownSeverity, String childrenSeveritySummary) { this.label = label; - this.isMatch = isMatch; + this.isSearchMatch = isMatch; this.children = children; -// this.ownSeverity = ownSeverity; -// this.childrenSeveritySummary = childrenSeveritySummary; this.properties = new HashMap<>(); } @@ -56,26 +48,18 @@ public class DataTreeChildObject { return this; } - public Object getProperty(String key, Object defaultValue) { - return this.properties.getOrDefault(key, defaultValue); - } - - /** - * @param string - * @param b - */ public DataTreeChildObject(String label, boolean isMatch) { this(label, isMatch, new HashMap<>(), null, null); } - /** - * @param treeLevel - * @param id - * @param data - * @param childKey - * @param parentKey - * @return - */ + public boolean isMatch() { + return this.isSearchMatch; + } + + public Object getProperty(String key, Object defaultValue) { + return this.properties.getOrDefault(key, defaultValue); + } + public boolean putChild(long treeLevel, String id, DataTreeChildObject data, String parentKey, String childKey) { Object itemValue; Object itemValueToMatch = data.getProperty(parentKey, null); @@ -100,14 +84,6 @@ public class DataTreeChildObject { return false; } - /** - * @param treeLevel - * @param id - * @param data - * @param parentKey - * @param childKey - * @return - */ public boolean putChildIfNotExists(long treeLevel, String id, DataTreeChildObject data, String parentKey, String childKey) { Object itemValue; @@ -134,13 +110,10 @@ public class DataTreeChildObject { return false; } - /** - * @return - */ public JSONObject toJSONObject() { JSONObject o = new JSONObject(); o.put("label", this.label); - o.put("isMatch", this.isMatch); + o.put("isMatch", this.isSearchMatch); JSONObject c = new JSONObject(); if (this.children != null) { for (Entry<String, DataTreeChildObject> entry : this.children.entrySet()) { @@ -148,15 +121,13 @@ public class DataTreeChildObject { } } o.put("children", c); - //o.put("ownSeverity", null); - //o.put("childrenSeveritySummary", null); return o; } public boolean hasChildMatching() { boolean match = false; for (DataTreeChildObject child : this.children.values()) { - match = match || child.hasChildMatching() || this.isMatch; + match = match || child.hasChildMatching() || this.isSearchMatch; if (match) { break; } @@ -164,13 +135,10 @@ public class DataTreeChildObject { return match; } - /** - * - */ public void removeUnmatchedPaths() { List<String> toRemove = new ArrayList<>(); for (Entry<String, DataTreeChildObject> entry : this.children.entrySet()) { - if (!(entry.getValue().hasChildMatching() || entry.getValue().isMatch)) { + if (!(entry.getValue().hasChildMatching() || entry.getValue().isSearchMatch)) { toRemove.add(entry.getKey()); } else { entry.getValue().removeUnmatchedPaths(); @@ -182,6 +150,6 @@ public class DataTreeChildObject { } public boolean hasChildren() { - return this.children!=null && !this.children.isEmpty(); + return this.children != null && !this.children.isEmpty(); } } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeObject.java index f12ff3deb..c4b2b128d 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeObject.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= * */ -package org.onap.ccsdk.features.sdnr.wt.dataprovider.http; +package org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types; import java.util.ArrayList; import java.util.HashMap; @@ -32,58 +32,33 @@ public class DataTreeObject extends HashMap<String, DataTreeChildObject> { private final String parentKey; private final String childKey; - public DataTreeObject createTreeByPath(String[] pathFilter) { - - if (pathFilter != null && pathFilter.length > 0) { - for (String key : this.keySet()) { - if (key.equals(pathFilter[0])) { - DataTreeChildObject o = this.getChildElemByPath(this.get(key), slice(pathFilter, 1)); - DataTreeObject r = new DataTreeObject(this.parentKey, this.childKey); - r.put(key, o); - return r; - } - } - } - - return null; - - } - - private DataTreeChildObject getChildElemByPath(DataTreeChildObject source, String[] pathFilter) { - - if (pathFilter != null && pathFilter.length > 0) { - // for(String key:source..keySet()) { - // if(key.equals(pathFilter[0])){ - // DataTreeChildObject o= this.getChildElemByPath(this.get(key),slice(pathFilter,1)); - // } - // } - } - - return null; - } - public DataTreeObject(String parentKey, String childKey) { this.parentKey = parentKey; this.childKey = childKey; } - /** - * @param treeLevel - * @param id - * @param data - */ public void put(long treeLevel, String id, DataTreeChildObject data) { for (DataTreeChildObject entry : this.values()) { if (entry.putChild(treeLevel, id, data, this.parentKey, this.childKey)) { break; } } + } + + public void putIfNotExists(long treeLevel, String id, DataTreeChildObject data) { + for (DataTreeChildObject entry : this.values()) { + if (entry.putChildIfNotExists(treeLevel, id, data, this.parentKey, this.childKey)) { + break; + } + } + } + public void putIfNotExists(String id, DataTreeChildObject data) { + if (!this.containsKey(id)) { + this.put(id, data); + } } - /** - * - */ public String toJSON() { JSONObject o = new JSONObject(); for (Entry<String, DataTreeChildObject> entry : this.entrySet()) { @@ -92,9 +67,6 @@ public class DataTreeObject extends HashMap<String, DataTreeChildObject> { return o.toString(); } - /** - * - */ public void removeUnmatchedPaths() { List<String> toRemove = new ArrayList<>(); for (Entry<String,DataTreeChildObject> entry : this.entrySet()) { @@ -109,34 +81,7 @@ public class DataTreeObject extends HashMap<String, DataTreeChildObject> { } - /** - * @param treeLevel - * @param id - * @param setProperty - */ - public void putIfNotExists(long treeLevel, String id, DataTreeChildObject data) { - for (DataTreeChildObject entry : this.values()) { - if (entry.putChildIfNotExists(treeLevel, id, data, this.parentKey, this.childKey)) { - break; - } - } - } - - /** - * @param id - * @param data - */ - public void putIfNotExists(String id, DataTreeChildObject data) { - if (!this.containsKey(id)) { - this.put(id, data); - } - } - /** - * @param source - * @param i - * @return - */ public static String[] slice(String[] source, int start) { String[] r = new String[source.length - start]; for (int i = 0; i < r.length; i++) { diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/YangHelper2.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/YangHelper2.java index 423ebab0b..d0169ce06 100644 --- a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/YangHelper2.java +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/YangHelper2.java @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SortOrder; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.Identifier; import org.opendaylight.yangtools.yang.common.Uint16; @@ -113,4 +114,9 @@ public class YangHelper2 { return org.opendaylight.yangtools.yang.binding.ScalarTypeObject.class; } + public static SortOrder getSortOrder(org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder sortOrder){ + return sortOrder== org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING? + SortOrder.Ascending:SortOrder.Descending; + } + } 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 72ac45a56..0c89b675b 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 @@ -2015,6 +2015,26 @@ module data-provider { } } + rpc read-inventory-device-list { + description + "Get list of mountpoints with inventory data"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + leaf-list data { + type string; + description + "The list of found mountpoint names."; + } + } + } + rpc read-status { description "Read status information of controller"; diff --git a/sdnr/wt/data-provider/pom.xml b/sdnr/wt/data-provider/pom.xml index 631f2db68..7c2430f1a 100755 --- a/sdnr/wt/data-provider/pom.xml +++ b/sdnr/wt/data-provider/pom.xml @@ -22,13 +22,14 @@ ~ ============LICENSE_END======================================================= ~ --> + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-lite</artifactId> - <version>2.5.3</version> + <version>2.5.4-SNAPSHOT</version> <relativePath/> </parent> diff --git a/sdnr/wt/data-provider/provider/pom.xml b/sdnr/wt/data-provider/provider/pom.xml index 0b456e5c2..b94c73ea2 100644 --- a/sdnr/wt/data-provider/provider/pom.xml +++ b/sdnr/wt/data-provider/provider/pom.xml @@ -22,13 +22,14 @@ ~ ============LICENSE_END======================================================= ~ --> + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> - <version>2.5.3</version> + <version>2.5.4-SNAPSHOT</version> <relativePath/> </parent> @@ -89,8 +90,8 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> + <groupId>jakarta.servlet</groupId> + <artifactId>jakarta.servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> @@ -144,6 +145,12 @@ <artifactId>mariaDB4j</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + <version>7.0.0</version> + <scope>compile</scope> + </dependency> <!-- MariaDB end --> </dependencies> diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java index a10864c96..dbb73bdad 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/EsDataObjectReaderWriter2.java @@ -28,7 +28,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.eclipse.jdt.annotation.NonNull; import org.onap.ccsdk.features.sdnr.wt.common.database.DatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; @@ -36,7 +35,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper2; import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; -import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +58,7 @@ public class EsDataObjectReaderWriter2<T extends DataObject> { private String dataTypeName; /** Elasticsearch Database client to be used **/ - private DatabaseClient db; + protected DatabaseClient db; /** Mapper with configuration to use opendaylight yang-tools builder pattern for object creation **/ private YangToolsMapper2<T> yangtoolsMapper; diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessor.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessor.java index ec467eab1..8319d5d4f 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessor.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessor.java @@ -57,4 +57,5 @@ public class DataObjectAcessor<T extends DataObject> extends EsDataObjectReaderW SearchResult<T> result = doReadAll(queryBuilder, ignoreException); return new QueryResult<>(queryByFilter, result); } + } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessorInventory.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessorInventory.java new file mode 100644 index 000000000..622333403 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessorInventory.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2019 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.elasticsearch.data.acessor; + +import java.io.IOException; +import org.onap.ccsdk.features.sdnr.wt.common.database.ExtRestClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.AggregationEntries; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.rpctypehelper.QueryByFilter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.rpctypehelper.QueryResult; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DataObjectAcessorInventory<T extends DataObject> extends DataObjectAcessorWithId<T> { + + private final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorInventory.class); + + private static final String KEY = "node-id"; + + private ExtRestClient dbClient; + + public DataObjectAcessorInventory(HtDatabaseClient dbClient, Entity entity, Class<T> clazz, + boolean doFullsizeRequest) throws ClassNotFoundException { + super(dbClient, entity, clazz, doFullsizeRequest); + LOG.info("Create DataObjectAcessorInventory"); + this.dbClient = dbClient; + } + + + /** + * get aggregated devices list + * + * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name') + * @return + * @throws IOException + */ + public QueryResult<String> getDataDeviceList(EntityInput input) { + + QueryByFilter queryByFilter = new QueryByFilter(input); + SearchRequest request = + queryByFilter.getSearchRequestAggregated(KEY,this.getDataTypeName(), this.getDataTypeName(), this.doFullsizeRequest); + try { + SearchResponse response = this.dbClient.search(request); + AggregationEntries aggs = response.getAggregations(KEY); + String[] uuids = + aggs.getKeysAsPagedStringList(queryByFilter.getPageSize(), queryByFilter.getPageStartIndex()); + long totalSize = aggs.size(); + return new QueryResult<String>(queryByFilter.getPage(), queryByFilter.getPageSize(), + new SearchResult<String>(uuids, totalSize)); + } catch (IOException e) { + throw new RuntimeException("problem reading nodes for req=" + request, e); + } + + } + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessorPm.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessorPm.java index 04849004f..8e04db07b 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessorPm.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/acessor/DataObjectAcessorPm.java @@ -72,7 +72,7 @@ public class DataObjectAcessorPm<T extends DataObject> extends DataObjectAcessor public DataObjectAcessorPm(HtDatabaseClient dbClient, Intervall mode, Entity entity, Class<T> clazz, boolean doFullsizeRequest) throws ClassNotFoundException { super(dbClient, entity, clazz, doFullsizeRequest); - LOG.info("DataObjectAcessorPm"); + LOG.info("Create DataObjectAcessorPm"); this.dbClient = dbClient; this.mode = mode; } @@ -113,7 +113,7 @@ public class DataObjectAcessorPm<T extends DataObject> extends DataObjectAcessor QueryByFilter queryByFilter = new QueryByFilter(input); SearchRequest request = - queryByFilter.getSearchRequestBySortOrder(NODE_KEY, UUID_KEY, mode.getIndex(), mode.getType(), this.doFullsizeRequest); + queryByFilter.getSearchRequestAggregated(NODE_KEY, mode.getIndex(), mode.getType(), this.doFullsizeRequest); try { SearchResponse response = this.dbClient.search(request); AggregationEntries aggs = response.getAggregations(KEY); 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 64156dc07..708467d0d 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 @@ -21,8 +21,6 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.entity; -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; @@ -38,7 +36,7 @@ public class FaultEntityManager { /** * Specific problems are not moving into current problem list - * + * * @param problemName to be verified * @return true if problem is current */ @@ -52,7 +50,7 @@ public class FaultEntityManager { /** * Specific problems are not moving into current problem list - * + * * @param fault to be verified * @return true if cleared indication */ @@ -62,7 +60,7 @@ public class FaultEntityManager { /** * Create a specific ES id for the current log. - * + * * @return a string with the generated ES Id */ public static String genSpecificEsId(String nodeName, String objectId, String problemName) { @@ -80,7 +78,7 @@ public class FaultEntityManager { /** * Create Es id - * + * * @param fault used to create uuid for faultcurrent * @return String with Id */ 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 9cfe4e50d..8367a87d3 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 @@ -38,7 +38,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.queries.BoolQueryBuilder; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.RangeQueryBuilder; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.EsDataObjectReaderWriter2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.ArchiveCleanProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataInconsistencyException; @@ -97,16 +96,11 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid private final EsDataObjectReaderWriter2<GuicutthroughEntity> guiCutThroughDB; private final EsDataObjectReaderWriter2<PmdataEntity> pmData15mDB; private final EsDataObjectReaderWriter2<PmdataEntity> pmData24hDB; - - @SuppressWarnings("unused") - private final DatabaseDataProvider dataProvider; // --- Construct and initialize - public HtDatabaseEventsService(HtDatabaseClient client, DatabaseDataProvider elasticSearchDataProvider) - throws Exception { + public HtDatabaseEventsService(HtDatabaseClient client) throws Exception { LOG.info("Create {} start", HtDatabaseEventsService.class); - this.dataProvider = elasticSearchDataProvider; try { // Create control structure @@ -124,8 +118,8 @@ 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); + eventRWFCMLogDB = + new EsDataObjectReaderWriter2<>(client, Entity.Cmlog, CmlogEntity.class, CmlogBuilder.class); eventRWConnectionLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Connectionlog, ConnectionlogEntity.class, ConnectionlogBuilder.class); @@ -460,7 +454,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid @Override public boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy, String nodeId) { - LOG.info("update networkelement-connection for {} with data {}", nodeId, networkElementConnectionEntitiy); + LOG.debug("update networkelement-connection for {} with data {}", nodeId, networkElementConnectionEntitiy); return this.networkelementConnectionDB.updateOrCreate(networkElementConnectionEntitiy, nodeId, Arrays.asList("is-required", "username", "password")) != null; // NetworkElementConnectionEntity e = @@ -530,7 +524,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); numberOfElements += eventRWFaultLogDB.doReadAll(queryFaultLog).getTotal(); - QueryBuilder queryCMLog = EsCMLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); + QueryBuilder queryCMLog = EsCMLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); numberOfElements += eventRWFCMLogDB.doReadAll(queryCMLog).getTotal(); return numberOfElements; diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseMaintenanceService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseMaintenanceService.java index 9f4c0f399..c280f4fb3 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseMaintenanceService.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseMaintenanceService.java @@ -80,7 +80,7 @@ public class HtDatabaseMaintenanceService implements HtDatabaseMaintenance { if (maintenanceRW.write(m, m.getNodeId()) == null) { throw new IllegalArgumentException("Problem writing to database: " + m.getId()); } - LOG.info("Wrote maintenance object {}", m.toString()); + LOG.debug("Wrote maintenance object {}", m.toString()); } return m; } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java index 69f9bcc29..51584484b 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/rpctypehelper/QueryByFilter.java @@ -130,16 +130,16 @@ public class QueryByFilter { } } - public SearchRequest getSearchRequestBySortOrder(String nodeKey, String uuidKey, String index, String dataType, - boolean doFullsizeRequest) { - Sortorder soNode = getSortOrder(sortOrder, nodeKey); + public SearchRequest getSearchRequestAggregated(String aggregationKey, String index, String dataType, + boolean doFullsizeRequest) { + Sortorder soNode = getSortOrder(sortOrder, aggregationKey); SearchRequest request = new SearchRequest(index, dataType); QueryBuilder query = null; if (soNode != null) { query = QueryBuilders.matchAllQuery().setFullsizeRequest(doFullsizeRequest) - .aggregations(nodeKey, convert(soNode.getSortorder())).size(0); + .aggregations(aggregationKey, convert(soNode.getSortorder())).size(0); } else { - query = QueryBuilders.matchAllQuery().setFullsizeRequest(doFullsizeRequest).aggregations(nodeKey).size(0); + query = QueryBuilders.matchAllQuery().setFullsizeRequest(doFullsizeRequest).aggregations(aggregationKey).size(0); } request.setQuery(query); return request; 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 753930cdd..71372275a 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 @@ -29,8 +29,8 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.EsConfig; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.acessor.DataObjectAcessorInventory; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.acessor.DataObjectAcessorPm; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.acessor.DataObjectAcessorPm.Intervall; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.acessor.DataObjectAcessorStatus; @@ -38,10 +38,13 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data. import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.entity.HtDatabaseEventsService; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.entity.HtDatabaseMaintenanceService; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.rpctypehelper.QueryResult; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataTreeProviderImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DatabaseDataProvider; 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.onap.ccsdk.features.sdnr.wt.dataprovider.model.InventoryTreeProvider; 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; @@ -65,6 +68,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.ReadFaultcurrentListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMediatorServerListOutputBuilder; @@ -82,6 +86,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.UpdateMediatorServerOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,7 +105,7 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { 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; - private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data> equipmentRW; + private final DataObjectAcessorInventory<Data> equipmentRW; private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.Data> connnectionlogRW; private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.eventlog.list.output.Data> eventlogRW; private final DataObjectAcessorWithId<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.network.element.connection.list.output.Data> networkelementConnectionRW; @@ -111,6 +116,7 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { private final HtDatabaseEventsService databaseService; private final HtDatabaseMaintenanceService databaseMaintenanceService; private final HtUserdataManager usermanager; + private final InventoryTreeProvider inventoryTreeProvider; private final HtDatabaseMediatorserver dbMediatorServerService = new HtDatabaseMediatorserver() { @@ -158,7 +164,7 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { doFullsizeRequests); this.guicutthroughRW.setWriteInterface(Guicutthrough.class); - this.equipmentRW = new DataObjectAcessorWithId<>(dbClient, Entity.Inventoryequipment, + this.equipmentRW = new DataObjectAcessorInventory<>(dbClient, Entity.Inventoryequipment, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.list.output.Data.class, doFullsizeRequests); @@ -197,9 +203,10 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { this.readStatus = new DataObjectAcessorStatus(dbClient, Entity.Faultcurrent, doFullsizeRequests); - this.databaseService = new HtDatabaseEventsService(dbClient, this); + this.databaseService = new HtDatabaseEventsService(dbClient); this.databaseMaintenanceService = new HtDatabaseMaintenanceService(dbClient); this.usermanager = new HtUserdataManagerImpl(this.dbClient); + this.inventoryTreeProvider = new DataTreeProviderImpl(this.dbClient); } /*------------------------- @@ -297,6 +304,17 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { } @Override + public ReadInventoryDeviceListOutputBuilder readInventoryDeviceList(EntityInput input) { + ReadInventoryDeviceListOutputBuilder outputBuilder = new ReadInventoryDeviceListOutputBuilder(); + QueryResult<String> result = equipmentRW.getDataDeviceList(input); + outputBuilder.setPagination( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.inventory.device.list.output.PaginationBuilder( + result.getPagination()).build()); + outputBuilder.setData(result.getResult().getHitSets()); + return outputBuilder; + } + + @Override public ReadConnectionlogListOutputBuilder readConnectionlogList(EntityInput input) { ReadConnectionlogListOutputBuilder outputBuilder = new ReadConnectionlogListOutputBuilder(); QueryResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.Data> result = @@ -547,5 +565,9 @@ public class ElasticSearchDataProvider implements DatabaseDataProvider { return this.usermanager; } + @Override + public InventoryTreeProvider getInventoryTreeProvider() { + return this.inventoryTreeProvider; + } } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/nodb/NoDbDatabaseDataProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/nodb/NoDbDatabaseDataProvider.java index 54cf32ce0..02b58bf72 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/nodb/NoDbDatabaseDataProvider.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/nodb/NoDbDatabaseDataProvider.java @@ -24,11 +24,12 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.nodb; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DatabaseDataProvider; 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.onap.ccsdk.features.sdnr.wt.dataprovider.model.InventoryTreeProvider; 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; @@ -48,6 +49,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.ReadFaultcurrentListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMediatorServerListOutputBuilder; @@ -72,12 +74,14 @@ public class NoDbDatabaseDataProvider implements DatabaseDataProvider { private final HtDatabaseMediatorserver mediatorserver; private final HtDatabaseMaintenance maintenance; private final DataProvider dataprovider; + private final InventoryTreeProvider inventoryTreeProvider; public NoDbDatabaseDataProvider() { this.usermanger = new NoDbHtUserdataManager(); this.mediatorserver = new NoDbHtDatabaseMediatorserver(); this.maintenance = new NoDbHtDatabaseMaintenance(); this.dataprovider = new NoDbDataProvider(); + this.inventoryTreeProvider = new NoDbInventoryTreeProvider(); } @Override public HtDatabaseClient getRawClient() { @@ -241,4 +245,14 @@ public class NoDbDatabaseDataProvider implements DatabaseDataProvider { public HtUserdataManager getUserManager() { return this.usermanger; } + + @Override + public InventoryTreeProvider getInventoryTreeProvider() { + return this.inventoryTreeProvider; + } + + @Override + public ReadInventoryDeviceListOutputBuilder readInventoryDeviceList(EntityInput input) { + return new ReadInventoryDeviceListOutputBuilder(); + } } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/nodb/NoDbInventoryTreeProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/nodb/NoDbInventoryTreeProvider.java new file mode 100644 index 000000000..ad2960f64 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/nodb/NoDbInventoryTreeProvider.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 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.nodb; + +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.InventoryTreeProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeObject; + +import java.io.IOException; +import java.util.List; + +public class NoDbInventoryTreeProvider implements InventoryTreeProvider { + @Override + public DataTreeObject readInventoryTree(List<String> tree, String filter) throws IOException { + return new DataTreeObject("",""); + } +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java index 3c4a7621b..2f7b9e3fc 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java @@ -32,14 +32,18 @@ import java.util.List; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; -import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataTreeProviderImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.InventoryTreeProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeObject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,22 +51,22 @@ import org.slf4j.LoggerFactory; * @author Michael Dürre * */ + +@HttpWhiteboardServletPattern("/tree/*") +@HttpWhiteboardServletName("DataTreeHttpServlet") +@Component(service = Servlet.class) public class DataTreeHttpServlet extends HttpServlet { private static final long serialVersionUID = 1L; - private final DataTreeProviderImpl dataTreeProvider; + private InventoryTreeProvider dataTreeProvider; private static final Logger LOG = LoggerFactory.getLogger(DataTreeHttpServlet.class); public DataTreeHttpServlet() { super(); - this.dataTreeProvider = new DataTreeProviderImpl(); } - /** - * @param client - */ - public void setDatabaseClient(HtDatabaseClient client) { - this.dataTreeProvider.setDatabaseClient(client); + public void setInventoryTreeProvider(InventoryTreeProvider provider) { + this.dataTreeProvider = provider; } @@ -109,7 +113,7 @@ public class DataTreeHttpServlet extends HttpServlet { LOG.debug("GET request for {}", uri); final EntityWithTree e = getEntity(uri); if (e != null) { - LOG.info("GET request for {} to e={} with tree={}", uri, e.entity, e.tree); + LOG.debug("GET request for {} to e={} with tree={}", uri, e.entity, e.tree); switch (e.entity) { case Inventoryequipment: DataTreeObject o = this.dataTreeProvider.readInventoryTree(e.tree, null); @@ -170,7 +174,7 @@ public class DataTreeHttpServlet extends HttpServlet { final Matcher matcher = pattern.matcher(uri); if (matcher.find() && matcher.groupCount() > 0) { try { - Optional<Entity> oe = Entity.forName(matcher.group(1)); + Optional<Entity> oe = Optional.ofNullable(Entity.forName(matcher.group(1))); if (oe.isPresent()) { return new EntityWithTree(oe.get(), matcher.groupCount() > 1 ? matcher.group(2) : null); } else { diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java index 103dec70d..85658d439 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java @@ -22,15 +22,22 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.http; import java.io.IOException; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.onap.ccsdk.features.sdnr.wt.common.http.BaseServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.MediatorServerDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMediatorserver; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@HttpWhiteboardServletPattern("/ms/*") +@HttpWhiteboardServletName("MsServlet") +@Component(service = Servlet.class) public class MsServlet extends BaseServlet { /** diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java index b51d2a6df..92bccce6f 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java @@ -26,6 +26,7 @@ import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -33,9 +34,15 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPClient; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@HttpWhiteboardServletPattern({"/userdata","/userdata/*"}) +@HttpWhiteboardServletName("UserdataHttpServlet") +@Component(service = Servlet.class) public class UserdataHttpServlet extends HttpServlet { private static final long serialVersionUID = 1L; @@ -50,10 +57,10 @@ public class UserdataHttpServlet extends HttpServlet { final String uri = req.getRequestURI(); final Matcher matcher = PATTERN.matcher(uri); if (matcher.find()) { - LOG.info("GET found match"); + LOG.debug("GET found match"); this.handleGetRequest(req, resp, matcher.groupCount() > 0 ? matcher.group(1) : null); } else { - LOG.info("no valid request"); + LOG.debug("no valid request"); super.doGet(req, resp); } } @@ -63,11 +70,11 @@ public class UserdataHttpServlet extends HttpServlet { final String uri = req.getRequestURI(); final Matcher matcher = PATTERN.matcher(uri); if (matcher.find()) { - LOG.info("PUT found match"); + LOG.debug("PUT found match"); final String payload = getPayload(req); this.handlePutRequest(req, resp, payload, matcher.groupCount() > 0 ? matcher.group(1) : null); } else { - LOG.info("no valid request"); + LOG.debug("no valid request"); super.doPut(req, resp); } } @@ -81,10 +88,10 @@ public class UserdataHttpServlet extends HttpServlet { final String uri = req.getRequestURI(); final Matcher matcher = PATTERN.matcher(uri); if (matcher.find()) { - LOG.info("DELETE found match"); + LOG.debug("DELETE found match"); this.handleDeleteRequest(req, resp, matcher.groupCount() > 0 ? matcher.group(1) : null); } else { - LOG.info("no valid request"); + LOG.debug("no valid request"); super.doPut(req, resp); } } 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 40a46e6fb..45bd80cd6 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 @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.jar.Attributes; import java.util.jar.Manifest; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; @@ -41,9 +42,16 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStamp import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ServiceScope; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@HttpWhiteboardServletPattern("/about") +@HttpWhiteboardServletName("AboutHttpServlet") +@Component(service = Servlet.class) public class AboutHttpServlet extends HttpServlet { /** @@ -98,7 +106,6 @@ public class AboutHttpServlet extends HttpServlet { this.BUNDLESTATE_LUT.put(Bundle.STARTING, "starting"); this.BUNDLESTATE_LUT.put(Bundle.STOPPING, "stopping"); this.BUNDLESTATE_LUT.put(Bundle.ACTIVE, "active"); - } protected String getGroupIdOrDefault(String def) { 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 868bf7ec6..c623d9955 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 @@ -72,6 +72,8 @@ public class ODLVersionLUT { } if(odlMdsalVersionLUT==null) { odlMdsalVersionLUT = new HashMap<>(); + odlMdsalVersionLUT.put("10.0.2","chlorine-SR0 (0.17.0)"); + odlMdsalVersionLUT.put("9.0.5","sulfur-SR2 (0.16.2)"); odlMdsalVersionLUT.put("9.0.4","sulfur-SR1 (0.16.1)"); odlMdsalVersionLUT.put("9.0.2","sulfur-SR0 (0.16.0)"); odlMdsalVersionLUT.put("8.0.11","phosphorus-SR2 (0.15.2)"); 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 86f67b1de..f9fa2e931 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,13 +23,21 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.http.yangschema; import java.io.IOException; import java.text.ParseException; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import org.osgi.service.component.annotations.Component; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@HttpWhiteboardServletPattern("/yang-schema/*") +@HttpWhiteboardServletName("YangSchemaHttpServlet") +@Component(service = Servlet.class) public class YangSchemaHttpServlet extends HttpServlet { /** * diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java index e06a1a9a2..66ffdf8b3 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java @@ -87,7 +87,7 @@ public class DataProviderImpl implements IEntityDataProvider, AutoCloseable { try { // Start RPC Service this.rpcApiService = new DataProviderServiceImpl(rpcProviderService, this.mediatorServerServlet, this.dataBroker); - this.treeServlet.setDatabaseClient(this.rpcApiService.getRawClient()); + this.treeServlet.setInventoryTreeProvider(this.rpcApiService.getInventoryTreeProvider()); this.userdataServlet.setDatabaseClient(this.rpcApiService.getHtDatabaseUserManager()); LOG.info("Session Initiated end. Initialization done"); } catch (Exception e) { @@ -109,7 +109,7 @@ public class DataProviderImpl implements IEntityDataProvider, AutoCloseable { /** * Used to close all Services, that should support AutoCloseable Pattern * - * @param toClose + * @param toCloseList * @throws Exception */ private void close(AutoCloseable... toCloseList) throws Exception { 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 b75108ab2..d21d50f83 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 @@ -27,9 +27,6 @@ import com.google.common.util.concurrent.ListenableFuture; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -39,15 +36,16 @@ import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNull; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.nodb.NoDbDatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.SqlDBDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.InventoryTreeProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.SdnrDbType; import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper; import org.opendaylight.mdsal.binding.api.DataBroker; @@ -82,6 +80,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.ReadFaultlogListOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListInput; @@ -141,7 +141,6 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab private final DatabaseDataProvider dataProvider; private final ConfigurationFileRepresentation configuration; private final DataProviderConfig dbConfig; - private final HtUserdataManager dbUserManager; private final DataBroker dataBroker; private final MsServlet mediatorServerServlet; @@ -161,7 +160,6 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab else { this.dataProvider = new NoDbDatabaseDataProvider(); } - this.dbUserManager = this.dataProvider.getUserManager(); this.dataProvider.waitForYellowDatabaseStatus(DATABASE_TIMEOUT_MS, TimeUnit.MILLISECONDS); mediatorServerServlet.setDataProvider(this.dataProvider.getHtDatabaseMediatorServer()); // Register ourselves as the REST API RPC implementation @@ -296,6 +294,15 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab } @Override + public ListenableFuture<RpcResult<ReadInventoryDeviceListOutput>> readInventoryDeviceList( + ReadInventoryDeviceListInput input) { + LOG.debug("RPC Request: readInventoryDeviceList with input {}", input); + RpcResultBuilder<ReadInventoryDeviceListOutput> result = + read(() -> DataProviderServiceImpl.this.dataProvider.readInventoryDeviceList(input)); + return result.buildFuture(); + } + + @Override public ListenableFuture<RpcResult<ReadPmdata15mLtpListOutput>> readPmdata15mLtpList( ReadPmdata15mLtpListInput input) { LOG.debug("RPC Request: readPmdata15mLtpList with input {}", input); @@ -495,6 +502,10 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab return buf.toString(); } + public InventoryTreeProvider getInventoryTreeProvider() { + return this.dataProvider.getInventoryTreeProvider(); + } + private interface GetEntityInput<O extends DataObject,B> { B get() throws IOException; } @@ -515,7 +526,7 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab public HtUserdataManager getHtDatabaseUserManager() { - return this.dbUserManager; + return this.dataProvider.getUserManager(); } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java index cb62e3326..f5f1e4583 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java @@ -21,294 +21,114 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.impl; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -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.BoolQueryBuilder; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder; -import org.onap.ccsdk.features.sdnr.wt.common.database.requests.Search7Request; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.AggregationEntries; import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeChildObject; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeObject; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.acessor.DataObjectAcessorWithId; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.BaseInventoryTreeProvider; 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.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * @author Michael Dürre - * */ -public class DataTreeProviderImpl { +public class DataTreeProviderImpl extends BaseInventoryTreeProvider { + private static final Logger LOG = LoggerFactory.getLogger(DataTreeProviderImpl.class); private static final long MAXSIZE_PERSEARCH = 10; - private HtDatabaseClient dbClient; - private static final String INVENTORY_PROPERTY_TREELEVEL = "tree-level"; - private static final String INVENTORY_PROPERTY_NODEID = "node-id"; - private static final String INVENTORY_PROPERTY_UUID = "uuid"; - private static final String INVENTORY_PROPERTY_PARENTUUID = "parent-uuid"; - private static final String INVENTORY_PROPERTY_FOR_LABEL_CHILD = "uuid"; - private static final String INVENTORY_PROPERTY_FOR_LABEL = "uuid"; - - private List<SearchHit> search(Entity e, String filter, String propTreeLevel) throws IOException { - return this.search(e, filter, null, null, null, null, null, null, propTreeLevel); - } - - private List<SearchHit> search(Entity e, String filter, String nodeKey, String nodeId, String parentKey, - String parentValue, String childKey, String childValue, String propTreeLevel) throws IOException { - QueryBuilder query = - filter == null ? QueryBuilders.matchAllQuery() : QueryBuilders.searchAllFieldsQuery(filter); - if ((nodeId != null && nodeKey != null) || (parentKey != null && parentValue != null)) { - BoolQueryBuilder bquery = new BoolQueryBuilder(); - if (filter != null) { - bquery.must(query); - } - if (nodeId != null) { - bquery.must(QueryBuilders.matchQuery(nodeKey, nodeId)); - } - query = bquery; - + private final HtDatabaseClient dbClient; + private final DataObjectAcessorWithId<Inventory> dbReader; + + public DataTreeProviderImpl(HtDatabaseClient dbClient) { + this.dbClient = dbClient; + try { + this.dbReader = new DataObjectAcessorWithId<>(dbClient,Entity.Inventoryequipment,Inventory.class,true); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); } - return this.search(e, query, propTreeLevel); } - private List<SearchHit> search(Entity e, QueryBuilder query, String propTreeLevel) throws IOException { - List<SearchHit> list = new ArrayList<SearchHit>(); - query.sort(propTreeLevel, SortOrder.ASCENDING); - SearchRequest request = new Search7Request(Entity.Inventoryequipment.getName()); + private List<InventoryEntity> search(QueryBuilder query) { + query.size(MAXSIZE_PERSEARCH); - request.setQuery(query); - SearchResponse response = this.dbClient.search(request); - SearchHit[] matches = response.getHits(); - for (SearchHit hit : matches) { - list.add(hit); - } + SearchResult<Inventory> response = null; + response = this.dbReader.doReadAll(query); + List<Inventory> matches = response.getHits(); + List<InventoryEntity> list = new ArrayList<>(); + list.addAll(matches); if (response.getTotal() > MAXSIZE_PERSEARCH) { long todo = response.getTotal(); long from = MAXSIZE_PERSEARCH; while (todo > from) { - request.setQuery(query.from(from)); + query.from(from); from += MAXSIZE_PERSEARCH; //merge into list - response = this.dbClient.search(request); + response = this.dbReader.doReadAll(query); matches = response.getHits(); - for (SearchHit hit : matches) { - list.add(hit); - } + list.addAll(matches); } } return list; } - /** - * @param iNVENTORY_PROPERTY_NODEID2 - * @return - * @throws IOException - */ - private AggregationEntries searchAggregated(Entity e, String key) throws IOException { - QueryBuilder query = QueryBuilders.matchAllQuery().aggregations(key).size(MAXSIZE_PERSEARCH); - SearchRequest request = new Search7Request(e.getName()); - request.setQuery(query); - SearchResponse response = this.dbClient.search(request); - return response.getAggregations(key); - } - - /** - * - * @param tree - * @param filter - * @param - * @return - * @throws IOException - */ - public DataTreeObject readInventoryTree(List<String> tree, String filter) throws IOException { - //root nodes will be node-information -> below inventory - if (tree == null || tree.size() <= 0) { - return this.readInventoryTreeWithNode(filter); - } - //root node will be inventory on tree-level if sliced treePath - else { - return this.readInventoryTreeForNode(tree.get(0), tree.subList(0, tree.size() - 1), filter); + @Override + protected List<String> getAllNodeIds() { + QueryBuilder query = QueryBuilders.matchAllQuery().setFullsizeRequest(true).aggregations(INVENTORY_PROPERTY_NODEID).size(0); + SearchRequest request = new SearchRequest(Entity.Inventoryequipment.getName(),Entity.Inventoryequipment.getName()); + request.setQuery(query); + try { + SearchResponse response = this.dbClient.search(request); + AggregationEntries aggs = response.getAggregations(INVENTORY_PROPERTY_NODEID); + return new ArrayList<>(aggs.keySet()); + } catch (IOException e) { + LOG.warn("problem reading nodes of inventory: ", e); } - + return List.of(); } - /** - * @param string - * @param slice - * @param filter - * @param mode - * @return - */ - private DataTreeObject readInventoryTreeForNode(String nodeId, List<String> list, String filter) - throws IOException { - DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID); - final String parentUuid = list.size() > 1 ? list.get(list.size() - 2) : null; - final String uuid = list.size() > 0 ? list.get(list.size() - 1) : null; - List<SearchHit> matches = this.search(Entity.Inventoryequipment, filter, INVENTORY_PROPERTY_NODEID, nodeId, - INVENTORY_PROPERTY_PARENTUUID, parentUuid, INVENTORY_PROPERTY_UUID, uuid, INVENTORY_PROPERTY_TREELEVEL); - - //tree.a(subtreePath); - List<SearchHit> others = this.search(Entity.Inventoryequipment, (String) null, INVENTORY_PROPERTY_NODEID, nodeId, - null, null, null, null, INVENTORY_PROPERTY_TREELEVEL); - if (matches.size() > 0) { - int treeLevelToStart = (list == null || list.size() <= 0) ? 0 : list.size() - 1; - //build tree - JSONObject hitData; - //fill root elems - for (SearchHit hit : matches) { - hitData = hit.getSource(); - if (hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) == treeLevelToStart) { - tree.put(hit.getId(), - new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), true) - .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) - .setProperty(INVENTORY_PROPERTY_PARENTUUID, - hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); - } - } - for (SearchHit hit : others) { - hitData = hit.getSource(); - if (hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) == treeLevelToStart) { - tree.putIfNotExists(hit.getId(), - new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), false) - .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) - .setProperty(INVENTORY_PROPERTY_PARENTUUID, - hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); - } - } - //fill child elems - for (SearchHit hit : matches) { - hitData = hit.getSource(); - if (hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) > treeLevelToStart) { - tree.put(hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) - treeLevelToStart - 1, hit.getId(), - new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), true) - .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) - .setProperty(INVENTORY_PROPERTY_PARENTUUID, - hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); - } - } - for (SearchHit hit : others) { - hitData = hit.getSource(); - if (hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) > treeLevelToStart) { - tree.putIfNotExists(hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) - treeLevelToStart - 1, hit.getId(), - new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), false) - .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) - .setProperty(INVENTORY_PROPERTY_PARENTUUID, - hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); - } - } - tree.removeUnmatchedPaths(); - } - return tree; + @Override + protected List<InventoryEntity> search(String filter, String sortOrderProperty, SortOrder sortOrder) { + return this.search(filter, null, null, null, sortOrderProperty, sortOrder); } - /** - * node will be root elements inventory information below from level-1 - * - * @param filter - * @return - * @throws IOException - */ - private DataTreeObject readInventoryTreeWithNode(String filter) throws IOException { - DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID); - - List<SearchHit> matches = this.search(Entity.Inventoryequipment, filter, INVENTORY_PROPERTY_TREELEVEL); - List<SearchHit> others = null; - if (matches.size() > 0) { + @Override + protected List<InventoryEntity> search(String filter, String nodeId, String parentUuid, String uuid, String sortOrderProperty, SortOrder sortOrder) { + QueryBuilder query = + filter == null ? QueryBuilders.matchAllQuery() : QueryBuilders.searchAllFieldsQuery(filter); + if ((nodeId != null) || (parentUuid != null)) { + BoolQueryBuilder bquery = new BoolQueryBuilder(); if (filter != null) { - //find all parents up to tree-level 0 - String nodeId = ""; - List<String> alreadyInList = new ArrayList<>(); - BoolQueryBuilder query2 = QueryBuilders.boolQuery(); - for (SearchHit hit : matches) { - nodeId = hit.getSource().getString(INVENTORY_PROPERTY_NODEID); - if (alreadyInList.contains(nodeId)) { - continue; - } - query2.should(QueryBuilders.matchQuery(INVENTORY_PROPERTY_NODEID, nodeId)); - alreadyInList.add(nodeId); - tree.put(nodeId, - new DataTreeChildObject(nodeId, false).setProperty(INVENTORY_PROPERTY_UUID, nodeId)); - - } - others = this.search(Entity.Inventoryequipment, query2, INVENTORY_PROPERTY_TREELEVEL); - } else { - AggregationEntries nodes = this.searchAggregated(Entity.Inventoryequipment, INVENTORY_PROPERTY_NODEID); - for (String node : nodes.keySet()) { - tree.put(node, new DataTreeChildObject(node, false).setProperty(INVENTORY_PROPERTY_UUID, node)); - } - } - - //build tree - JSONObject hitData; - //fill root elems - for (SearchHit hit : matches) { - hitData = hit.getSource(); - if (hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) == 0) { - tree.put(0, hit.getId(), - new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), true) - .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) - .setProperty(INVENTORY_PROPERTY_PARENTUUID, - hitData.getString(INVENTORY_PROPERTY_NODEID))); - } - } - if (others != null) { - for (SearchHit hit : others) { - hitData = hit.getSource(); - if (hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) == 0) { - tree.putIfNotExists(0, hit.getId(), - new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), false) - .setProperty(INVENTORY_PROPERTY_UUID, - hitData.getString(INVENTORY_PROPERTY_UUID)) - .setProperty(INVENTORY_PROPERTY_PARENTUUID, - hitData.getString(INVENTORY_PROPERTY_NODEID))); - } - } - } - //fill child elements - for (SearchHit hit : matches) { - hitData = hit.getSource(); - long treeLevel = hitData.getLong(INVENTORY_PROPERTY_TREELEVEL); - if (treeLevel > 0) { - tree.put(treeLevel, hit.getId(), - new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL_CHILD), true) - .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) - .setProperty(INVENTORY_PROPERTY_PARENTUUID, - hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); - } + bquery.must(query); } - if (others != null) { - for (SearchHit hit : others) { - hitData = hit.getSource(); - long treeLevel = hitData.getLong(INVENTORY_PROPERTY_TREELEVEL); - if (hitData.getLong(INVENTORY_PROPERTY_TREELEVEL) > 0) { - tree.putIfNotExists(treeLevel, hit.getId(), - new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL_CHILD), false) - .setProperty(INVENTORY_PROPERTY_UUID, - hitData.getString(INVENTORY_PROPERTY_UUID)) - .setProperty(INVENTORY_PROPERTY_PARENTUUID, - hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); - } - } + if (nodeId != null) { + bquery.must(QueryBuilders.matchQuery(INVENTORY_PROPERTY_NODEID, nodeId)); } - tree.removeUnmatchedPaths(); + query = bquery; } - return tree; + query.sort(sortOrderProperty, sortOrder); + return this.search(query); } - - - /** - * @param client - */ - public void setDatabaseClient(HtDatabaseClient client) { - this.dbClient = client; - + @Override + protected List<InventoryEntity> getItemsForNodes(List<String> nodeIds, String sortOrderProperty, SortOrder sortOrder) { + BoolQueryBuilder query = QueryBuilders.boolQuery(); + nodeIds.forEach(e->query.should(QueryBuilders.matchQuery(INVENTORY_PROPERTY_NODEID,e))); + return this.search(query); } + } diff --git a/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index d5f8a991a..5a681d76f 100644 --- a/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -29,42 +29,20 @@ <reference id="rpcProviderService" interface="org.opendaylight.mdsal.binding.api.RpcProviderService"/> <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/> - - <bean id="aboutServlet" - class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet"> - </bean> - <service interface="javax.servlet.http.HttpServlet" - ref="aboutServlet"> - <service-properties> - <entry key="alias" value="/about"/> - </service-properties> - </service> + + <bean id="aboutServlet" class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet" /> <bean id="msServlet" class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet"> </bean> - <service interface="javax.servlet.http.HttpServlet" ref="msServlet"> - <service-properties> - <entry key="alias" value="/ms"/> - </service-properties> - </service> + <bean id="treeServlet" class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet"> </bean> - <service interface="javax.servlet.http.HttpServlet" ref="treeServlet"> - <service-properties> - <entry key="alias" value="/tree"/> - </service-properties> - </service> <bean id="userdataServlet" class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet"> </bean> - <service interface="javax.servlet.http.HttpServlet" ref="userdataServlet"> - <service-properties> - <entry key="alias" value="/userdata"/> - </service-properties> - </service> <bean id="provider" class="org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl" @@ -80,12 +58,6 @@ <bean id="yangServlet" class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.yangschema.YangSchemaHttpServlet"> </bean> - <service interface="javax.servlet.http.HttpServlet" - ref="yangServlet"> - <service-properties> - <entry key="alias" value="/yang-schema"/> - </service-properties> - </service> <service ref="provider" interface="org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider"/> 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 08b1d00aa..268015a4d 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 @@ -36,8 +36,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; - -import org.eclipse.jdt.annotation.Nullable; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; @@ -46,10 +44,11 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; 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.BaseRequest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.HtUserdataManagerImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DatabaseDataProvider; 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; @@ -187,12 +186,12 @@ public class TestCRUDforDatabase { "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateFaultcurrentInput", SeverityType.Warning, "nodeA"); - createNeConnection("nodeA","10.20.30.40",30000, ConnectionLogStatus.Connected); - createNeConnection("nodeB","10.20.30.40",31000, ConnectionLogStatus.Connected); - createNeConnection("nodeC","10.20.30.40",32000, ConnectionLogStatus.Connected); - createNeConnection("nodeAD","10.20.30.40",33000, ConnectionLogStatus.Connected); - createNeConnection("nodeE","10.20.30.40",34000, ConnectionLogStatus.Connected); - createNeConnection("nodeF","10.20.30.40",35000, ConnectionLogStatus.Connected); + createNeConnection("nodeA", "10.20.30.40", 30000, ConnectionLogStatus.Connected); + createNeConnection("nodeB", "10.20.30.40", 31000, ConnectionLogStatus.Connected); + createNeConnection("nodeC", "10.20.30.40", 32000, ConnectionLogStatus.Connected); + createNeConnection("nodeAD", "10.20.30.40", 33000, ConnectionLogStatus.Connected); + createNeConnection("nodeE", "10.20.30.40", 34000, ConnectionLogStatus.Connected); + createNeConnection("nodeF", "10.20.30.40", 35000, ConnectionLogStatus.Connected); //== READ ================================ List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.status.output.Data> readOutput = @@ -1052,7 +1051,7 @@ public class TestCRUDforDatabase { assertTrue(holder.contains(holderArray[0])); assertTrue(holder.contains(holderArray[1])); assertTrue(holder.contains(holderArray[2])); - + // ==DELETE============================ System.out.println("delete after test"); @@ -1538,7 +1537,7 @@ public class TestCRUDforDatabase { boolean success = client.setUserdata(USERNAME, DATA1); assertTrue(success); String data = client.getUserdata(USERNAME); - //JSONAssert.assertEquals(DATA1,data,false); + JSONAssert.assertEquals(DATA1,data,false); assertEquals("admin", UserdataHttpServlet.decodeJWTPayloadUsername(String.format("Bearer %s", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBzZG4iLCJyb2xlcyI6WyJ1c2VyIiwiYWRtaW4iXSwiaXN" @@ -1571,19 +1570,12 @@ public class TestCRUDforDatabase { return createFaultEntity(initialDbId, entityType, implementedInterface, severity, nodeId); } - private void createNeConnection(String nodeId, String host, int port, ConnectionLogStatus connectionStatus) { - try { - dbProvider.createNetworkElementConnection(new NetworkElementConnectionBuilder().setId(nodeId) - .setNodeId(nodeId).setStatus(connectionStatus).setHost(host).setPort(Uint32.valueOf(port)).build()); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - private String createFaultEntity(String initialDbId, String entityType, String implementedInterface, - SeverityType severity) { - return createFaultEntity(initialDbId, entityType, implementedInterface, severity, "s1"); + private void createNeConnection(String nodeId, String host, int port, ConnectionLogStatus connectionStatus) + throws IOException { + dbProvider.createNetworkElementConnection(new NetworkElementConnectionBuilder().setId(nodeId).setNodeId(nodeId) + .setStatus(connectionStatus).setHost(host).setPort(Uint32.valueOf(port)).build()); } + private String createFaultEntity(String initialDbId, String entityType, String implementedInterface, SeverityType severity, String nodeId) { // ==CREATE============================ @@ -1594,7 +1586,7 @@ public class TestCRUDforDatabase { dbId = dbRawProvider.doUpdateOrCreate(entityType, initialDbId, "{\n" + "\"timestamp\": \"2019-10-28T11:55:58.3Z\",\n" + "\"object-id\": \"LP-MWPS-RADIO\",\n" - + "\"severity\": \"" + severity.toString() + "\",\n" + "\"node-id\": \""+nodeId+"\",\n" + + "\"severity\": \"" + severity.toString() + "\",\n" + "\"node-id\": \"" + nodeId + "\",\n" + "\"implemented-interface\": \"" + implementedInterface + "\",\n" + "\"counter\": 4340,\n" + "\"problem\": \"signalIsLost\",\n" + "\"type\": \"ProblemNotificationXml\"\n" + "}"); 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 0db019005..4c6e1b893 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 @@ -39,7 +39,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; 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.model.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; @@ -98,7 +98,7 @@ public class TestEventService { dbRawProvider = HtDatabaseClient.getClient(hosts); try { - service = new HtDatabaseEventsService(dbRawProvider, dbProvider); + service = new HtDatabaseEventsService(dbRawProvider); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInventoryConsistency.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInventoryConsistency.java index ce1bd78fa..d1b5cfcfd 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInventoryConsistency.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInventoryConsistency.java @@ -21,20 +21,29 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; -import static org.junit.Assert.fail; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper; +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.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder; +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 TestInventoryConsistency { @@ -51,10 +60,11 @@ public class TestInventoryConsistency { @Test public void test1() { YangToolsMapper mapper = new YangToolsMapper(); + SearchHit[] hits = null; try { - SearchHit[] hits = TestTree.loadEntries("test1.json"); + hits = TestTree.loadEntries("test1.json"); List<Inventory> inventoryList = new ArrayList<>(); - for(SearchHit hit:hits) { + for (SearchHit hit : hits) { inventoryList.add(mapper.readValue(hit.getSourceAsString(), Inventory.class)); } dbProvider.getDataProvider().writeInventory(TEST1NODEID, inventoryList); @@ -63,5 +73,14 @@ public class TestInventoryConsistency { e.printStackTrace(); fail(e.getMessage()); } + SearchHit sim2Hit = hits[hits.length-1]; + dbProvider.getRawClient().doWriteRaw(Entity.Inventoryequipment.getName(),sim2Hit.getId(),sim2Hit.getSourceAsString(),true); + ReadInventoryDeviceListOutputBuilder deviceListWithInventory = + dbProvider.readInventoryDeviceList(new ReadInventoryDeviceListInputBuilder().setPagination( + new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1)) + .build()).build()); + assertNotNull(deviceListWithInventory); + assertEquals(2, deviceListWithInventory.getPagination().getTotal().intValue()); + assertEquals(Set.of("sim1", "sim2"), deviceListWithInventory.getData()); } } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java index e85ed8cdd..1b95050d4 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java @@ -33,7 +33,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; 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.model.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java index 408f6a636..dcd2eb0c7 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java @@ -32,7 +32,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; 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.model.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.MediatorServerDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfNodeBuilder.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfNodeBuilder.java index f7a5a841c..85db4b2a0 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfNodeBuilder.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfNodeBuilder.java @@ -21,16 +21,17 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; +import org.junit.Test; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPassword; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder; +@SuppressWarnings("deprecation") public class TestNetconfNodeBuilder { - @SuppressWarnings("deprecation") - //@Test + @Test public void test() { NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder(); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfTimestamp.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfTimestamp.java index 1081e3cfe..a21373277 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfTimestamp.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfTimestamp.java @@ -21,14 +21,13 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; -import static org.junit.Assert.*; - +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; @@ -64,7 +63,7 @@ public class TestNetconfTimestamp { @Test(expected = IllegalArgumentException.class) public void testMillisMalformed() { - long millis = converter.getTimeStampFromNetconfAsMilliseconds(NETCONF_DEF_MILLIS_STRING_MALFORMAED); + converter.getTimeStampFromNetconfAsMilliseconds(NETCONF_DEF_MILLIS_STRING_MALFORMAED); } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java index 29f35560e..b7689ed49 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java @@ -35,12 +35,12 @@ 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.common.test.JSONAssert; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.EntityWithTree; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeObject; import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataTreeProviderImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeObject; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; @@ -56,8 +56,6 @@ public class TestTree { dbProvider = new ElasticSearchDataProvider(hosts); dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); dbRawProvider = HtDatabaseClient.getClient(hosts); - - } public static void clearTestData(HtDatabaseClient dbRawProvider) throws IOException { @@ -85,50 +83,24 @@ public class TestTree { } @Test - public void testInventoryTree() throws IOException { - test1(); - //test2(); - - } - - private void test1() throws IOException { + public void testInventoryTree1() throws IOException { clearTestData(dbRawProvider); fillTestData(dbRawProvider, "test1.json"); - DataTreeProviderImpl provider = new DataTreeProviderImpl(); - provider.setDatabaseClient(dbRawProvider); + DataTreeProviderImpl provider = new DataTreeProviderImpl(dbRawProvider); DataTreeObject tree = provider.readInventoryTree(null, null); - System.out.println(tree.toJSON()); JSONObject o = new JSONObject(tree.toJSON()); + System.out.println("Tree1.1: "+o); JSONAssert.assertContainsExactKeys(o, new String[]{"sim1","sim2"}); JSONObject children = o.getJSONObject("sim1").getJSONObject("children"); this.assertSim1(children); tree = provider.readInventoryTree(Arrays.asList("sim1"), "*"); this.assertSim1(new JSONObject(tree.toJSON())); - System.out.println(tree.toJSON()); + System.out.println("Tree1.2: "+tree.toJSON()); } - private void test2() throws IOException { - clearTestData(dbRawProvider); - fillTestData(dbRawProvider, "test2.json"); - DataTreeProviderImpl provider = new DataTreeProviderImpl(); - provider.setDatabaseClient(dbRawProvider); - - - DataTreeObject tree = - provider.readInventoryTree(Arrays.asList("netconf_server_simulator"), "*"); - System.out.println(tree.toJSON()); - JSONObject o = new JSONObject(tree.toJSON()); - JSONAssert.assertContainsOnlyKey(o, "sim1"); - JSONObject children = o.getJSONObject("sim1").getJSONObject("children"); - this.assertSim1(children); - - tree = provider.readInventoryTree(Arrays.asList("sim1"), "*"); - this.assertSim1(new JSONObject(tree.toJSON())); - System.out.println(tree.toJSON()); - } private void assertSim1(JSONObject sim1Children) { JSONAssert.assertContainsExactKeys(sim1Children, diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java index 910f63daf..ed6642a6f 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java @@ -23,11 +23,9 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; import java.io.IOException; import java.math.BigInteger; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; - import org.eclipse.jdt.annotation.Nullable; import org.json.JSONObject; import org.junit.Test; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java index 35ddaf2f3..0192b47db 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java @@ -37,6 +37,7 @@ import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper2; import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType; import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataTypeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.BIPErrorCounter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.DelayTCM2Up; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.OpticalPowerInputOSCMin; 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.PmdataEntity; @@ -57,12 +58,12 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito { out("Test: " + method()); MeasurementBuilder measurementBuilder1 = new MeasurementBuilder(); - measurementBuilder1.setPmKey(OpticalPowerInputOSCMin.class); + measurementBuilder1.setPmKey(OpticalPowerInputOSCMin.VALUE); measurementBuilder1.setPmValue(new PmDataType(Uint64.valueOf(64L))); Measurement measurement1 = measurementBuilder1.build(); MeasurementBuilder measurementBuilder2 = new MeasurementBuilder(); - measurementBuilder2.setPmKey(BIPErrorCounter.class); + measurementBuilder2.setPmKey(BIPErrorCounter.VALUE); measurementBuilder2.setPmValue(new PmDataType(Uint64.valueOf(65L))); Measurement measurement2 = measurementBuilder2.build(); @@ -98,7 +99,7 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito { assertNotNull("PerformanceData", performanceData); @Nullable Map<MeasurementKey, Measurement> measurement = performanceData.getMeasurement(); assertNotNull("Measurement", measurement); - Measurement measurement1 = measurement.get(new MeasurementKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.OpticalPowerInputOSCMin.class)); + Measurement measurement1 = measurement.get(new MeasurementKey(OpticalPowerInputOSCMin.VALUE)); assertTrue("Measurement=64", measurement1.getPmValue().stringValue().equals("64")); } @@ -144,7 +145,7 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito { assertNotNull("PerformanceData", performanceData); @Nullable Map<MeasurementKey, Measurement> measurement = performanceData.getMeasurement(); assertNotNull("Measurement", measurement); - Measurement measurement1 = measurement.get(new MeasurementKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.DelayTCM2Up.class)); + Measurement measurement1 = measurement.get(new MeasurementKey(DelayTCM2Up.VALUE)); assertTrue("Measurement=11298624220985537708", measurement1.getPmValue().stringValue().equals("11298624220985537708")); } /* diff --git a/sdnr/wt/data-provider/setup/pom.xml b/sdnr/wt/data-provider/setup/pom.xml index bedd548c2..d8f8e8c38 100644 --- a/sdnr/wt/data-provider/setup/pom.xml +++ b/sdnr/wt/data-provider/setup/pom.xml @@ -22,13 +22,14 @@ ~ ============LICENSE_END======================================================= ~ --> + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> - <version>2.5.3</version> + <version>2.5.4-SNAPSHOT</version> <relativePath/> </parent> |