diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2023-03-02 12:06:07 +0530 |
---|---|---|
committer | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2023-03-10 10:46:55 +0530 |
commit | 6b8e4f12fc66a64fa5c5498d06891f1f5f1189ac (patch) | |
tree | 6414988944a78393509923a5ace70d66db0b29bd /sdnr/wt/data-provider/provider | |
parent | d944abfab1a53a462868ae805ab5372935f854ef (diff) |
Upgrade parents to 2.5.4-SNAPSHOT
Code changes as a result of changes induced by ODL Chlorine SR1
Issue-ID: CCSDK-3856
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: Ic08786f050e58bdb8371c8f8c25fb0db9f258cd4
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/provider')
34 files changed, 387 insertions, 752 deletions
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/DataTreeChildObject.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java deleted file mode 100644 index 05e6d2f13..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : ccsdk features - * ================================================================================ - * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. - * All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - */ -package org.onap.ccsdk.features.sdnr.wt.dataprovider.http; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -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 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.children = children; -// this.ownSeverity = ownSeverity; -// this.childrenSeveritySummary = childrenSeveritySummary; - this.properties = new HashMap<>(); - } - - public DataTreeChildObject setProperty(String key, Object value) { - this.properties.put(key, value); - 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 putChild(long treeLevel, String id, DataTreeChildObject data, String parentKey, String childKey) { - Object itemValue; - Object itemValueToMatch = data.getProperty(parentKey, null); - if (itemValueToMatch == null) { - return false; - } - if (treeLevel > 0) { - if (this.children != null) { - for (DataTreeChildObject child : this.children.values()) { - if (child.putChild(treeLevel - 1, id, data, parentKey, childKey)) { - return true; - } - } - } - } else { - itemValue = this.getProperty(childKey, null); - if (itemValue != null && itemValue.equals(itemValueToMatch)) { - this.children.put(id, data); - return true; - } - } - 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; - Object itemValueToMatch = data.getProperty(parentKey, null); - if (itemValueToMatch == null) { - return false; - } - if (treeLevel > 0) { - if (this.children != null) { - for (DataTreeChildObject child : this.children.values()) { - if (child.putChildIfNotExists(treeLevel - 1, id, data, parentKey, childKey)) { - return true; - } - } - } - } else { - itemValue = this.getProperty(childKey, null); - if (itemValue != null && itemValue.equals(itemValueToMatch)) { - if (!this.children.containsKey(id)) { - this.children.put(id, data); - } - } - } - return false; - } - - /** - * @return - */ - public JSONObject toJSONObject() { - JSONObject o = new JSONObject(); - o.put("label", this.label); - o.put("isMatch", this.isMatch); - JSONObject c = new JSONObject(); - if (this.children != null) { - for (Entry<String, DataTreeChildObject> entry : this.children.entrySet()) { - c.put(entry.getKey(), entry.getValue().toJSONObject()); - } - } - 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; - if (match) { - break; - } - } - 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)) { - toRemove.add(entry.getKey()); - } else { - entry.getValue().removeUnmatchedPaths(); - } - } - for (String key : toRemove) { - this.children.remove(key); - } - } - - public boolean hasChildren() { - 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/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/DataTreeObject.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java deleted file mode 100644 index f12ff3deb..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : ccsdk features - * ================================================================================ - * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. - * All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - */ -package org.onap.ccsdk.features.sdnr.wt.dataprovider.http; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import org.json.JSONObject; - -public class DataTreeObject extends HashMap<String, DataTreeChildObject> { - - private static final long serialVersionUID = 1L; - 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 String toJSON() { - JSONObject o = new JSONObject(); - for (Entry<String, DataTreeChildObject> entry : this.entrySet()) { - o.put(entry.getKey(), entry.getValue().toJSONObject()); - } - return o.toString(); - } - - /** - * - */ - public void removeUnmatchedPaths() { - List<String> toRemove = new ArrayList<>(); - for (Entry<String,DataTreeChildObject> entry : this.entrySet()) { - entry.getValue().removeUnmatchedPaths(); - if(!entry.getValue().isMatch() && !entry.getValue().hasChildren()) { - toRemove.add(entry.getKey()); - } - } - for(String toRemoveKey:toRemove) { - this.remove(toRemoveKey); - } - - } - - /** - * @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++) { - r[i] = source[i + start]; - } - return r; - - } -} 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")); } /* |