From 1e9b47aa36b47e60dd2a0d028a8080cf25054ad2 Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Wed, 12 Aug 2020 08:25:21 +0200 Subject: organize java sources and optimization organize java sources and optimization - for better readability and clean segregation Issue-ID: CCSDK-2639 Signed-off-by: Ravi Pendurty Change-Id: I4547b42f3a0fc86283a934bc82a30b591648715e Signed-off-by: Ravi Pendurty --- .../wt/dataprovider/data/DataObjectAcessor.java | 58 --- .../wt/dataprovider/data/DataObjectAcessorPm.java | 130 ----- .../dataprovider/data/DataObjectAcessorStatus.java | 71 --- .../dataprovider/data/DataObjectAcessorWithId.java | 41 -- .../data/ElasticSearchDataProvider.java | 8 +- .../wt/dataprovider/data/FaultEntityManager.java | 98 ---- .../dataprovider/data/HtDatabaseEventsService.java | 526 -------------------- .../data/HtDatabaseMaintenanceService.java | 176 ------- .../data/MediatorServerDataProvider.java | 7 +- .../sdnr/wt/dataprovider/data/QueryByFilter.java | 423 ----------------- .../wt/dataprovider/data/QueryByFilterStatic.java | 336 ------------- .../sdnr/wt/dataprovider/data/QueryResult.java | 66 --- .../wt/dataprovider/data/YangFileProvider.java | 208 -------- .../sdnr/wt/dataprovider/data/YangFilename.java | 74 --- .../data/acessor/DataObjectAcessor.java | 60 +++ .../data/acessor/DataObjectAcessorPm.java | 132 ++++++ .../data/acessor/DataObjectAcessorStatus.java | 72 +++ .../data/acessor/DataObjectAcessorWithId.java | 41 ++ .../data/entity/FaultEntityManager.java | 98 ++++ .../data/entity/HtDatabaseEventsService.java | 527 +++++++++++++++++++++ .../data/entity/HtDatabaseMaintenanceService.java | 176 +++++++ .../data/rpctypehelper/QueryByFilter.java | 424 +++++++++++++++++ .../data/rpctypehelper/QueryByFilterStatic.java | 337 +++++++++++++ .../data/rpctypehelper/QueryResult.java | 66 +++ .../wt/dataprovider/http/AboutHttpServlet.java | 393 --------------- .../wt/dataprovider/http/GetYangSchemaRequest.java | 61 --- .../sdnr/wt/dataprovider/http/MarkdownTable.java | 75 --- .../sdnr/wt/dataprovider/http/ODLVersionLUT.java | 70 --- .../sdnr/wt/dataprovider/http/SystemInfo.java | 337 ------------- .../dataprovider/http/YangSchemaHttpServlet.java | 122 ----- .../dataprovider/http/about/AboutHttpServlet.java | 385 +++++++++++++++ .../wt/dataprovider/http/about/MarkdownTable.java | 75 +++ .../wt/dataprovider/http/about/ODLVersionLUT.java | 70 +++ .../wt/dataprovider/http/about/SystemInfo.java | 337 +++++++++++++ .../http/yangschema/GetYangSchemaRequest.java | 61 +++ .../http/yangschema/YangFileProvider.java | 208 ++++++++ .../dataprovider/http/yangschema/YangFilename.java | 74 +++ .../http/yangschema/YangSchemaHttpServlet.java | 122 +++++ .../wt/dataprovider/impl/DataProviderImpl.java | 2 +- .../dataprovider/impl/DataProviderServiceImpl.java | 6 +- .../provider/src/main/resources/about/README.md | 1 - .../src/main/resources/es-init.replaced.sh | 446 +++++++++++++++++ .../provider/src/main/resources/es-init.sh | 22 + .../org/opendaylight/blueprint/impl-blueprint.xml | 4 +- .../sdnr/wt/dataprovider/test/TestAbout.java | 3 +- .../wt/dataprovider/test/TestEventService.java | 2 +- .../wt/dataprovider/test/TestFilterConversion.java | 2 +- .../wt/dataprovider/test/TestImplementation.java | 2 +- .../wt/dataprovider/test/TestTimestampFilter.java | 2 +- .../dataprovider/test/TestYangGenSalMapping.java | 3 - .../wt/dataprovider/test/TestYangProvider.java | 7 +- 51 files changed, 3759 insertions(+), 3288 deletions(-) delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessor.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorPm.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorStatus.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorWithId.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/FaultEntityManager.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseMaintenanceService.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilter.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilterStatic.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryResult.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/YangFileProvider.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/YangFilename.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessor.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorPm.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorStatus.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorWithId.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/FaultEntityManager.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseMaintenanceService.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilterStatic.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryResult.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/AboutHttpServlet.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/GetYangSchemaRequest.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MarkdownTable.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ODLVersionLUT.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/SystemInfo.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/YangSchemaHttpServlet.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/GetYangSchemaRequest.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFileProvider.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFilename.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangSchemaHttpServlet.java create mode 100755 sdnr/wt/data-provider/provider/src/main/resources/es-init.replaced.sh create mode 100755 sdnr/wt/data-provider/provider/src/main/resources/es-init.sh (limited to 'sdnr/wt/data-provider/provider/src') diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessor.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessor.java deleted file mode 100644 index c3c63a963..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessor.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ============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.data; - -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.queries.QueryBuilder; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DataObjectAcessor extends EsDataObjectReaderWriter2 { - - private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessor.class); - - DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class clazz) throws ClassNotFoundException { - super(dbClient, entity, clazz); - LOG.info("Create {}", this.getClass().getName()); - } - - public QueryResult getData(EntityInput input) { - - QueryByFilter queryByFilter = new QueryByFilter(input); - QueryBuilder queryBuilder = queryByFilter.getQueryBuilderByFilter(); - // Exception handling during user input for invalid filter input. - // This wrong filter by user is allowed an results into empty data. - boolean ignoreException = queryBuilder.contains("range"); - - LOG.info("Request: {} filter {} ignoreException{}:", this.getDataTypeName(), queryByFilter, ignoreException); - - SearchResult 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/data/DataObjectAcessorPm.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorPm.java deleted file mode 100644 index 83017366d..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorPm.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * ============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.data; - -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.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DataObjectAcessorPm extends DataObjectAcessor { - - private final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorPm.class); - - private static final String UUID_KEY = "uuid-interface"; - private static final String NODE_KEY = "node-name"; - private static final String KEY = "node-name"; - - - public enum Intervall { - PMDATA15M("historicalperformance15min", "historicalperformance15min"), PMDATA24H("historicalperformance24h", - "historicalperformance24h"); - - String index; - String type; - - Intervall(String index, String type) { - this.index = index; - this.type = type; - } - - public String getIndex() { - return index; - } - - public String getType() { - return type; - } - } - - private ExtRestClient dbClient; - private Intervall mode; - - public DataObjectAcessorPm(HtDatabaseClient dbClient, Intervall mode, Entity entity, Class clazz) - throws ClassNotFoundException { - super(dbClient, entity, clazz); - LOG.info("DataObjectAcessorPm"); - this.dbClient = dbClient; - this.mode = mode; - } - - /** - * get aggregated list of ltps for filter NODE_KEY - * - * @param input - * @return - * @throws IOException - */ - public QueryResult getDataLtpList(EntityInput input) throws IOException { - - QueryByFilter queryByFilter = new QueryByFilter(input); - SearchRequest request = - queryByFilter.getSearchRequestByFilter(NODE_KEY, UUID_KEY, mode.getIndex(), mode.getType()); - try { - SearchResponse response = this.dbClient.search(request); - AggregationEntries aggs = response.getAggregations(UUID_KEY); - String[] uuids = - aggs.getKeysAsPagedStringList(queryByFilter.getPageSize(), queryByFilter.getPageStartIndex()); - long totalSize = aggs.size(); - return new QueryResult(queryByFilter.getPage(), queryByFilter.getPageSize(), - new SearchResult(uuids, totalSize)); - } catch (IOException e) { - throw new IOException("problem reading ltps for req=" + request, e); - } - } - - /** - * get aggregated devices list - * - * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name') - * @return - * @throws IOException - */ - public QueryResult getDataDeviceList(EntityInput input) throws IOException { - - QueryByFilter queryByFilter = new QueryByFilter(input); - SearchRequest request = - queryByFilter.getSearchRequestBySortOrder(NODE_KEY, UUID_KEY, mode.getIndex(), mode.getType()); - 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(queryByFilter.getPage(), queryByFilter.getPageSize(), - new SearchResult(uuids, totalSize)); - } catch (IOException e) { - throw new IOException("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/data/DataObjectAcessorStatus.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorStatus.java deleted file mode 100644 index 1fa6de37d..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorStatus.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ============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.data; - -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.queries.QueryBuilders; -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.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.status.output.Data; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.status.output.DataBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.status.entity.FaultsBuilder; - -public class DataObjectAcessorStatus extends DataObjectAcessor { - - final String ESDATATYPE_FAULTCURRENT_SEVERITY_KEY = "severity"; - - private final ExtRestClient dbClient; - private final Entity entity; - - public DataObjectAcessorStatus(HtDatabaseClient dbClient, Entity entity) throws ClassNotFoundException { - super(dbClient, entity, Data.class); - this.dbClient = dbClient; - this.entity = entity; - } - - public QueryResult getDataStatus() throws IOException { - SearchRequest request = getNewInstanceOfSearchRequest(entity); - request.setQuery(QueryBuilders.matchAllQuery().aggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY).size(0)); - SearchResponse response = this.dbClient.search(request); - AggregationEntries aggs = response.getAggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY); - - Data[] data = {new DataBuilder().setFaults(new FaultsBuilder().setCriticals(aggs.getOrDefault("Critical", 0L)) - .setMajors(aggs.getOrDefault("Major", 0L)).setMinors(aggs.getOrDefault("Minor", 0L)) - .setWarnings(aggs.getOrDefault("Warning", 0L)).build()).build()}; - long toalsize = data.length; - return new QueryResult(1L, 1L, new SearchResult(data, toalsize)); - - } - - - private static SearchRequest getNewInstanceOfSearchRequest(Entity entity) { - return new SearchRequest(entity.getName(), entity.getName()); - } - - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorWithId.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorWithId.java deleted file mode 100644 index 10dd7792c..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorWithId.java +++ /dev/null @@ -1,41 +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.data; - -import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DataObjectAcessorWithId extends DataObjectAcessor { - - private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorWithId.class); - - public DataObjectAcessorWithId(HtDatabaseClient dbClient, Entity entity, Class clazz) - throws ClassNotFoundException { - super(dbClient, entity, clazz); - setEsIdAttributeName("_id"); - LOG.info("Create {}", this.getClass().getName()); - } - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java index 30e617ab6..e8d573b79 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ElasticSearchDataProvider.java @@ -25,7 +25,13 @@ 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.common.database.config.HostInfo; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.DataObjectAcessorPm.Intervall; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.acessor.DataObjectAcessorPm; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.acessor.DataObjectAcessorPm.Intervall; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.acessor.DataObjectAcessorStatus; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.acessor.DataObjectAcessorWithId; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.entity.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.entity.HtDatabaseMaintenanceService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryResult; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMaintenanceInput; diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/FaultEntityManager.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/FaultEntityManager.java deleted file mode 100644 index 7efdab110..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/FaultEntityManager.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ============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.data; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Fault; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType; - -public class FaultEntityManager { - - private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]"); - - /** - * The leading indication for notification or events that are not in the currentProblem data of the ONF Coremodel - */ - private static final String NOCURRENTPROBLEMINDICATION = "#"; - - /** - * Specific problems are not moving into current problem list - * - * @param problemName to be verified - * @return true if problem is current - */ - public static boolean isManagedAsCurrentProblem(String problemName) { - return !problemName.startsWith(NOCURRENTPROBLEMINDICATION); - } - - public static boolean isManagedAsCurrentProblem(Fault problem) { - return isManagedAsCurrentProblem(problem.getProblem()); - } - - /** - * Specific problems are not moving into current problem list - * - * @param fault to be verified - * @return true if cleared indication - */ - public static boolean isNoAlarmIndication(@Nonnull Fault fault) { - return SeverityType.NonAlarmed.equals(fault.getSeverity()); - } - - /** - * 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) { - - String uuId; - - Matcher matcher = pattern.matcher(objectId); - if (matcher.matches() && matcher.groupCount() == 1) { - uuId = matcher.group(1); - } else { - uuId = objectId; - } - - StringBuffer strBuf = new StringBuffer(); - strBuf.append(nodeName); - strBuf.append("/"); - strBuf.append(uuId); - strBuf.append("/"); - strBuf.append(problemName); - return strBuf.toString(); - } - - /** - * Create Es id - * - * @param fault used to create uuid for faultcurrent - * @return String with Id - */ - public static String genSpecificEsId(FaultcurrentEntity fault) { - return genSpecificEsId(fault.getNodeId(), fault.getObjectId(), fault.getProblem()); - } -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java deleted file mode 100644 index 4efbf6e28..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java +++ /dev/null @@ -1,526 +0,0 @@ -/* - * ============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.data; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import javax.annotation.Nonnull; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -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.EsDataObjectReaderWriter2; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.ArchiveCleanProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionLogStatus; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.GranularityPeriodType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntityBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateNetworkElementConnectionInputBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Event service, writing all events into the database into the appropriate index. - * - * @author herbert - */ -public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvider { - private static final Logger LOG = LoggerFactory.getLogger(HtDatabaseEventsService.class); - - private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter(); - - private HtDatabaseClient client; - private EsDataObjectReaderWriter2 eventRWEventLogDevicemanager; - private EsDataObjectReaderWriter2 eventRWEquipment; - private EsDataObjectReaderWriter2 eventRWFaultCurrentDB; - private EsDataObjectReaderWriter2 eventRWFaultLogDB; - private EsDataObjectReaderWriter2 eventRWConnectionLogDB; - private final EsDataObjectReaderWriter2 networkelementConnectionDB; - private final EsDataObjectReaderWriter2 pmData15mDB; - private final EsDataObjectReaderWriter2 pmData24hDB; - - @SuppressWarnings("unused") - private final ElasticSearchDataProvider dataProvider; - // --- Construct and initialize - - - public HtDatabaseEventsService(HtDatabaseClient client, ElasticSearchDataProvider elasticSearchDataProvider) - throws Exception { - - LOG.info("Create {} start", HtDatabaseEventsService.class); - this.dataProvider = elasticSearchDataProvider; - - try { - // Create control structure - this.client = client; - - eventRWEventLogDevicemanager = new EsDataObjectReaderWriter2<>(client, Entity.Eventlog, - EventlogEntity.class, EventlogBuilder.class); - - eventRWEquipment = new EsDataObjectReaderWriter2<>(client, Entity.Inventoryequipment, InventoryEntity.class, - InventoryBuilder.class); - - eventRWFaultCurrentDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultcurrent, - FaultcurrentEntity.class, FaultcurrentBuilder.class); - - eventRWFaultLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultlog, FaultlogEntity.class, - FaultlogBuilder.class); - - eventRWConnectionLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Connectionlog, - ConnectionlogEntity.class, ConnectionlogBuilder.class); - - networkelementConnectionDB = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection, - NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true) - .setEsIdAttributeName("_id"); - - pmData15mDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance15min, PmdataEntity.class, - PmdataEntityBuilder.class); - - pmData24hDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance24h, PmdataEntity.class, - PmdataEntityBuilder.class); - - } catch (Exception e) { - LOG.error("Can not start database client. Exception: {}", e); - throw new Exception("Can not start database client. Exception: {}", e); - } - LOG.info("Create {} finished. DB Service {} started.", HtDatabaseEventsService.class, - client != null ? "sucessfully" : "not"); - } - - // --- Function - - // -- Connection log - @Override - public void writeConnectionLog(ConnectionlogEntity event) { - if (assertIfClientNull(event)) { - return; - } - LOG.debug("Write event: {}", event); - eventRWConnectionLogDB.write(event, null); - - } - - // -- Event log - @Override - public void writeEventLog(EventlogEntity event) { - if (assertIfClientNull("No client to write {}", event)) { - return; - } - - LOG.debug("Write event: {}", event.toString()); - eventRWEventLogDevicemanager.write(event, null); - } - - - // -- Fault log - - @Override - public void writeFaultLog(FaultlogEntity fault) { - if (assertIfClientNull(fault)) { - return; - } - - LOG.debug("Write fault to faultlog: {}", fault.toString()); - eventRWFaultLogDB.write(fault, null); - } - - // -- Fault current - - @Override - public void updateFaultCurrent(FaultcurrentEntity fault) { - if (assertIfClientNull(fault)) { - return; - } - - if (FaultEntityManager.isManagedAsCurrentProblem(fault)) { - if (FaultEntityManager.isNoAlarmIndication(fault)) { - LOG.debug("Remove from currentFaults: {}", fault.toString()); - eventRWFaultCurrentDB.remove(FaultEntityManager.genSpecificEsId(fault)); - } else { - LOG.debug("Write to currentFaults: {}", fault.toString()); - eventRWFaultCurrentDB.write(fault, FaultEntityManager.genSpecificEsId(fault)); - } - } else { - LOG.debug("Ingnore for currentFaults: {}", fault.toString()); - } - } - - /** - * Remove all entries for one node - * - * @param nodeName contains the mountpointname - * @return number of deleted entries - */ - @Override - public int clearFaultsCurrentOfNode(String nodeName) { - if (assertIfClientNullForNodeName(nodeName)) { - return -1; - } - - LOG.debug("Remove from currentFaults all faults for node: {}", nodeName); - return eventRWFaultCurrentDB.remove(EsFaultCurrent.getQueryForOneNode(nodeName)); - } - - /** - * Remove all entries for one node - * - * @param nodeName contains the mountpointname - * @param objectId of element to be deleted - * @return number of deleted entries - */ - @Override - public int clearFaultsCurrentOfNodeWithObjectId(String nodeName, String objectId) { - if (assertIfClientNullForNodeName(nodeName)) { - return -1; - } - - LOG.debug("Remove from currentFaults all faults for node/objectId: {}/{}", nodeName, objectId); - return eventRWFaultCurrentDB.remove(EsFaultCurrent.getQueryForOneNodeAndObjectId(nodeName, objectId)); - } - - /** - * Deliver list with all mountpoint/node-names in the database. - * - * @return List of all mountpoint/node-names the had active alarms. - */ - @Override - public @Nonnull List getAllNodesWithCurrentAlarms() { - if (assertIfClientNull("No DB, can not delete for all nodes", null)) { - return new ArrayList<>(); - } - - LOG.debug("Remove from currentFaults faults for all node"); - List nodeNames = new ArrayList<>(); - - for (FaultcurrentEntity fault : eventRWFaultCurrentDB.doReadAll().getHits()) { - String nodeName = fault.getNodeId(); - if (!nodeNames.contains(nodeName)) { - // this.clearFaultsCurrentOfNode(nodeName); -> Function shifted - nodeNames.add(nodeName); - } - } - return nodeNames; - } - - // -- Inventory and equipment current - - /** - * write internal equipment to database - * - * @param internalEquipment with mandatory fields. - */ - @Override - public void writeInventory(Inventory internalEquipment) { - - if (assertIfClientNullForNodeName(internalEquipment.getNodeId())) { - return; - } - if (internalEquipment.getManufacturerIdentifier() == null) { - internalEquipment = new InventoryBuilder(internalEquipment).setManufacturerIdentifier("").build(); - } - if (internalEquipment.getDate() == null) { - internalEquipment = new InventoryBuilder(internalEquipment).setDate("").build(); - } - - eventRWEquipment.write(internalEquipment, internalEquipment.getNodeId() + "/" + internalEquipment.getUuid()); - } - - - // -- Networkelement - - - /** - * join base with parameters of toJoin (only non null values) - * - * @param base base object - * @param toJoin object with new property values - * @return new joined object - */ - @SuppressWarnings("unused") - private NetworkElementConnectionEntity joinNe(NetworkElementConnectionEntity base, - NetworkElementConnectionEntity toJoin) { - if (base == null) { - return toJoin; - } - NetworkElementConnectionBuilder builder = new NetworkElementConnectionBuilder(base); - if (toJoin != null) { - if (toJoin.isIsRequired() != null) { - builder.setIsRequired(toJoin.isIsRequired()); - } - if (toJoin.getCoreModelCapability() != null) { - builder.setCoreModelCapability(toJoin.getCoreModelCapability()); - } - if (toJoin.getDeviceType() != null) { - builder.setDeviceType(toJoin.getDeviceType()); - } - if (toJoin.getHost() != null) { - builder.setHost(toJoin.getHost()); - } - if (toJoin.getNodeDetails() != null) { - builder.setNodeDetails(toJoin.getNodeDetails()); - } - if (toJoin.getPassword() != null) { - builder.setPassword(toJoin.getPassword()); - } - if (toJoin.getPort() != null) { - builder.setPort(toJoin.getPort()); - } - if (toJoin.getStatus() != null) { - builder.setStatus(toJoin.getStatus()); - } - if (toJoin.getUsername() != null) { - builder.setUsername(toJoin.getUsername()); - } - } - return builder.build(); - } - - /** - * - * @param networkElementConnectionEntitiy to wirte to DB - * @param nodeId Id for this DB element - */ - @Override - public boolean updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy, - String nodeId) { - return this.networkelementConnectionDB.update(networkElementConnectionEntitiy, nodeId) != null; - // NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId); - // this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId); - } - - /** - * Update after new mountpoint registration - * - * @param networkElementConnectionEntitiy data - * @param nodeId of device (mountpoint name) - */ - @Override - public boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy, - String nodeId) { - LOG.info("update networkelement-connection for {} with data {}", nodeId, networkElementConnectionEntitiy); - return this.networkelementConnectionDB.updateOrCreate(networkElementConnectionEntitiy, nodeId, - Arrays.asList("is-required", "username", "password")) != null; - // NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId); - // this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId); - - } - - /* please do not remove */ - // public void cleanNetworkElementConnections() { - // this.networkelementConnectionDB.remove(QueryBuilders.matchQuery("is-required", false)); - // CreateNetworkElementConnectionInput x = new CreateNetworkElementConnectionInputBuilder().setStatus(ConnectionLogStatus.Disconnected).build(); - // this.networkelementConnectionDB.update(x,QueryBuilders.matchAllQuery()); - // } - - @Override - public void removeNetworkConnection(String nodeId) { - Boolean isRequired; - NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId); - if (e != null && (isRequired = e.isIsRequired()) != null) { - if (isRequired) { - LOG.debug("updating connection status for {} of required ne to disconnected", nodeId); - this.networkelementConnectionDB.update(new UpdateNetworkElementConnectionInputBuilder() - .setStatus(ConnectionLogStatus.Disconnected).build(), nodeId); - } else { - LOG.debug("remove networkelement-connection for {} entry because of non-required", nodeId); - this.networkelementConnectionDB.remove(nodeId); - } - } else { - LOG.warn("Unable to update connection-status. dbentry for {} not found in networkelement-connection", - nodeId); - } - } - - // -- Multiple areas - - @Override - public int doIndexClean(Date olderAreOutdated) { - - String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated); - int removed = 0; - - QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp); - removed += eventRWEventLogDevicemanager.remove(queryEventBase); - - QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); - removed += eventRWFaultLogDB.remove(queryFaultLog); - return removed; - } - - @Override - public int getNumberOfOldObjects(Date olderAreOutdated) { - - String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated); - int numberOfElements = 0; - - QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp); - numberOfElements += eventRWEventLogDevicemanager.doReadAll(queryEventBase).getTotal(); - - QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); - numberOfElements += eventRWFaultLogDB.doReadAll(queryFaultLog).getTotal(); - - return numberOfElements; - } - - // -- Helper - - /** - * Verify status of client - * - * @param event that is printed with message - * @return true if client is null - */ - private boolean assertIfClientNull(Object event) { - return assertIfClientNull("No DB, can not write: {}", event); - } - - private boolean assertIfClientNullForNodeName(Object object) { - return assertIfClientNull("No DB, can not handle node: {}", object); - } - - /** - * Verify status of client - * - * @param message to print including {} for object printout. - * @return true if client is null - */ - private boolean assertIfClientNull(String message, Object object) { - if (client == null) { - LOG.debug(message, object); - return true; - } - return false; - } - - // ### sub classes - - - private static class EsEventBase { - /** - * Query to get older Elements - * - * @param netconfTimeStamp to identify older Elements - * @return QueryBuilder for older elements related to timestamp - */ - private static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { - return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp); - } - } - private static class EsFaultLogDevicemanager { - /** - * Get older Elements - * - * @param netconfTimeStamp to identify query elements older than this timestamp. - * @return QueryBuilder for related elements - */ - public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { - return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp); - } - } - public static class EsFaultCurrent { - /** - * @param nodeName name of the node - * @return query builder - */ - public static QueryBuilder getQueryForOneNode(String nodeName) { - return QueryBuilders.matchQuery("node-id", nodeName); - } - - public static QueryBuilder getQueryForOneNodeAndObjectId(String nodeName, String objectId) { - BoolQueryBuilder bq = QueryBuilders.boolQuery(); - bq.must(QueryBuilders.matchQuery("node-id", nodeName)); - bq.must(QueryBuilders.matchQuery("object-id", objectId)); - return bq; - } - } - - @Override - public List getNetworkElementConnections() { - return this.networkelementConnectionDB.doReadAll().getHits(); - } - - @Override - public void doWritePerformanceData(List list) { - - list.forEach(elem -> { - GranularityPeriodType granularityPeriod = nnGetGranularityPeriodType(elem.getGranularityPeriod()); - //_id": "Sim12600/LP-MWPS-TTP-01/2017-07-04T15:15:00.0+00:00" - StringBuffer id = new StringBuffer(); - DateAndTime date = elem.getTimeStamp(); - id.append(elem.getNodeName()); - id.append("/"); - id.append(elem.getUuidInterface()); - id.append("/"); - id.append(date != null ? date.getValue() : "null"); - - switch (granularityPeriod) { - case Period15Min: - pmData15mDB.write(elem, id.toString()); - break; - case Period24Hours: - pmData24hDB.write(elem, id.toString()); - break; - case Unknown: - default: - LOG.debug("Unknown granularity {} id {}", granularityPeriod, id); - break; - } - }); - - } - - @NonNull - GranularityPeriodType nnGetGranularityPeriodType(@Nullable GranularityPeriodType granularityPeriod) { - return granularityPeriod != null ? granularityPeriod : GranularityPeriodType.Unknown; - } - - @Override - public HtDatabaseClient getRawClient() { - return this.client; - } - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseMaintenanceService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseMaintenanceService.java deleted file mode 100644 index 3e9a93902..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseMaintenanceService.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * ============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.data; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.onap.ccsdk.features.sdnr.wt.common.HtAssert; -import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceEntity; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HtDatabaseMaintenanceService implements HtDatabaseMaintenance { - - private static final Logger LOG = LoggerFactory.getLogger(HtDatabaseMaintenanceService.class); - - private final EsDataObjectReaderWriter2 maintenanceRW; - private final EsDataObjectReaderWriter2 requiredNeRW; - - public HtDatabaseMaintenanceService(@NonNull HtDatabaseClient client) throws ClassNotFoundException { - HtAssert.nonnull(client); - - // Create control structure - maintenanceRW = new EsDataObjectReaderWriter2<>(client, Entity.Maintenancemode, MaintenanceEntity.class, - MaintenanceBuilder.class, true).setEsIdAttributeName("_id"); - - requiredNeRW = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection, - NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true) - .setEsIdAttributeName("_id"); - - } - - /** - * Get existing object for mountpoint to manage maintenance mode - * - * @return Object with configuration - */ - @Override - @Nullable - public MaintenanceEntity getMaintenance(@Nullable String mountpointId) { - MaintenanceEntity deviceMaintenanceMode = null; - if (maintenanceRW != null && mountpointId != null) { - deviceMaintenanceMode = maintenanceRW.read(mountpointId); - } - return deviceMaintenanceMode; - } - - @Override - public MaintenanceEntity setMaintenance(MaintenanceEntity m) { - if (maintenanceRW != null) { - if (maintenanceRW.write(m, m.getNodeId()) == null) { - throw new IllegalArgumentException("Problem writing to database: " + m.getId()); - } - LOG.info("Wrote maintenance object {}", m.toString()); - } - return m; - } - - @Override - public List getAll() { - return maintenanceRW != null ? maintenanceRW.doReadAll().getHits() : new ArrayList<>(); - } - - @Override - public MaintenanceEntity createIfNotExists(String mountpointId) { - MaintenanceEntity deviceMaintenanceMode = null; - if (maintenanceRW != null) { - deviceMaintenanceMode = maintenanceRW.read(mountpointId); - if (deviceMaintenanceMode == null) { - LOG.debug("creating empty maintenance object in database"); - deviceMaintenanceMode = getDefaultMaintenance(mountpointId); - maintenanceRW.write(deviceMaintenanceMode, mountpointId); - } else { - LOG.debug("maintenance object already exists in database"); - } - } else { - LOG.warn("cannot create maintenance obj. db reader/writer is null"); - } - return deviceMaintenanceMode; - } - - @Override - public void deleteIfNotRequired(String mountPointNodeName) { - - if (!this.isRequireNe(mountPointNodeName)) { - if (maintenanceRW != null) { - LOG.debug("removing maintenance object in database for " + mountPointNodeName); - maintenanceRW.remove(mountPointNodeName); - } else { - LOG.warn("cannot create maintenance obj. db reader/writer is null"); - } - } - - - } - - /** - * Provide default maintenanceinformation for a device - * - * @param mountpointId nodeId of device - * @return default data - */ - static private MaintenanceEntity getDefaultMaintenance(String mountpointId) { - - DateAndTime now = NetconfTimeStampImpl.getConverter().getTimeStamp(); - - MaintenanceBuilder deviceMaintenanceModeBuilder = new MaintenanceBuilder(); - deviceMaintenanceModeBuilder.setNodeId(mountpointId).setId(mountpointId); - // Use time from mountpoint creation - deviceMaintenanceModeBuilder.setDescription(""); - // Use time from mountpoint creation - deviceMaintenanceModeBuilder.setStart(now); - deviceMaintenanceModeBuilder.setEnd(now); - deviceMaintenanceModeBuilder.setActive(false); - - // Reference to all - //consistent to UI input to null/not empty string - //deviceMaintenanceModeBuilder.setObjectIdRef(""); - //deviceMaintenanceModeBuilder.setProblem(""); - - return deviceMaintenanceModeBuilder.build(); - } - - // -- Private - /** - * Check in required ne if entry exists for mountpointNodeName - * - * @param mountPointNodeName - * @return - */ - @SuppressWarnings("null") - private boolean isRequireNe(String mountPointNodeName) { - NetworkElementConnectionEntity ne = null; - if (requiredNeRW != null) { - LOG.debug("searching for entry in required-networkelement for " + mountPointNodeName); - ne = requiredNeRW.read(mountPointNodeName); - } else { - LOG.warn("cannot read db. no db reader writer initialized"); - } - if (ne != null && ne.isIsRequired() != null) { - return ne.isIsRequired(); - } else { - return false; - } - } - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java index c229006ff..4998c3031 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java @@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit; 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.config.HostInfo; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.acessor.DataObjectAcessorWithId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data; import org.slf4j.Logger; @@ -47,14 +48,14 @@ public class MediatorServerDataProvider implements AutoCloseable { private boolean isRunning; public MediatorServerDataProvider(HostInfo[] hosts) throws Exception { - this(hosts, null, null); + this(hosts, null, null, false); } - public MediatorServerDataProvider(HostInfo[] hosts, String authUsername, String authPassword) throws Exception { + public MediatorServerDataProvider(HostInfo[] hosts, String authUsername, String authPassword, boolean trustAll) throws Exception { super(); LOG.info("Start {}", this.getClass().getName()); this.entries = new HashMap<>(); - this.dbClient = HtDatabaseClient.getClient(hosts, authUsername, authPassword); + this.dbClient = HtDatabaseClient.getClient(hosts, authUsername, authPassword, trustAll); this.mediatorserverRW = new DataObjectAcessorWithId<>(dbClient, Entity.MediatorServer, Data.class); this.scheduler.scheduleAtFixedRate(onTick, this.REFRESH_INTERVAL, this.REFRESH_INTERVAL, TimeUnit.SECONDS); } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilter.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilter.java deleted file mode 100644 index 4e7bee9d0..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilter.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * ============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.data; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; - -import org.eclipse.jdt.annotation.Nullable; -import org.onap.ccsdk.features.sdnr.wt.common.database.data.DbFilter; -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.common.database.requests.SearchRequest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SortOrder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Pagination; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Sortorder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class QueryByFilter { - - private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorPm.class); - private static final List timestampValueNames = Arrays.asList("timestamp", "start", "end"); - - private static List emptySortOrderList = new ArrayList<>(); - private static List emptyFilterList = new ArrayList<>(); - - // Derived from input - private long page; - private long pageSize; - private long fromPage; - private List filterList; - private List sortOrder; - - /** - * Process input from RPC into Queries to database - * - * @param input Input from RPC, for test it could be null - */ - public QueryByFilter(EntityInput input) { - page = -1; - pageSize = -1; - if (input != null) { - @Nullable - Pagination pagination = input.getPagination(); - if (pagination != null) { - BigInteger pageOrNull = pagination.getPage(); - if (pageOrNull != null) { - page = pageOrNull.longValue(); - } - Long pageSizeOrNull = pagination.getSize(); - if (pageSizeOrNull != null) { - pageSize = pageSizeOrNull; - } - } - } - if (page < 0) - page = 1; - if (pageSize < 0) - pageSize = 1; - - fromPage = (page - 1) * pageSize; - if (fromPage < 0 || pageSize > 10000) - throw new IllegalArgumentException("mismatching input parameters. From:" + fromPage + " size:" + pageSize); - - filterList = input.getFilter(); - if (filterList == null) - filterList = emptyFilterList; - sortOrder = input.getSortorder(); - if (sortOrder == null) - sortOrder = emptySortOrderList; - - } - - public QueryBuilder getQueryBuilderByFilter() { - return getQueryBuilderByFilter(""); - } - - public QueryBuilder getQueryBuilderByFilter(String prefix) { - QueryBuilder queryBuilder = fromFilter(filterList, prefix).from(fromPage).size(pageSize); - setSortOrder(queryBuilder, sortOrder, prefix); - return queryBuilder; - } - - public SearchRequest getSearchRequestByFilter(String nodeKey, String uuidKey, String index, String dataType) { - Filter nodeFilter = getFilter(filterList, nodeKey); - if (nodeFilter != null) { - SearchRequest request = new SearchRequest(index, dataType); - request.setQuery( - QueryBuilders.matchQuery(nodeKey, nodeFilter.getFiltervalue()).aggregations(uuidKey).size(0)); - return request; - } else { - String msg = "no nodename in filter found "; - LOG.debug(msg); - throw new IllegalArgumentException(msg); - } - } - - public SearchRequest getSearchRequestBySortOrder(String nodeKey, String uuidKey, String index, String dataType) { - Sortorder soNode = getSortOrder(sortOrder, nodeKey); - SearchRequest request = new SearchRequest(index, dataType); - QueryBuilder query = null; - if (soNode != null) { - query = QueryBuilders.matchAllQuery().aggregations(nodeKey, convert(soNode.getSortorder())).size(0); - } else { - query = QueryBuilders.matchAllQuery().aggregations(nodeKey).size(0); - } - request.setQuery(query); - return request; - } - - public long getPage() { - return page; - } - - public long getPageSize() { - return pageSize; - } - - public long getPageStartIndex() { - return fromPage; - } - - @Override - public String toString() { - return "QueryByFilter [page=" + page + ", pageSize=" + pageSize + ", fromPage=" + fromPage + ", filterList=" - + filterList + ", sortOrder=" + sortOrder + "]"; - } - - /* - * Private and static implementations - */ - private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List sortorder, String prefix) { - if (sortorder != null && sortorder.size() > 0) { - for (Sortorder so : sortorder) { - query.sort(handlePrefix(prefix, so.getProperty()), convert(so.getSortorder())); - } - } - return query; - } - - private static org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder convert(SortOrder sortOrder) { - return sortOrder == SortOrder.Ascending - ? org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING - : org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.DESCENDING; - }; - - private static Sortorder getSortOrder(@Nullable List list, String prop) { - if (list == null) { - return null; - } - for (Sortorder o : list) { - if (prop.equals(o.getProperty())) { - return o; - } - } - return null; - } - - private static Filter getFilter(@Nullable List list, String prop) { - if (list == null) { - return null; - } - for (Filter f : list) { - if (prop.equals(f.getProperty())) { - return f; - } - } - return null; - } - - private static String fillTimeStamp(String value) { - int idx = value.lastIndexOf("*"); - final String REPLACE = "0000-00-00T00:00:00.0Z"; - String s = value.substring(0, idx) + REPLACE.substring(idx); - if (Integer.parseInt(s.substring(5, 7)) == 0) { - s = s.substring(0, 5) + "01-" + s.substring(8); - } - if (Integer.parseInt(s.substring(8, 10)) == 0) { - s = s.substring(0, 8) + "01" + s.substring(10); - } - - return s; - } - - /** - * convert timestamp with ending placeholder in filter to elasticsearch filter e.g. 2017* => gte: - * 2017-01-01T00:00:00Z, lt:2018-01-01T00:00:00Z - * - * 201* => 2010-01... 2020 .. 2018-* => 2018-01... <=> 2019-01 - * - */ - private static @Nullable QueryBuilder fromTimestampSearchFilter(String property, String value) { - if (!value.endsWith("*")) { - return null; - } - int idx = value.lastIndexOf("*"); - String lowerEnd = fillTimeStamp(value); - String upperEnd = null; - NetconfTimeStamp converter = NetconfTimeStampImpl.getConverter(); - Date dt = null; - try { - dt = converter.getDateFromNetconf(lowerEnd); - } catch (Exception e) { - - } - if (dt == null) { - return null; - } - // property.substring(0,idx)+REPLACE.substring(idx+1); - Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - c.setTime(dt); - int tmpvalue; - switch (idx) { - case 1: // (2*) - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1000); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 2: // (20*) - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 100); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 3: // (200*) - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 10); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 4: // (2000*) - case 5: // (2000-*) - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 6: // switch 10 months (2000-0* or 2000-1*) - tmpvalue = c.get(Calendar.MONTH); - if (tmpvalue < 9) { - c.set(Calendar.MONTH, 9); - } else { - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1); - c.set(Calendar.MONTH, 0); - } - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - - break; - case 7: // switch one month (2018-01* or 2018-01-*) - case 8: - c.add(Calendar.MONTH, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 9: // (2018-01-0*) - tmpvalue = c.get(Calendar.DAY_OF_MONTH); - if (tmpvalue == 1) { - c.set(Calendar.DAY_OF_MONTH, 10); - } else if (tmpvalue == 10) { - c.set(Calendar.DAY_OF_MONTH, 20); - } else if (tmpvalue == 20) { - if (c.getActualMaximum(Calendar.DAY_OF_MONTH) < 30) { - c.set(Calendar.DAY_OF_MONTH, 1); - c.add(Calendar.MONTH, 1); - } else { - c.set(Calendar.DAY_OF_MONTH, 30); - } - } else if (tmpvalue == 30) { - c.set(Calendar.DAY_OF_MONTH, 1); - c.add(Calendar.MONTH, 1); - } else { - break; - } - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 10: // (2018-01-01*) - case 11: // (2018-01-01T*) - c.add(Calendar.DAY_OF_MONTH, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 12: // (2018-01-01T1*) - tmpvalue = c.get(Calendar.HOUR_OF_DAY); - if (tmpvalue == 20) { - c.set(Calendar.HOUR_OF_DAY, 0); - c.add(Calendar.DAY_OF_MONTH, 1); - } else { - c.add(Calendar.HOUR_OF_DAY, 10); - } - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 13: // (2018-01-01T11*) - case 14: // (2018-01-01T11-*) - c.add(Calendar.HOUR_OF_DAY, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 15: // (2018-01-01T11-3*) - c.add(Calendar.MINUTE, 10); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 16: // (2018-01-01T11-32*) - case 17: // (2018-01-01T11-32-*) - c.add(Calendar.MINUTE, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 18: // (2018-01-01T11-32-1*) - c.add(Calendar.SECOND, 10); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 19: // (2018-01-01T11-32-11*) - case 20: // (2018-01-01T11-32-11.*) - c.add(Calendar.SECOND, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - - default: - break; - } - - if (upperEnd == null) { - return null; - } - return QueryBuilders.rangeQuery(property).gte(lowerEnd).lt(upperEnd); - - } - - private static QueryBuilder fromFilter(@Nullable List filters, String prefix) { - if (filters == null || filters.size() == 0) { - return QueryBuilders.matchAllQuery(); - - } else if (filters.size() == 1) { - QueryBuilder query; - String p = filters.get(0).getProperty(); - String v = filters.get(0).getFiltervalue(); - if ("id".equals(p)) { - p = "_id"; - } else { - // v=v.toLowerCase(); - } - if (DbFilter.hasSearchParams(v)) { - if (p != null && timestampValueNames.contains(p.toLowerCase())) { - query = fromTimestampSearchFilter(p, v); - if (query != null) { - return query; - } - } - return QueryBuilders.regex(p, DbFilter.createDatabaseRegex(v)); - - - } else if (DbFilter.isComparisonValid(v)) { - RangeQueryBuilder q = DbFilter.getRangeQuery(handlePrefix(prefix, p), v); - if (q != null) { - return q; - } else { - return QueryBuilders.matchQuery(handlePrefix(prefix, p), v); - } - } else { - return QueryBuilders.matchQuery(handlePrefix(prefix, p), v); - } - } else { - BoolQueryBuilder query = new BoolQueryBuilder(); - QueryBuilder tmpQuery; - for (Filter fi : filters) { - String p = fi.getProperty(); - String v = fi.getFiltervalue(); - if ("id".equals(p)) { - p = "_id"; - } else { - // v=v.toLowerCase(); - } - if (DbFilter.hasSearchParams(v)) { - if (p != null && timestampValueNames.contains(p.toLowerCase())) { - tmpQuery = fromTimestampSearchFilter(p, v); - if (tmpQuery != null) { - query.must(tmpQuery); - } else { - query.must(QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v))); - } - } else { - query.must(QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v))); - } - } else if (DbFilter.isComparisonValid(v)) { - RangeQueryBuilder q = DbFilter.getRangeQuery(handlePrefix(prefix, p), v); - if (q != null) { - query.must(q); - } else { - query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v)); - } - } else { - query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v)); - } - } - LOG.trace("Query result. {}", query.toJSON()); - return query; - } - } - - private static String handlePrefix(String prefix, String p) { - return (prefix != null ? prefix : "") + p; - } - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilterStatic.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilterStatic.java deleted file mode 100644 index 4abe65856..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilterStatic.java +++ /dev/null @@ -1,336 +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.data; - -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; -import org.eclipse.jdt.annotation.Nullable; -import org.onap.ccsdk.features.sdnr.wt.common.database.data.DbFilter; -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.model.NetconfTimeStamp; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SortOrder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Sortorder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class QueryByFilterStatic { - - private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorPm.class); - private static final List timestampValueNames = Arrays.asList("timestamp", "start", "end"); - - private QueryByFilterStatic() { - //Hide - } - - static long getPage(EntityInput input) { - return getPage(input, 1); - } - - private static long getPage(EntityInput input, long defaultValue) { - return input.getPagination() != null ? input.getPagination().getPage().longValue() : defaultValue; - } - - static long getPageSize(EntityInput input) { - return getPageSize(input, 1); - } - - private static long getPageSize(EntityInput input, long defaultValue) { - return input.getPagination() != null ? input.getPagination().getSize().longValue() : defaultValue; - } - - - public static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List sortorder) { - return setSortOrder(query, sortorder, ""); - } - - private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List sortorder, String prefix) { - if (sortorder != null && sortorder.size() > 0) { - for (Sortorder so : sortorder) { - query.sort((prefix != null ? prefix : "") + so.getProperty(), - so.getSortorder() == SortOrder.Ascending - ? org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING - : org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.DESCENDING); - } - } - return query; - - } - - - public static Sortorder getSortOrder(@Nullable List list, String prop) { - if (list == null) { - return null; - } - for (Sortorder o : list) { - if (prop.equals(o.getProperty())) { - return o; - } - } - return null; - } - - public static Filter getFilter(@Nullable List list, String prop) { - if (list == null) { - return null; - } - for (Filter f : list) { - if (prop.equals(f.getProperty())) { - return f; - } - } - return null; - } - - public static QueryBuilder fromFilter(@Nullable List filters) { - return fromFilter(filters, ""); - } - - private static String fillTimeStamp(String value) { - int idx = value.lastIndexOf("*"); - final String REPLACE = "0000-00-00T00:00:00.0Z"; - String s = value.substring(0, idx) + REPLACE.substring(idx); - if (Integer.parseInt(s.substring(5, 7)) == 0) { - s = s.substring(0, 5) + "01-" + s.substring(8); - } - if (Integer.parseInt(s.substring(8, 10)) == 0) { - s = s.substring(0, 8) + "01" + s.substring(10); - } - - return s; - } - - /** - * convert timestamp with ending placeholder in filter to elasticsearch filter e.g. 2017* => gte: - * 2017-01-01T00:00:00Z, lt:2018-01-01T00:00:00Z - * - * 201* => 2010-01... 2020 .. 2018-* => 2018-01... <=> 2019-01 - * - */ - private static @Nullable QueryBuilder fromTimestampSearchFilter(String property, String value) { - if (!value.endsWith("*")) { - return null; - } - int idx = value.lastIndexOf("*"); - String lowerEnd = fillTimeStamp(value); - String upperEnd = null; - NetconfTimeStamp converter = NetconfTimeStampImpl.getConverter(); - Date dt = null; - try { - dt = converter.getDateFromNetconf(lowerEnd); - } catch (Exception e) { - - } - if (dt == null) { - return null; - } - // property.substring(0,idx)+REPLACE.substring(idx+1); - Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - c.setTime(dt); - int tmpvalue; - switch (idx) { - case 1: // (2*) - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1000); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 2: // (20*) - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 100); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 3: // (200*) - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 10); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 4: // (2000*) - case 5: // (2000-*) - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 6: //switch 10 months (2000-0* or 2000-1*) - tmpvalue = c.get(Calendar.MONTH); - if (tmpvalue < 9) { - c.set(Calendar.MONTH, 9); - } else { - c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1); - c.set(Calendar.MONTH, 0); - } - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - - break; - case 7: //switch one month (2018-01* or 2018-01-*) - case 8: - c.add(Calendar.MONTH, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 9: // (2018-01-0*) - tmpvalue = c.get(Calendar.DAY_OF_MONTH); - if (tmpvalue == 1) { - c.set(Calendar.DAY_OF_MONTH, 10); - } else if (tmpvalue == 10) { - c.set(Calendar.DAY_OF_MONTH, 20); - } else if (tmpvalue == 20) { - if (c.getActualMaximum(Calendar.DAY_OF_MONTH) < 30) { - c.set(Calendar.DAY_OF_MONTH, 1); - c.add(Calendar.MONTH, 1); - } else { - c.set(Calendar.DAY_OF_MONTH, 30); - } - } else if (tmpvalue == 30) { - c.set(Calendar.DAY_OF_MONTH, 1); - c.add(Calendar.MONTH, 1); - } else { - break; - } - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 10: // (2018-01-01*) - case 11: // (2018-01-01T*) - c.add(Calendar.DAY_OF_MONTH, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 12: // (2018-01-01T1*) - tmpvalue = c.get(Calendar.HOUR_OF_DAY); - if (tmpvalue == 20) { - c.set(Calendar.HOUR_OF_DAY, 0); - c.add(Calendar.DAY_OF_MONTH, 1); - } else { - c.add(Calendar.HOUR_OF_DAY, 10); - } - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 13: // (2018-01-01T11*) - case 14: // (2018-01-01T11-*) - c.add(Calendar.HOUR_OF_DAY, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 15: // (2018-01-01T11-3*) - c.add(Calendar.MINUTE, 10); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 16: // (2018-01-01T11-32*) - case 17: // (2018-01-01T11-32-*) - c.add(Calendar.MINUTE, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 18: // (2018-01-01T11-32-1*) - c.add(Calendar.SECOND, 10); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - case 19: // (2018-01-01T11-32-11*) - case 20: // (2018-01-01T11-32-11.*) - c.add(Calendar.SECOND, 1); - upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); - break; - - default: - break; - } - - if (upperEnd == null) { - return null; - } - return QueryBuilders.rangeQuery(property).gte(lowerEnd).lt(upperEnd); - - } - - private static QueryBuilder fromFilter(@Nullable List filters, String prefix) { - if (filters == null || filters.size() == 0) { - return QueryBuilders.matchAllQuery(); - - } else if (filters.size() == 1) { - QueryBuilder query; - String p = filters.get(0).getProperty(); - String v = filters.get(0).getFiltervalue(); - if ("id".equals(p)) { - p = "_id"; - } else { - // v=v.toLowerCase(); - } - if (DbFilter.hasSearchParams(v)) { - if (p != null && timestampValueNames.contains(p.toLowerCase())) { - query = fromTimestampSearchFilter(p, v); - if (query != null) { - return query; - } - } - return QueryBuilders.regex(p, DbFilter.createDatabaseRegex(v)); - - - } else if (DbFilter.isComparisonValid(v)) { - RangeQueryBuilder q = DbFilter.getRangeQuery((prefix != null ? prefix : "") + p, v); - if (q != null) { - return q; - } else { - return QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v); - } - } else { - return QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v); - } - } else { - BoolQueryBuilder query = new BoolQueryBuilder(); - QueryBuilder tmpQuery; - for (Filter fi : filters) { - String p = fi.getProperty(); - String v = fi.getFiltervalue(); - if ("id".equals(p)) { - p = "_id"; - } else { - // v=v.toLowerCase(); - } - if (DbFilter.hasSearchParams(v)) { - if (p != null && timestampValueNames.contains(p.toLowerCase())) { - tmpQuery = fromTimestampSearchFilter(p, v); - if (tmpQuery != null) { - query.must(tmpQuery); - } else { - query.must(QueryBuilders.regex((prefix != null ? prefix : "") + p, - DbFilter.createDatabaseRegex(v))); - } - } else { - query.must(QueryBuilders.regex((prefix != null ? prefix : "") + p, - DbFilter.createDatabaseRegex(v))); - } - } else if (DbFilter.isComparisonValid(v)) { - RangeQueryBuilder q = DbFilter.getRangeQuery((prefix != null ? prefix : "") + p, v); - if (q != null) { - query.must(q); - } else { - query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v)); - } - } else { - query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v)); - } - } - LOG.trace("Query result. {}", query.toJSON()); - return query; - } - } - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryResult.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryResult.java deleted file mode 100644 index 7570523cd..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryResult.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ============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.data; - -import java.math.BigInteger; - -import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PaginationOutputG; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.connectionlog.list.output.PaginationBuilder; - -public class QueryResult { - - private SearchResult result; - private PaginationOutputG pagination; - - public QueryResult(long page, long pageSize, SearchResult result) { - this.result = result; - - PaginationBuilder x = new PaginationBuilder(); - x.setPage(BigInteger.valueOf(page)); - x.setSize(pageSize); - x.setTotal(BigInteger.valueOf(result.getTotal())); - pagination = x.build(); - } - - public QueryResult(QueryByFilter queryByFilter, SearchResult result) { - this.result = result; - - PaginationBuilder x = new PaginationBuilder(); - x.setPage(BigInteger.valueOf(queryByFilter.getPage())); - x.setSize(queryByFilter.getPageSize()); - x.setTotal(BigInteger.valueOf(result.getTotal())); - pagination = x.build(); - } - - - public SearchResult getResult() { - return result; - } - - public PaginationOutputG getPagination() { - return pagination; - } - - - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/YangFileProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/YangFileProvider.java deleted file mode 100644 index 4f259aa4b..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/YangFileProvider.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * ============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.data; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Path; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Date; -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class YangFileProvider { - - private static final Logger LOG = LoggerFactory.getLogger(YangFileProvider.class); - - private static final FilenameFilter yangFilenameFilter = new FilenameFilter() { - - @Override - public boolean accept(File dir, String name) { - return name.toLowerCase().endsWith(".yang"); - } - }; - - private static final int BUFFER_SIZE = 1024; - - private final Path mainSourcePath; - private final List additionalSources; - - public YangFileProvider(String path) { - this.mainSourcePath = new File(path).toPath(); - this.additionalSources = new ArrayList<>(); - } - - public boolean hasFileForModule(String module, String version) { - return this.mainSourcePath.resolve(YangFilename.createFilename(module, version)).toFile().exists(); - } - - public boolean hasFileForModule(String module) { - return this.findYangFiles(module).size() > 0; - } - - private List findYangFiles(String module) { - List list = new ArrayList<>(); - String[] files = this.mainSourcePath.toFile().list(yangFilenameFilter); - YangFilename yangfile; - for (String file : files) { - files = this.mainSourcePath.toFile().list(yangFilenameFilter); - for (String fn : files) { - try { - yangfile = new YangFilename(this.mainSourcePath.resolve(fn).toString()); - if (yangfile.getModule().equals(module)) { - list.add(yangfile); - } - } catch (ParseException e) { - LOG.warn("unable to handle yangfile {}: {}", file, e); - } - } - } - for (Path addPath : this.additionalSources) { - files = addPath.toFile().list(yangFilenameFilter); - for (String file : files) { - try { - yangfile = new YangFilename(addPath.resolve(file).toString()); - if (yangfile.getModule().equals(module)) { - list.add(yangfile); - } - } catch (ParseException e) { - LOG.warn("unable to handle yangfile {}: {}", file, e); - } - } - } - return list; - } - - /** - * get yang file from source with specified version or least newer one if version is null then the latest one - * - * @param module - * @param version - * @return - * @throws ParseException - */ - private @Nullable YangFilename getYangFile(@Nonnull String module, @Nullable String version) throws ParseException { - YangFilename f = null; - List list = this.findYangFiles(module); - - list.sort(SortByDateAscComparator.getInstance()); - - // find specific version or nearest oldest - if (version != null) { - Date rev = YangFilename.parseRevision(version); - for (YangFilename item : list) { - if (rev.equals(item.getRevision())) { - f = item; - break; - } - if (item.getRevision().after(rev)) { - f = item; - break; - } - } - } - // get latest - else { - f = list.get(list.size() - 1); - } - return f; - } - - /** - * write filestream directly to output stream easier for http handling - * - * @param module - * @param version - * @param outputStream - * @return - * @throws IOException - * @throws ParseException - */ - public int writeOutput(@Nonnull String module, @Nullable String version, @Nonnull OutputStream outputStream) - throws IOException, ParseException { - YangFilename fn = this.getYangFile(module, version); - if (fn == null) { - return 0; - } - byte[] buffer = new byte[BUFFER_SIZE]; - int bytesRead = -1; - int sumlen = 0; - InputStream inputStream = null; - try { - inputStream = new FileInputStream(fn.getFilename()); - - while ((bytesRead = inputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead); - sumlen += bytesRead; - } - } catch (IOException e) { - LOG.warn("problem sending {}: {}", fn.getFilename(), e); - } finally { - if (inputStream != null) { - inputStream.close(); - } - } - return sumlen; - } - - private static class SortByDateAscComparator implements Comparator { - - private static SortByDateAscComparator instance; - - @Override - public int compare(YangFilename o1, YangFilename o2) { - return o1.getRevision().compareTo(o2.getRevision()); - } - - public static Comparator getInstance() { - if (instance == null) { - instance = new SortByDateAscComparator(); - } - return instance; - } - - } - - public YangFilename getFileForModule(String module, String rev) throws ParseException { - return this.getYangFile(module, rev); - } - - public YangFilename getFileForModule(String module) throws ParseException { - return this.getFileForModule(module, null); - } - - public boolean hasFileOrNewerForModule(String module, String version) throws ParseException { - return this.getYangFile(module, version) != null; - } - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/YangFilename.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/YangFilename.java deleted file mode 100644 index e5d0b18cd..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/YangFilename.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * ============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.data; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class YangFilename { - - private static final String REGEX = "([^\\/]*)@([0-9]{4}-[0-9]{2}-[0-9]{2}).yang"; - private static final Pattern pattern = Pattern.compile(REGEX, Pattern.MULTILINE); - private final String filename; - private final Matcher matcher; - private Date revision; - private String module; - - public static Date parseRevision(String sRevision) throws ParseException { - final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); - return fmt.parse(sRevision); - } - - public YangFilename(String fn) throws ParseException { - this.filename = fn; - matcher = pattern.matcher(this.filename); - if (!matcher.find()) { - throw new ParseException("unknown filename format", 0); - } - this.module = matcher.group(1); - this.revision = parseRevision(matcher.group(2)); - - } - - public static String createFilename(String module, String rev) { - return String.format("%s@%s.yang", module, rev); - } - - public YangFilename(String module, String rev) throws ParseException { - this(createFilename(module, rev)); - } - - public String getFilename() { - return this.filename; - } - - public Date getRevision() { - return this.revision; - } - - public String getModule() { - return this.module; - } -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessor.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessor.java new file mode 100644 index 000000000..90915fc63 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessor.java @@ -0,0 +1,60 @@ +/* + * ============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.data.acessor; + +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.queries.QueryBuilder; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryByFilter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryResult; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DataObjectAcessor extends EsDataObjectReaderWriter2 { + + private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessor.class); + + DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class clazz) throws ClassNotFoundException { + super(dbClient, entity, clazz); + LOG.info("Create {}", this.getClass().getName()); + } + + public QueryResult getData(EntityInput input) { + + QueryByFilter queryByFilter = new QueryByFilter(input); + QueryBuilder queryBuilder = queryByFilter.getQueryBuilderByFilter(); + // Exception handling during user input for invalid filter input. + // This wrong filter by user is allowed an results into empty data. + boolean ignoreException = queryBuilder.contains("range"); + + LOG.info("Request: {} filter {} ignoreException{}:", this.getDataTypeName(), queryByFilter, ignoreException); + + SearchResult 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/data/acessor/DataObjectAcessorPm.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorPm.java new file mode 100644 index 000000000..aa9da01ad --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorPm.java @@ -0,0 +1,132 @@ +/* + * ============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.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.data.rpctypehelper.QueryByFilter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryResult; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DataObjectAcessorPm extends DataObjectAcessor { + + private final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorPm.class); + + private static final String UUID_KEY = "uuid-interface"; + private static final String NODE_KEY = "node-name"; + private static final String KEY = "node-name"; + + + public enum Intervall { + PMDATA15M("historicalperformance15min", "historicalperformance15min"), PMDATA24H("historicalperformance24h", + "historicalperformance24h"); + + String index; + String type; + + Intervall(String index, String type) { + this.index = index; + this.type = type; + } + + public String getIndex() { + return index; + } + + public String getType() { + return type; + } + } + + private ExtRestClient dbClient; + private Intervall mode; + + public DataObjectAcessorPm(HtDatabaseClient dbClient, Intervall mode, Entity entity, Class clazz) + throws ClassNotFoundException { + super(dbClient, entity, clazz); + LOG.info("DataObjectAcessorPm"); + this.dbClient = dbClient; + this.mode = mode; + } + + /** + * get aggregated list of ltps for filter NODE_KEY + * + * @param input + * @return + * @throws IOException + */ + public QueryResult getDataLtpList(EntityInput input) throws IOException { + + QueryByFilter queryByFilter = new QueryByFilter(input); + SearchRequest request = + queryByFilter.getSearchRequestByFilter(NODE_KEY, UUID_KEY, mode.getIndex(), mode.getType()); + try { + SearchResponse response = this.dbClient.search(request); + AggregationEntries aggs = response.getAggregations(UUID_KEY); + String[] uuids = + aggs.getKeysAsPagedStringList(queryByFilter.getPageSize(), queryByFilter.getPageStartIndex()); + long totalSize = aggs.size(); + return new QueryResult(queryByFilter.getPage(), queryByFilter.getPageSize(), + new SearchResult(uuids, totalSize)); + } catch (IOException e) { + throw new IOException("problem reading ltps for req=" + request, e); + } + } + + /** + * get aggregated devices list + * + * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name') + * @return + * @throws IOException + */ + public QueryResult getDataDeviceList(EntityInput input) throws IOException { + + QueryByFilter queryByFilter = new QueryByFilter(input); + SearchRequest request = + queryByFilter.getSearchRequestBySortOrder(NODE_KEY, UUID_KEY, mode.getIndex(), mode.getType()); + 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(queryByFilter.getPage(), queryByFilter.getPageSize(), + new SearchResult(uuids, totalSize)); + } catch (IOException e) { + throw new IOException("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/data/acessor/DataObjectAcessorStatus.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorStatus.java new file mode 100644 index 000000000..f6fc60e2f --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorStatus.java @@ -0,0 +1,72 @@ +/* + * ============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.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.queries.QueryBuilders; +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.data.rpctypehelper.QueryResult; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.status.output.Data; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.status.output.DataBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.status.entity.FaultsBuilder; + +public class DataObjectAcessorStatus extends DataObjectAcessor { + + final String ESDATATYPE_FAULTCURRENT_SEVERITY_KEY = "severity"; + + private final ExtRestClient dbClient; + private final Entity entity; + + public DataObjectAcessorStatus(HtDatabaseClient dbClient, Entity entity) throws ClassNotFoundException { + super(dbClient, entity, Data.class); + this.dbClient = dbClient; + this.entity = entity; + } + + public QueryResult getDataStatus() throws IOException { + SearchRequest request = getNewInstanceOfSearchRequest(entity); + request.setQuery(QueryBuilders.matchAllQuery().aggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY).size(0)); + SearchResponse response = this.dbClient.search(request); + AggregationEntries aggs = response.getAggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY); + + Data[] data = {new DataBuilder().setFaults(new FaultsBuilder().setCriticals(aggs.getOrDefault("Critical", 0L)) + .setMajors(aggs.getOrDefault("Major", 0L)).setMinors(aggs.getOrDefault("Minor", 0L)) + .setWarnings(aggs.getOrDefault("Warning", 0L)).build()).build()}; + long toalsize = data.length; + return new QueryResult(1L, 1L, new SearchResult(data, toalsize)); + + } + + + private static SearchRequest getNewInstanceOfSearchRequest(Entity entity) { + return new SearchRequest(entity.getName(), entity.getName()); + } + + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorWithId.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorWithId.java new file mode 100644 index 000000000..accd1d894 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/acessor/DataObjectAcessorWithId.java @@ -0,0 +1,41 @@ +/* + * ============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.data.acessor; + +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DataObjectAcessorWithId extends DataObjectAcessor { + + private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorWithId.class); + + public DataObjectAcessorWithId(HtDatabaseClient dbClient, Entity entity, Class clazz) + throws ClassNotFoundException { + super(dbClient, entity, clazz); + setEsIdAttributeName("_id"); + LOG.info("Create {}", this.getClass().getName()); + } + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/FaultEntityManager.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/FaultEntityManager.java new file mode 100644 index 000000000..46252651f --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/FaultEntityManager.java @@ -0,0 +1,98 @@ +/* + * ============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.data.entity; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Fault; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType; + +public class FaultEntityManager { + + private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]"); + + /** + * The leading indication for notification or events that are not in the currentProblem data of the ONF Coremodel + */ + private static final String NOCURRENTPROBLEMINDICATION = "#"; + + /** + * Specific problems are not moving into current problem list + * + * @param problemName to be verified + * @return true if problem is current + */ + public static boolean isManagedAsCurrentProblem(String problemName) { + return !problemName.startsWith(NOCURRENTPROBLEMINDICATION); + } + + public static boolean isManagedAsCurrentProblem(Fault problem) { + return isManagedAsCurrentProblem(problem.getProblem()); + } + + /** + * Specific problems are not moving into current problem list + * + * @param fault to be verified + * @return true if cleared indication + */ + public static boolean isNoAlarmIndication(@Nonnull Fault fault) { + return SeverityType.NonAlarmed.equals(fault.getSeverity()); + } + + /** + * 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) { + + String uuId; + + Matcher matcher = pattern.matcher(objectId); + if (matcher.matches() && matcher.groupCount() == 1) { + uuId = matcher.group(1); + } else { + uuId = objectId; + } + + StringBuffer strBuf = new StringBuffer(); + strBuf.append(nodeName); + strBuf.append("/"); + strBuf.append(uuId); + strBuf.append("/"); + strBuf.append(problemName); + return strBuf.toString(); + } + + /** + * Create Es id + * + * @param fault used to create uuid for faultcurrent + * @return String with Id + */ + public static String genSpecificEsId(FaultcurrentEntity fault) { + return genSpecificEsId(fault.getNodeId(), fault.getObjectId(), fault.getProblem()); + } +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java new file mode 100644 index 000000000..46475f02d --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java @@ -0,0 +1,527 @@ +/* + * ============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.data.entity; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import javax.annotation.Nonnull; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +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.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.ArchiveCleanProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionLogStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.GranularityPeriodType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntityBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateNetworkElementConnectionInputBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Event service, writing all events into the database into the appropriate index. + * + * @author herbert + */ +public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvider { + private static final Logger LOG = LoggerFactory.getLogger(HtDatabaseEventsService.class); + + private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter(); + + private HtDatabaseClient client; + private EsDataObjectReaderWriter2 eventRWEventLogDevicemanager; + private EsDataObjectReaderWriter2 eventRWEquipment; + private EsDataObjectReaderWriter2 eventRWFaultCurrentDB; + private EsDataObjectReaderWriter2 eventRWFaultLogDB; + private EsDataObjectReaderWriter2 eventRWConnectionLogDB; + private final EsDataObjectReaderWriter2 networkelementConnectionDB; + private final EsDataObjectReaderWriter2 pmData15mDB; + private final EsDataObjectReaderWriter2 pmData24hDB; + + @SuppressWarnings("unused") + private final ElasticSearchDataProvider dataProvider; + // --- Construct and initialize + + + public HtDatabaseEventsService(HtDatabaseClient client, ElasticSearchDataProvider elasticSearchDataProvider) + throws Exception { + + LOG.info("Create {} start", HtDatabaseEventsService.class); + this.dataProvider = elasticSearchDataProvider; + + try { + // Create control structure + this.client = client; + + eventRWEventLogDevicemanager = new EsDataObjectReaderWriter2<>(client, Entity.Eventlog, + EventlogEntity.class, EventlogBuilder.class); + + eventRWEquipment = new EsDataObjectReaderWriter2<>(client, Entity.Inventoryequipment, InventoryEntity.class, + InventoryBuilder.class); + + eventRWFaultCurrentDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultcurrent, + FaultcurrentEntity.class, FaultcurrentBuilder.class); + + eventRWFaultLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Faultlog, FaultlogEntity.class, + FaultlogBuilder.class); + + eventRWConnectionLogDB = new EsDataObjectReaderWriter2<>(client, Entity.Connectionlog, + ConnectionlogEntity.class, ConnectionlogBuilder.class); + + networkelementConnectionDB = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection, + NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true) + .setEsIdAttributeName("_id"); + + pmData15mDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance15min, PmdataEntity.class, + PmdataEntityBuilder.class); + + pmData24hDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance24h, PmdataEntity.class, + PmdataEntityBuilder.class); + + } catch (Exception e) { + LOG.error("Can not start database client. Exception: {}", e); + throw new Exception("Can not start database client. Exception: {}", e); + } + LOG.info("Create {} finished. DB Service {} started.", HtDatabaseEventsService.class, + client != null ? "sucessfully" : "not"); + } + + // --- Function + + // -- Connection log + @Override + public void writeConnectionLog(ConnectionlogEntity event) { + if (assertIfClientNull(event)) { + return; + } + LOG.debug("Write event: {}", event); + eventRWConnectionLogDB.write(event, null); + + } + + // -- Event log + @Override + public void writeEventLog(EventlogEntity event) { + if (assertIfClientNull("No client to write {}", event)) { + return; + } + + LOG.debug("Write event: {}", event.toString()); + eventRWEventLogDevicemanager.write(event, null); + } + + + // -- Fault log + + @Override + public void writeFaultLog(FaultlogEntity fault) { + if (assertIfClientNull(fault)) { + return; + } + + LOG.debug("Write fault to faultlog: {}", fault.toString()); + eventRWFaultLogDB.write(fault, null); + } + + // -- Fault current + + @Override + public void updateFaultCurrent(FaultcurrentEntity fault) { + if (assertIfClientNull(fault)) { + return; + } + + if (FaultEntityManager.isManagedAsCurrentProblem(fault)) { + if (FaultEntityManager.isNoAlarmIndication(fault)) { + LOG.debug("Remove from currentFaults: {}", fault.toString()); + eventRWFaultCurrentDB.remove(FaultEntityManager.genSpecificEsId(fault)); + } else { + LOG.debug("Write to currentFaults: {}", fault.toString()); + eventRWFaultCurrentDB.write(fault, FaultEntityManager.genSpecificEsId(fault)); + } + } else { + LOG.debug("Ingnore for currentFaults: {}", fault.toString()); + } + } + + /** + * Remove all entries for one node + * + * @param nodeName contains the mountpointname + * @return number of deleted entries + */ + @Override + public int clearFaultsCurrentOfNode(String nodeName) { + if (assertIfClientNullForNodeName(nodeName)) { + return -1; + } + + LOG.debug("Remove from currentFaults all faults for node: {}", nodeName); + return eventRWFaultCurrentDB.remove(EsFaultCurrent.getQueryForOneNode(nodeName)); + } + + /** + * Remove all entries for one node + * + * @param nodeName contains the mountpointname + * @param objectId of element to be deleted + * @return number of deleted entries + */ + @Override + public int clearFaultsCurrentOfNodeWithObjectId(String nodeName, String objectId) { + if (assertIfClientNullForNodeName(nodeName)) { + return -1; + } + + LOG.debug("Remove from currentFaults all faults for node/objectId: {}/{}", nodeName, objectId); + return eventRWFaultCurrentDB.remove(EsFaultCurrent.getQueryForOneNodeAndObjectId(nodeName, objectId)); + } + + /** + * Deliver list with all mountpoint/node-names in the database. + * + * @return List of all mountpoint/node-names the had active alarms. + */ + @Override + public @Nonnull List getAllNodesWithCurrentAlarms() { + if (assertIfClientNull("No DB, can not delete for all nodes", null)) { + return new ArrayList<>(); + } + + LOG.debug("Remove from currentFaults faults for all node"); + List nodeNames = new ArrayList<>(); + + for (FaultcurrentEntity fault : eventRWFaultCurrentDB.doReadAll().getHits()) { + String nodeName = fault.getNodeId(); + if (!nodeNames.contains(nodeName)) { + // this.clearFaultsCurrentOfNode(nodeName); -> Function shifted + nodeNames.add(nodeName); + } + } + return nodeNames; + } + + // -- Inventory and equipment current + + /** + * write internal equipment to database + * + * @param internalEquipment with mandatory fields. + */ + @Override + public void writeInventory(Inventory internalEquipment) { + + if (assertIfClientNullForNodeName(internalEquipment.getNodeId())) { + return; + } + if (internalEquipment.getManufacturerIdentifier() == null) { + internalEquipment = new InventoryBuilder(internalEquipment).setManufacturerIdentifier("").build(); + } + if (internalEquipment.getDate() == null) { + internalEquipment = new InventoryBuilder(internalEquipment).setDate("").build(); + } + + eventRWEquipment.write(internalEquipment, internalEquipment.getNodeId() + "/" + internalEquipment.getUuid()); + } + + + // -- Networkelement + + + /** + * join base with parameters of toJoin (only non null values) + * + * @param base base object + * @param toJoin object with new property values + * @return new joined object + */ + @SuppressWarnings("unused") + private NetworkElementConnectionEntity joinNe(NetworkElementConnectionEntity base, + NetworkElementConnectionEntity toJoin) { + if (base == null) { + return toJoin; + } + NetworkElementConnectionBuilder builder = new NetworkElementConnectionBuilder(base); + if (toJoin != null) { + if (toJoin.isIsRequired() != null) { + builder.setIsRequired(toJoin.isIsRequired()); + } + if (toJoin.getCoreModelCapability() != null) { + builder.setCoreModelCapability(toJoin.getCoreModelCapability()); + } + if (toJoin.getDeviceType() != null) { + builder.setDeviceType(toJoin.getDeviceType()); + } + if (toJoin.getHost() != null) { + builder.setHost(toJoin.getHost()); + } + if (toJoin.getNodeDetails() != null) { + builder.setNodeDetails(toJoin.getNodeDetails()); + } + if (toJoin.getPassword() != null) { + builder.setPassword(toJoin.getPassword()); + } + if (toJoin.getPort() != null) { + builder.setPort(toJoin.getPort()); + } + if (toJoin.getStatus() != null) { + builder.setStatus(toJoin.getStatus()); + } + if (toJoin.getUsername() != null) { + builder.setUsername(toJoin.getUsername()); + } + } + return builder.build(); + } + + /** + * + * @param networkElementConnectionEntitiy to wirte to DB + * @param nodeId Id for this DB element + */ + @Override + public boolean updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy, + String nodeId) { + return this.networkelementConnectionDB.update(networkElementConnectionEntitiy, nodeId) != null; + // NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId); + // this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId); + } + + /** + * Update after new mountpoint registration + * + * @param networkElementConnectionEntitiy data + * @param nodeId of device (mountpoint name) + */ + @Override + public boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy, + String nodeId) { + LOG.info("update networkelement-connection for {} with data {}", nodeId, networkElementConnectionEntitiy); + return this.networkelementConnectionDB.updateOrCreate(networkElementConnectionEntitiy, nodeId, + Arrays.asList("is-required", "username", "password")) != null; + // NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId); + // this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId); + + } + + /* please do not remove */ + // public void cleanNetworkElementConnections() { + // this.networkelementConnectionDB.remove(QueryBuilders.matchQuery("is-required", false)); + // CreateNetworkElementConnectionInput x = new CreateNetworkElementConnectionInputBuilder().setStatus(ConnectionLogStatus.Disconnected).build(); + // this.networkelementConnectionDB.update(x,QueryBuilders.matchAllQuery()); + // } + + @Override + public void removeNetworkConnection(String nodeId) { + Boolean isRequired; + NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId); + if (e != null && (isRequired = e.isIsRequired()) != null) { + if (isRequired) { + LOG.debug("updating connection status for {} of required ne to disconnected", nodeId); + this.networkelementConnectionDB.update(new UpdateNetworkElementConnectionInputBuilder() + .setStatus(ConnectionLogStatus.Disconnected).build(), nodeId); + } else { + LOG.debug("remove networkelement-connection for {} entry because of non-required", nodeId); + this.networkelementConnectionDB.remove(nodeId); + } + } else { + LOG.warn("Unable to update connection-status. dbentry for {} not found in networkelement-connection", + nodeId); + } + } + + // -- Multiple areas + + @Override + public int doIndexClean(Date olderAreOutdated) { + + String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated); + int removed = 0; + + QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp); + removed += eventRWEventLogDevicemanager.remove(queryEventBase); + + QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); + removed += eventRWFaultLogDB.remove(queryFaultLog); + return removed; + } + + @Override + public int getNumberOfOldObjects(Date olderAreOutdated) { + + String netconfTimeStamp = NETCONFTIME_CONVERTER.getTimeStampAsNetconfString(olderAreOutdated); + int numberOfElements = 0; + + QueryBuilder queryEventBase = EsEventBase.getQueryForTimeStamp(netconfTimeStamp); + numberOfElements += eventRWEventLogDevicemanager.doReadAll(queryEventBase).getTotal(); + + QueryBuilder queryFaultLog = EsFaultLogDevicemanager.getQueryForTimeStamp(netconfTimeStamp); + numberOfElements += eventRWFaultLogDB.doReadAll(queryFaultLog).getTotal(); + + return numberOfElements; + } + + // -- Helper + + /** + * Verify status of client + * + * @param event that is printed with message + * @return true if client is null + */ + private boolean assertIfClientNull(Object event) { + return assertIfClientNull("No DB, can not write: {}", event); + } + + private boolean assertIfClientNullForNodeName(Object object) { + return assertIfClientNull("No DB, can not handle node: {}", object); + } + + /** + * Verify status of client + * + * @param message to print including {} for object printout. + * @return true if client is null + */ + private boolean assertIfClientNull(String message, Object object) { + if (client == null) { + LOG.debug(message, object); + return true; + } + return false; + } + + // ### sub classes + + + private static class EsEventBase { + /** + * Query to get older Elements + * + * @param netconfTimeStamp to identify older Elements + * @return QueryBuilder for older elements related to timestamp + */ + private static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { + return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp); + } + } + private static class EsFaultLogDevicemanager { + /** + * Get older Elements + * + * @param netconfTimeStamp to identify query elements older than this timestamp. + * @return QueryBuilder for related elements + */ + public static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) { + return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp); + } + } + public static class EsFaultCurrent { + /** + * @param nodeName name of the node + * @return query builder + */ + public static QueryBuilder getQueryForOneNode(String nodeName) { + return QueryBuilders.matchQuery("node-id", nodeName); + } + + public static QueryBuilder getQueryForOneNodeAndObjectId(String nodeName, String objectId) { + BoolQueryBuilder bq = QueryBuilders.boolQuery(); + bq.must(QueryBuilders.matchQuery("node-id", nodeName)); + bq.must(QueryBuilders.matchQuery("object-id", objectId)); + return bq; + } + } + + @Override + public List getNetworkElementConnections() { + return this.networkelementConnectionDB.doReadAll().getHits(); + } + + @Override + public void doWritePerformanceData(List list) { + + list.forEach(elem -> { + GranularityPeriodType granularityPeriod = nnGetGranularityPeriodType(elem.getGranularityPeriod()); + //_id": "Sim12600/LP-MWPS-TTP-01/2017-07-04T15:15:00.0+00:00" + StringBuffer id = new StringBuffer(); + DateAndTime date = elem.getTimeStamp(); + id.append(elem.getNodeName()); + id.append("/"); + id.append(elem.getUuidInterface()); + id.append("/"); + id.append(date != null ? date.getValue() : "null"); + + switch (granularityPeriod) { + case Period15Min: + pmData15mDB.write(elem, id.toString()); + break; + case Period24Hours: + pmData24hDB.write(elem, id.toString()); + break; + case Unknown: + default: + LOG.debug("Unknown granularity {} id {}", granularityPeriod, id); + break; + } + }); + + } + + @NonNull + GranularityPeriodType nnGetGranularityPeriodType(@Nullable GranularityPeriodType granularityPeriod) { + return granularityPeriod != null ? granularityPeriod : GranularityPeriodType.Unknown; + } + + @Override + public HtDatabaseClient getRawClient() { + return this.client; + } + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseMaintenanceService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseMaintenanceService.java new file mode 100644 index 000000000..1cb7c3a6e --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseMaintenanceService.java @@ -0,0 +1,176 @@ +/* + * ============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.data.entity; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.common.HtAssert; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HtDatabaseMaintenanceService implements HtDatabaseMaintenance { + + private static final Logger LOG = LoggerFactory.getLogger(HtDatabaseMaintenanceService.class); + + private final EsDataObjectReaderWriter2 maintenanceRW; + private final EsDataObjectReaderWriter2 requiredNeRW; + + public HtDatabaseMaintenanceService(@NonNull HtDatabaseClient client) throws ClassNotFoundException { + HtAssert.nonnull(client); + + // Create control structure + maintenanceRW = new EsDataObjectReaderWriter2<>(client, Entity.Maintenancemode, MaintenanceEntity.class, + MaintenanceBuilder.class, true).setEsIdAttributeName("_id"); + + requiredNeRW = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection, + NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true) + .setEsIdAttributeName("_id"); + + } + + /** + * Get existing object for mountpoint to manage maintenance mode + * + * @return Object with configuration + */ + @Override + @Nullable + public MaintenanceEntity getMaintenance(@Nullable String mountpointId) { + MaintenanceEntity deviceMaintenanceMode = null; + if (maintenanceRW != null && mountpointId != null) { + deviceMaintenanceMode = maintenanceRW.read(mountpointId); + } + return deviceMaintenanceMode; + } + + @Override + public MaintenanceEntity setMaintenance(MaintenanceEntity m) { + if (maintenanceRW != null) { + if (maintenanceRW.write(m, m.getNodeId()) == null) { + throw new IllegalArgumentException("Problem writing to database: " + m.getId()); + } + LOG.info("Wrote maintenance object {}", m.toString()); + } + return m; + } + + @Override + public List getAll() { + return maintenanceRW != null ? maintenanceRW.doReadAll().getHits() : new ArrayList<>(); + } + + @Override + public MaintenanceEntity createIfNotExists(String mountpointId) { + MaintenanceEntity deviceMaintenanceMode = null; + if (maintenanceRW != null) { + deviceMaintenanceMode = maintenanceRW.read(mountpointId); + if (deviceMaintenanceMode == null) { + LOG.debug("creating empty maintenance object in database"); + deviceMaintenanceMode = getDefaultMaintenance(mountpointId); + maintenanceRW.write(deviceMaintenanceMode, mountpointId); + } else { + LOG.debug("maintenance object already exists in database"); + } + } else { + LOG.warn("cannot create maintenance obj. db reader/writer is null"); + } + return deviceMaintenanceMode; + } + + @Override + public void deleteIfNotRequired(String mountPointNodeName) { + + if (!this.isRequireNe(mountPointNodeName)) { + if (maintenanceRW != null) { + LOG.debug("removing maintenance object in database for " + mountPointNodeName); + maintenanceRW.remove(mountPointNodeName); + } else { + LOG.warn("cannot create maintenance obj. db reader/writer is null"); + } + } + + + } + + /** + * Provide default maintenanceinformation for a device + * + * @param mountpointId nodeId of device + * @return default data + */ + static private MaintenanceEntity getDefaultMaintenance(String mountpointId) { + + DateAndTime now = NetconfTimeStampImpl.getConverter().getTimeStamp(); + + MaintenanceBuilder deviceMaintenanceModeBuilder = new MaintenanceBuilder(); + deviceMaintenanceModeBuilder.setNodeId(mountpointId).setId(mountpointId); + // Use time from mountpoint creation + deviceMaintenanceModeBuilder.setDescription(""); + // Use time from mountpoint creation + deviceMaintenanceModeBuilder.setStart(now); + deviceMaintenanceModeBuilder.setEnd(now); + deviceMaintenanceModeBuilder.setActive(false); + + // Reference to all + //consistent to UI input to null/not empty string + //deviceMaintenanceModeBuilder.setObjectIdRef(""); + //deviceMaintenanceModeBuilder.setProblem(""); + + return deviceMaintenanceModeBuilder.build(); + } + + // -- Private + /** + * Check in required ne if entry exists for mountpointNodeName + * + * @param mountPointNodeName + * @return + */ + @SuppressWarnings("null") + private boolean isRequireNe(String mountPointNodeName) { + NetworkElementConnectionEntity ne = null; + if (requiredNeRW != null) { + LOG.debug("searching for entry in required-networkelement for " + mountPointNodeName); + ne = requiredNeRW.read(mountPointNodeName); + } else { + LOG.warn("cannot read db. no db reader writer initialized"); + } + if (ne != null && ne.isIsRequired() != null) { + return ne.isIsRequired(); + } else { + return false; + } + } + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java new file mode 100644 index 000000000..a12391acd --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java @@ -0,0 +1,424 @@ +/* + * ============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.data.rpctypehelper; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.DbFilter; +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.common.database.requests.SearchRequest; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.acessor.DataObjectAcessorPm; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SortOrder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Pagination; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Sortorder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class QueryByFilter { + + private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorPm.class); + private static final List timestampValueNames = Arrays.asList("timestamp", "start", "end"); + + private static List emptySortOrderList = new ArrayList<>(); + private static List emptyFilterList = new ArrayList<>(); + + // Derived from input + private long page; + private long pageSize; + private long fromPage; + private List filterList; + private List sortOrder; + + /** + * Process input from RPC into Queries to database + * + * @param input Input from RPC, for test it could be null + */ + public QueryByFilter(EntityInput input) { + page = -1; + pageSize = -1; + if (input != null) { + @Nullable + Pagination pagination = input.getPagination(); + if (pagination != null) { + BigInteger pageOrNull = pagination.getPage(); + if (pageOrNull != null) { + page = pageOrNull.longValue(); + } + Long pageSizeOrNull = pagination.getSize(); + if (pageSizeOrNull != null) { + pageSize = pageSizeOrNull; + } + } + } + if (page < 0) + page = 1; + if (pageSize < 0) + pageSize = 1; + + fromPage = (page - 1) * pageSize; + if (fromPage < 0 || pageSize > 10000) + throw new IllegalArgumentException("mismatching input parameters. From:" + fromPage + " size:" + pageSize); + + filterList = input.getFilter(); + if (filterList == null) + filterList = emptyFilterList; + sortOrder = input.getSortorder(); + if (sortOrder == null) + sortOrder = emptySortOrderList; + + } + + public QueryBuilder getQueryBuilderByFilter() { + return getQueryBuilderByFilter(""); + } + + public QueryBuilder getQueryBuilderByFilter(String prefix) { + QueryBuilder queryBuilder = fromFilter(filterList, prefix).from(fromPage).size(pageSize); + setSortOrder(queryBuilder, sortOrder, prefix); + return queryBuilder; + } + + public SearchRequest getSearchRequestByFilter(String nodeKey, String uuidKey, String index, String dataType) { + Filter nodeFilter = getFilter(filterList, nodeKey); + if (nodeFilter != null) { + SearchRequest request = new SearchRequest(index, dataType); + request.setQuery( + QueryBuilders.matchQuery(nodeKey, nodeFilter.getFiltervalue()).aggregations(uuidKey).size(0)); + return request; + } else { + String msg = "no nodename in filter found "; + LOG.debug(msg); + throw new IllegalArgumentException(msg); + } + } + + public SearchRequest getSearchRequestBySortOrder(String nodeKey, String uuidKey, String index, String dataType) { + Sortorder soNode = getSortOrder(sortOrder, nodeKey); + SearchRequest request = new SearchRequest(index, dataType); + QueryBuilder query = null; + if (soNode != null) { + query = QueryBuilders.matchAllQuery().aggregations(nodeKey, convert(soNode.getSortorder())).size(0); + } else { + query = QueryBuilders.matchAllQuery().aggregations(nodeKey).size(0); + } + request.setQuery(query); + return request; + } + + public long getPage() { + return page; + } + + public long getPageSize() { + return pageSize; + } + + public long getPageStartIndex() { + return fromPage; + } + + @Override + public String toString() { + return "QueryByFilter [page=" + page + ", pageSize=" + pageSize + ", fromPage=" + fromPage + ", filterList=" + + filterList + ", sortOrder=" + sortOrder + "]"; + } + + /* + * Private and static implementations + */ + private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List sortorder, String prefix) { + if (sortorder != null && sortorder.size() > 0) { + for (Sortorder so : sortorder) { + query.sort(handlePrefix(prefix, so.getProperty()), convert(so.getSortorder())); + } + } + return query; + } + + private static org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder convert(SortOrder sortOrder) { + return sortOrder == SortOrder.Ascending + ? org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING + : org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.DESCENDING; + }; + + private static Sortorder getSortOrder(@Nullable List list, String prop) { + if (list == null) { + return null; + } + for (Sortorder o : list) { + if (prop.equals(o.getProperty())) { + return o; + } + } + return null; + } + + private static Filter getFilter(@Nullable List list, String prop) { + if (list == null) { + return null; + } + for (Filter f : list) { + if (prop.equals(f.getProperty())) { + return f; + } + } + return null; + } + + private static String fillTimeStamp(String value) { + int idx = value.lastIndexOf("*"); + final String REPLACE = "0000-00-00T00:00:00.0Z"; + String s = value.substring(0, idx) + REPLACE.substring(idx); + if (Integer.parseInt(s.substring(5, 7)) == 0) { + s = s.substring(0, 5) + "01-" + s.substring(8); + } + if (Integer.parseInt(s.substring(8, 10)) == 0) { + s = s.substring(0, 8) + "01" + s.substring(10); + } + + return s; + } + + /** + * convert timestamp with ending placeholder in filter to elasticsearch filter e.g. 2017* => gte: + * 2017-01-01T00:00:00Z, lt:2018-01-01T00:00:00Z + * + * 201* => 2010-01... 2020 .. 2018-* => 2018-01... <=> 2019-01 + * + */ + private static @Nullable QueryBuilder fromTimestampSearchFilter(String property, String value) { + if (!value.endsWith("*")) { + return null; + } + int idx = value.lastIndexOf("*"); + String lowerEnd = fillTimeStamp(value); + String upperEnd = null; + NetconfTimeStamp converter = NetconfTimeStampImpl.getConverter(); + Date dt = null; + try { + dt = converter.getDateFromNetconf(lowerEnd); + } catch (Exception e) { + + } + if (dt == null) { + return null; + } + // property.substring(0,idx)+REPLACE.substring(idx+1); + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + c.setTime(dt); + int tmpvalue; + switch (idx) { + case 1: // (2*) + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1000); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 2: // (20*) + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 100); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 3: // (200*) + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 10); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 4: // (2000*) + case 5: // (2000-*) + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 6: // switch 10 months (2000-0* or 2000-1*) + tmpvalue = c.get(Calendar.MONTH); + if (tmpvalue < 9) { + c.set(Calendar.MONTH, 9); + } else { + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1); + c.set(Calendar.MONTH, 0); + } + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + + break; + case 7: // switch one month (2018-01* or 2018-01-*) + case 8: + c.add(Calendar.MONTH, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 9: // (2018-01-0*) + tmpvalue = c.get(Calendar.DAY_OF_MONTH); + if (tmpvalue == 1) { + c.set(Calendar.DAY_OF_MONTH, 10); + } else if (tmpvalue == 10) { + c.set(Calendar.DAY_OF_MONTH, 20); + } else if (tmpvalue == 20) { + if (c.getActualMaximum(Calendar.DAY_OF_MONTH) < 30) { + c.set(Calendar.DAY_OF_MONTH, 1); + c.add(Calendar.MONTH, 1); + } else { + c.set(Calendar.DAY_OF_MONTH, 30); + } + } else if (tmpvalue == 30) { + c.set(Calendar.DAY_OF_MONTH, 1); + c.add(Calendar.MONTH, 1); + } else { + break; + } + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 10: // (2018-01-01*) + case 11: // (2018-01-01T*) + c.add(Calendar.DAY_OF_MONTH, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 12: // (2018-01-01T1*) + tmpvalue = c.get(Calendar.HOUR_OF_DAY); + if (tmpvalue == 20) { + c.set(Calendar.HOUR_OF_DAY, 0); + c.add(Calendar.DAY_OF_MONTH, 1); + } else { + c.add(Calendar.HOUR_OF_DAY, 10); + } + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 13: // (2018-01-01T11*) + case 14: // (2018-01-01T11-*) + c.add(Calendar.HOUR_OF_DAY, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 15: // (2018-01-01T11-3*) + c.add(Calendar.MINUTE, 10); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 16: // (2018-01-01T11-32*) + case 17: // (2018-01-01T11-32-*) + c.add(Calendar.MINUTE, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 18: // (2018-01-01T11-32-1*) + c.add(Calendar.SECOND, 10); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 19: // (2018-01-01T11-32-11*) + case 20: // (2018-01-01T11-32-11.*) + c.add(Calendar.SECOND, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + + default: + break; + } + + if (upperEnd == null) { + return null; + } + return QueryBuilders.rangeQuery(property).gte(lowerEnd).lt(upperEnd); + + } + + private static QueryBuilder fromFilter(@Nullable List filters, String prefix) { + if (filters == null || filters.size() == 0) { + return QueryBuilders.matchAllQuery(); + + } else if (filters.size() == 1) { + QueryBuilder query; + String p = filters.get(0).getProperty(); + String v = filters.get(0).getFiltervalue(); + if ("id".equals(p)) { + p = "_id"; + } else { + // v=v.toLowerCase(); + } + if (DbFilter.hasSearchParams(v)) { + if (p != null && timestampValueNames.contains(p.toLowerCase())) { + query = fromTimestampSearchFilter(p, v); + if (query != null) { + return query; + } + } + return QueryBuilders.regex(p, DbFilter.createDatabaseRegex(v)); + + + } else if (DbFilter.isComparisonValid(v)) { + RangeQueryBuilder q = DbFilter.getRangeQuery(handlePrefix(prefix, p), v); + if (q != null) { + return q; + } else { + return QueryBuilders.matchQuery(handlePrefix(prefix, p), v); + } + } else { + return QueryBuilders.matchQuery(handlePrefix(prefix, p), v); + } + } else { + BoolQueryBuilder query = new BoolQueryBuilder(); + QueryBuilder tmpQuery; + for (Filter fi : filters) { + String p = fi.getProperty(); + String v = fi.getFiltervalue(); + if ("id".equals(p)) { + p = "_id"; + } else { + // v=v.toLowerCase(); + } + if (DbFilter.hasSearchParams(v)) { + if (p != null && timestampValueNames.contains(p.toLowerCase())) { + tmpQuery = fromTimestampSearchFilter(p, v); + if (tmpQuery != null) { + query.must(tmpQuery); + } else { + query.must(QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v))); + } + } else { + query.must(QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v))); + } + } else if (DbFilter.isComparisonValid(v)) { + RangeQueryBuilder q = DbFilter.getRangeQuery(handlePrefix(prefix, p), v); + if (q != null) { + query.must(q); + } else { + query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v)); + } + } else { + query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v)); + } + } + LOG.trace("Query result. {}", query.toJSON()); + return query; + } + } + + private static String handlePrefix(String prefix, String p) { + return (prefix != null ? prefix : "") + p; + } + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilterStatic.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilterStatic.java new file mode 100644 index 000000000..3e4fcfedd --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilterStatic.java @@ -0,0 +1,337 @@ +/* + * ============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.data.rpctypehelper; + +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.common.database.data.DbFilter; +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.data.acessor.DataObjectAcessorPm; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SortOrder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Sortorder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class QueryByFilterStatic { + + private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorPm.class); + private static final List timestampValueNames = Arrays.asList("timestamp", "start", "end"); + + private QueryByFilterStatic() { + //Hide + } + + static long getPage(EntityInput input) { + return getPage(input, 1); + } + + private static long getPage(EntityInput input, long defaultValue) { + return input.getPagination() != null ? input.getPagination().getPage().longValue() : defaultValue; + } + + static long getPageSize(EntityInput input) { + return getPageSize(input, 1); + } + + private static long getPageSize(EntityInput input, long defaultValue) { + return input.getPagination() != null ? input.getPagination().getSize().longValue() : defaultValue; + } + + + public static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List sortorder) { + return setSortOrder(query, sortorder, ""); + } + + private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List sortorder, String prefix) { + if (sortorder != null && sortorder.size() > 0) { + for (Sortorder so : sortorder) { + query.sort((prefix != null ? prefix : "") + so.getProperty(), + so.getSortorder() == SortOrder.Ascending + ? org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING + : org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.DESCENDING); + } + } + return query; + + } + + + public static Sortorder getSortOrder(@Nullable List list, String prop) { + if (list == null) { + return null; + } + for (Sortorder o : list) { + if (prop.equals(o.getProperty())) { + return o; + } + } + return null; + } + + public static Filter getFilter(@Nullable List list, String prop) { + if (list == null) { + return null; + } + for (Filter f : list) { + if (prop.equals(f.getProperty())) { + return f; + } + } + return null; + } + + public static QueryBuilder fromFilter(@Nullable List filters) { + return fromFilter(filters, ""); + } + + private static String fillTimeStamp(String value) { + int idx = value.lastIndexOf("*"); + final String REPLACE = "0000-00-00T00:00:00.0Z"; + String s = value.substring(0, idx) + REPLACE.substring(idx); + if (Integer.parseInt(s.substring(5, 7)) == 0) { + s = s.substring(0, 5) + "01-" + s.substring(8); + } + if (Integer.parseInt(s.substring(8, 10)) == 0) { + s = s.substring(0, 8) + "01" + s.substring(10); + } + + return s; + } + + /** + * convert timestamp with ending placeholder in filter to elasticsearch filter e.g. 2017* => gte: + * 2017-01-01T00:00:00Z, lt:2018-01-01T00:00:00Z + * + * 201* => 2010-01... 2020 .. 2018-* => 2018-01... <=> 2019-01 + * + */ + private static @Nullable QueryBuilder fromTimestampSearchFilter(String property, String value) { + if (!value.endsWith("*")) { + return null; + } + int idx = value.lastIndexOf("*"); + String lowerEnd = fillTimeStamp(value); + String upperEnd = null; + NetconfTimeStamp converter = NetconfTimeStampImpl.getConverter(); + Date dt = null; + try { + dt = converter.getDateFromNetconf(lowerEnd); + } catch (Exception e) { + + } + if (dt == null) { + return null; + } + // property.substring(0,idx)+REPLACE.substring(idx+1); + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + c.setTime(dt); + int tmpvalue; + switch (idx) { + case 1: // (2*) + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1000); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 2: // (20*) + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 100); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 3: // (200*) + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 10); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 4: // (2000*) + case 5: // (2000-*) + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 6: //switch 10 months (2000-0* or 2000-1*) + tmpvalue = c.get(Calendar.MONTH); + if (tmpvalue < 9) { + c.set(Calendar.MONTH, 9); + } else { + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1); + c.set(Calendar.MONTH, 0); + } + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + + break; + case 7: //switch one month (2018-01* or 2018-01-*) + case 8: + c.add(Calendar.MONTH, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 9: // (2018-01-0*) + tmpvalue = c.get(Calendar.DAY_OF_MONTH); + if (tmpvalue == 1) { + c.set(Calendar.DAY_OF_MONTH, 10); + } else if (tmpvalue == 10) { + c.set(Calendar.DAY_OF_MONTH, 20); + } else if (tmpvalue == 20) { + if (c.getActualMaximum(Calendar.DAY_OF_MONTH) < 30) { + c.set(Calendar.DAY_OF_MONTH, 1); + c.add(Calendar.MONTH, 1); + } else { + c.set(Calendar.DAY_OF_MONTH, 30); + } + } else if (tmpvalue == 30) { + c.set(Calendar.DAY_OF_MONTH, 1); + c.add(Calendar.MONTH, 1); + } else { + break; + } + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 10: // (2018-01-01*) + case 11: // (2018-01-01T*) + c.add(Calendar.DAY_OF_MONTH, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 12: // (2018-01-01T1*) + tmpvalue = c.get(Calendar.HOUR_OF_DAY); + if (tmpvalue == 20) { + c.set(Calendar.HOUR_OF_DAY, 0); + c.add(Calendar.DAY_OF_MONTH, 1); + } else { + c.add(Calendar.HOUR_OF_DAY, 10); + } + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 13: // (2018-01-01T11*) + case 14: // (2018-01-01T11-*) + c.add(Calendar.HOUR_OF_DAY, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 15: // (2018-01-01T11-3*) + c.add(Calendar.MINUTE, 10); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 16: // (2018-01-01T11-32*) + case 17: // (2018-01-01T11-32-*) + c.add(Calendar.MINUTE, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 18: // (2018-01-01T11-32-1*) + c.add(Calendar.SECOND, 10); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + case 19: // (2018-01-01T11-32-11*) + case 20: // (2018-01-01T11-32-11.*) + c.add(Calendar.SECOND, 1); + upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); + break; + + default: + break; + } + + if (upperEnd == null) { + return null; + } + return QueryBuilders.rangeQuery(property).gte(lowerEnd).lt(upperEnd); + + } + + private static QueryBuilder fromFilter(@Nullable List filters, String prefix) { + if (filters == null || filters.size() == 0) { + return QueryBuilders.matchAllQuery(); + + } else if (filters.size() == 1) { + QueryBuilder query; + String p = filters.get(0).getProperty(); + String v = filters.get(0).getFiltervalue(); + if ("id".equals(p)) { + p = "_id"; + } else { + // v=v.toLowerCase(); + } + if (DbFilter.hasSearchParams(v)) { + if (p != null && timestampValueNames.contains(p.toLowerCase())) { + query = fromTimestampSearchFilter(p, v); + if (query != null) { + return query; + } + } + return QueryBuilders.regex(p, DbFilter.createDatabaseRegex(v)); + + + } else if (DbFilter.isComparisonValid(v)) { + RangeQueryBuilder q = DbFilter.getRangeQuery((prefix != null ? prefix : "") + p, v); + if (q != null) { + return q; + } else { + return QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v); + } + } else { + return QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v); + } + } else { + BoolQueryBuilder query = new BoolQueryBuilder(); + QueryBuilder tmpQuery; + for (Filter fi : filters) { + String p = fi.getProperty(); + String v = fi.getFiltervalue(); + if ("id".equals(p)) { + p = "_id"; + } else { + // v=v.toLowerCase(); + } + if (DbFilter.hasSearchParams(v)) { + if (p != null && timestampValueNames.contains(p.toLowerCase())) { + tmpQuery = fromTimestampSearchFilter(p, v); + if (tmpQuery != null) { + query.must(tmpQuery); + } else { + query.must(QueryBuilders.regex((prefix != null ? prefix : "") + p, + DbFilter.createDatabaseRegex(v))); + } + } else { + query.must(QueryBuilders.regex((prefix != null ? prefix : "") + p, + DbFilter.createDatabaseRegex(v))); + } + } else if (DbFilter.isComparisonValid(v)) { + RangeQueryBuilder q = DbFilter.getRangeQuery((prefix != null ? prefix : "") + p, v); + if (q != null) { + query.must(q); + } else { + query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v)); + } + } else { + query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v)); + } + } + LOG.trace("Query result. {}", query.toJSON()); + return query; + } + } + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryResult.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryResult.java new file mode 100644 index 000000000..544cd059c --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryResult.java @@ -0,0 +1,66 @@ +/* + * ============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.data.rpctypehelper; + +import java.math.BigInteger; + +import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PaginationOutputG; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.connectionlog.list.output.PaginationBuilder; + +public class QueryResult { + + private SearchResult result; + private PaginationOutputG pagination; + + public QueryResult(long page, long pageSize, SearchResult result) { + this.result = result; + + PaginationBuilder x = new PaginationBuilder(); + x.setPage(BigInteger.valueOf(page)); + x.setSize(pageSize); + x.setTotal(BigInteger.valueOf(result.getTotal())); + pagination = x.build(); + } + + public QueryResult(QueryByFilter queryByFilter, SearchResult result) { + this.result = result; + + PaginationBuilder x = new PaginationBuilder(); + x.setPage(BigInteger.valueOf(queryByFilter.getPage())); + x.setSize(queryByFilter.getPageSize()); + x.setTotal(BigInteger.valueOf(result.getTotal())); + pagination = x.build(); + } + + + public SearchResult getResult() { + return result; + } + + public PaginationOutputG getPagination() { + return pagination; + } + + + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/AboutHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/AboutHttpServlet.java deleted file mode 100644 index fdac1c10a..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/AboutHttpServlet.java +++ /dev/null @@ -1,393 +0,0 @@ -/* - * ============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.http; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.jar.Attributes; -import java.util.jar.Manifest; - -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -//import org.apache.karaf.bundle.core.BundleInfo; -//import org.apache.karaf.bundle.core.BundleService; -import org.onap.ccsdk.features.sdnr.wt.common.Resources; -import org.onap.ccsdk.features.sdnr.wt.common.file.PomFile; -import org.onap.ccsdk.features.sdnr.wt.common.file.PomPropertiesFile; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AboutHttpServlet extends HttpServlet { - - /** - * - */ - private static final long serialVersionUID = 1L; - private static final Logger LOG = LoggerFactory.getLogger(AboutHttpServlet.class); - private static final String UNKNOWN = "unknown"; - private static final String METAINF_MAVEN = "/META-INF/maven/"; - private static final String EXCEPTION_FORMAT_UNABLE_TO_READ_INNER_POMFILE = "unable to read inner pom file: {}"; - - private static final String URI_PRE = "/about"; - private static final String RES_BASEPATH = "about/"; - - private static final String PLACEHOLDER_ONAP_RELEASENAME = "{release-name}"; - private static final String PLACEHOLDER_ONAP_RELEASEVERSION = "{release-version}"; - private static final String PLACEHOLDER_ODL_RELEASENAME = "{odl-version}"; - private static final String PLACEHOLDER_BUILD_TIMESTAMP = "{build-time}"; - private static final String PLACEHOLDER_ODLUX_REVISION = "{odlux-revision}"; - private static final String PLACEHOLDER_PACKAGE_GITHASH = "{package-githash}"; - private static final String PLACEHOLDER_PACAKGE_VERSION = "{package-version}"; - private static final String PLACEHOLDER_CCSDK_VERSION = "{ccsdk-version}"; - private static final String PLACEHOLDER_CLUSTER_SIZE = "{cluster-size}"; - private static final String PLACEHOLDER_MDSAL_VERSION = "{mdsal-version}"; - private static final String PLACEHOLDER_YANGTOOLS_VERSION = "{yangtools-version}"; - private static final String PLACEHOLDER_KARAF_INFO = "{karaf-info}"; - private static final String PLACEHOLDER_DEVICEMANAGER_TABLE = "{devicemanagers}"; - private static final String README_FILE = "README.md"; - - private final String groupId = "org.onap.ccsdk.features.sdnr.wt"; - private final String artifactId = "sdnr-wt-data-provider-provider"; - - private final Map data; - private final String readmeContent; - // private BundleService bundleService; - - - public AboutHttpServlet() { - - this.data = new HashMap<>(); - this.collectStaticData(); - this.readmeContent = this.render(this.getResourceFileContent(README_FILE)); - //BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); - - } - - // public void setBundleService(BundleService bundleService) { - // this.bundleService = bundleService; - // } - - /** - * collect static versioning data - */ - private void collectStaticData() { - PomPropertiesFile props = this.getPomProperties(); - final String ccsdkVersion = this.getPomParentVersion(); - this.data.put(PLACEHOLDER_ONAP_RELEASENAME, ODLVersionLUT.getONAPReleaseName(ccsdkVersion, UNKNOWN)); - this.data.put(PLACEHOLDER_ODL_RELEASENAME, ODLVersionLUT.getOdlVersion(ccsdkVersion, UNKNOWN)); - this.data.put(PLACEHOLDER_BUILD_TIMESTAMP, props != null ? props.getBuildDate().toString() : ""); - this.data.put(PLACEHOLDER_ODLUX_REVISION, this.getPomProperty("odlux.buildno")); - this.data.put(PLACEHOLDER_PACAKGE_VERSION, this.getManifestValue("Bundle-Version")); - this.data.put(PLACEHOLDER_CCSDK_VERSION, ccsdkVersion); - this.data.put(PLACEHOLDER_ONAP_RELEASEVERSION, "2.0.0-SNAPSHOT"); - this.data.put(PLACEHOLDER_MDSAL_VERSION, SystemInfo.getMdSalVersion(UNKNOWN)); - this.data.put(PLACEHOLDER_YANGTOOLS_VERSION, SystemInfo.getYangToolsVersion(UNKNOWN)); - this.data.put(PLACEHOLDER_PACKAGE_GITHASH, this.getGitHash(UNKNOWN)); - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - - String uri = req.getRequestURI().substring(URI_PRE.length()); - LOG.debug("request for {}", uri); - if (uri.length() <= 0 || uri.equals("/")) { - // collect data - this.collectData(); - // render readme - String content = this.render(); - byte[] output = content != null ? content.getBytes() : new byte[0]; - // output - resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentLength(output.length); - resp.setContentType("text/plain"); - ServletOutputStream os = null; - try { - os = resp.getOutputStream(); - os.write(output); - } catch (IOException e) { - LOG.warn("problem writing response for {}: {}", uri, e); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - LOG.warn("problem closing response stream: {}", e); - } - } - } - - } else { - this.doGetFile(uri, resp); - } - } - - /** - * load git.commit.id from jar /META-INF/git.properties - * - * @param def - */ - private String getGitHash(String def) { - String content = Resources.getFileContent(AboutHttpServlet.class, "/META-INF/git.properties"); - if (content == null) { - return def; - } - String lines[] = content.split("\n"); - for (String line : lines) { - if (line.startsWith("git.commit.id")) { - def = line.substring("git.commit.id=".length()); - break; - } - } - return def; - } - - private String getResourceFileContent(String filename) { - LOG.debug("try ti get content of {}", filename); - return Resources.getFileContent(AboutHttpServlet.class, RES_BASEPATH + filename); - } - - /** - * collect dynamic data for about.md - */ - private void collectData() { - LOG.info("collecting dynamic data"); - try { - this.data.put(PLACEHOLDER_KARAF_INFO, SystemInfo.get()); - this.data.put(PLACEHOLDER_DEVICEMANAGER_TABLE, this.getDevicemanagerBundles()); - } catch (Exception e) { - LOG.warn("problem collecting system data: {}", e); - } - } - - /** - * get value for key out of /META-INF/MANIFEST.MF - * - * @param key - * @return - */ - private String getManifestValue(String key) { - URL url = Resources.getUrlForRessource(AboutHttpServlet.class, "/META-INF/MANIFEST.MF"); - if (url == null) { - return null; - } - Manifest manifest; - try { - manifest = new Manifest(url.openStream()); - Attributes attr = manifest.getMainAttributes(); - return attr.getValue(key); - } catch (IOException e) { - LOG.warn("problem reading manifest: {}", e); - } - return null; - - } - - /** - * get object representation of /META-INF/maven/groupId/artifactId/pom.properties - * - * @return - */ - private PomPropertiesFile getPomProperties() { - URL url = Resources.getUrlForRessource(AboutHttpServlet.class, - METAINF_MAVEN + groupId + "/" + artifactId + "/pom.properties"); - PomPropertiesFile propfile; - if (url == null) { - return null; - } - try { - propfile = new PomPropertiesFile(url.openStream()); - return propfile; - } catch (Exception e) { - LOG.warn(EXCEPTION_FORMAT_UNABLE_TO_READ_INNER_POMFILE, e); - } - return null; - } - - /** - * get value for key out of /META-INF/maven/groupId/artifactId/pom.xml in properties section - * - * @param key - * @return - */ - private String getPomProperty(String key) { - LOG.info("try to get pom property for {}", key); - URL url = Resources.getUrlForRessource(AboutHttpServlet.class, - METAINF_MAVEN + groupId + "/" + artifactId + "/pom.xml"); - if (url == null) { - return null; - } - PomFile pomfile; - try { - pomfile = new PomFile(url.openStream()); - return pomfile.getProperty(key); - } catch (Exception e) { - LOG.warn(EXCEPTION_FORMAT_UNABLE_TO_READ_INNER_POMFILE, e); - } - return null; - } - - /** - * get parent pom version out of /META-INF/maven/groupId/artifactId/pom.xml - * - * @return - */ - private String getPomParentVersion() { - LOG.info("try to get pom parent version"); - URL url = Resources.getUrlForRessource(AboutHttpServlet.class, - METAINF_MAVEN + groupId + "/" + artifactId + "/pom.xml"); - if (url == null) { - return null; - } - PomFile pomfile; - try { - pomfile = new PomFile(url.openStream()); - return pomfile.getParentVersion(); - } catch (Exception e) { - LOG.warn(EXCEPTION_FORMAT_UNABLE_TO_READ_INNER_POMFILE, e); - } - return null; - } - - private String getDevicemanagerBundles() { - // if(this.bundleService==null) { - // LOG.debug("no bundle service available"); - // return ""; - // } - // - // List ids = new ArrayList(); - // List bundles = bundleService.selectBundles("0", ids , true); - // if(bundles==null || bundles.size()<=0) { - // LOG.debug("no bundles found"); - // return ""; - // } - // LOG.debug("found {} bundles",bundles.size()); - // MarkdownTable table = new MarkdownTable(); - // for(Bundle bundle:bundles) { - // BundleInfo info = this.bundleService.getInfo(bundle); - // table.addRow(new String[] {String.valueOf(info.getBundleId()),info.getVersion(),info.getName(),info.getState().toString()}); - // } - // return table.toMarkDown(); - return ""; - } - - /** - * get file by uri from resources and write out to response stream - * - * @param uri - * @param resp - */ - private void doGetFile(String uri, HttpServletResponse resp) { - String content = this.getResourceFileContent(uri); - if (content == null) { - try { - resp.sendError(HttpServletResponse.SC_NOT_FOUND); - } catch (IOException e) { - LOG.debug("unable to send error response : {}", e); - } - } else { - byte[] data = content.getBytes(); - resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentType(this.getContentType(uri)); - try { - resp.getOutputStream().write(data); - } catch (IOException e) { - LOG.debug("unable to send data : {}", e); - } - } - - } - - /** - * create http response contentType by filename - * - * @param filename - * @return - */ - private String getContentType(String filename) { - String ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase(); - switch (ext) { - case "jpg": - case "jpeg": - case "svg": - case "png": - case "gif": - case "bmp": - return "image/" + ext; - case "json": - return "application/json"; - case "html": - case "htm": - return "text/html"; - case "txt": - case "md": - default: - return "text/plain"; - } - } - - /** - * render this.readmeContent with this.data - * - * @return - */ - private String render() { - return this.render(null); - } - - /** - * render content with this.data - * - * @param content - * @return - */ - private String render(String content) { - if (content == null) { - content = this.readmeContent; - } - if (content == null) { - return null; - } - for (Entry entry : this.data.entrySet()) { - if (entry.getValue() != null && content.contains(entry.getKey())) { - content = content.replace(entry.getKey(), entry.getValue()); - } - } - - return content; - } - - public void setClusterSize(String value) { - this.data.put(PLACEHOLDER_CLUSTER_SIZE, value); - } -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/GetYangSchemaRequest.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/GetYangSchemaRequest.java deleted file mode 100644 index fd2784804..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/GetYangSchemaRequest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * ============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.http; - -import javax.servlet.http.HttpServletRequest; - -public class GetYangSchemaRequest { - - private static final String URI_PREFIX = "/yang-schema/"; - private final String module; - private final String version; - - public String getModule() { - return this.module; - } - - public String getVersion() { - return this.version; - } - - public boolean hasVersion() { - return this.version != null; - } - - public GetYangSchemaRequest(HttpServletRequest req) throws Exception { - String uri = req.getRequestURI().substring(URI_PREFIX.length()); - - String[] hlp = uri.split("/"); - if (hlp.length < 1) { - throw new Exception("no module request found"); - - } else if (hlp.length == 1) { - this.module = hlp[0]; - this.version = null; - } else { - this.module = hlp[0]; - this.version = hlp[1]; - } - - } - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MarkdownTable.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MarkdownTable.java deleted file mode 100644 index 52eda0cd8..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MarkdownTable.java +++ /dev/null @@ -1,75 +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.List; - -/** - * @author Michael Dürre - * - */ -public class MarkdownTable { - - private String[] columns; - private final List rows; - - public MarkdownTable() { - this.rows = new ArrayList<>(); - } - - public void setHeader(String[] cols) { - this.columns = cols; - } - - public void addRow(String[] values) { - this.rows.add(values); - } - - public String toMarkDown() { - StringBuilder sb = new StringBuilder(); - final int cols = - this.columns != null ? this.columns.length : this.rows.size() > 0 ? this.rows.get(0).length : 0; - if (cols > 0) { - sb.append("|"); - for (int i = 0; i < cols; i++) { - sb.append(String.format(" %s |", this.columns != null ? this.columns[i] : "")); - } - sb.append("\n"); - sb.append("|"); - for (int i = 0; i < cols; i++) { - sb.append(" --- |"); - } - sb.append("\n"); - sb.append("|"); - for (String[] row : this.rows) { - for (int i = 0; i < cols; i++) { - sb.append(String.format(" %s |", row[i])); - } - sb.append("\n"); - } - - - } - return sb.toString(); - } -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ODLVersionLUT.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ODLVersionLUT.java deleted file mode 100644 index 3ea3e3d02..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ODLVersionLUT.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============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.http; - -public class ODLVersionLUT { - - public static String getONAPReleaseName(String onapCCSDKVersion, String def) { - if (onapCCSDKVersion == null) { - return def; - } - if (onapCCSDKVersion.startsWith("2.0.")) { - return "ONAP Guilin"; - } - if (onapCCSDKVersion.startsWith("1.5.")) { - return "ONAP Frankfurt"; - } - if (onapCCSDKVersion.startsWith("1.4.")) { - return "ONAP El Alto"; - } - if (onapCCSDKVersion.startsWith("1.3.")) { - return "ONAP El Alto"; - } - if (onapCCSDKVersion.startsWith("1.2.")) { - return "ONAP Guilin"; - } - return def; - } - - public static String getOdlVersion(String onapCCSDKVersion, String def) { - - if (onapCCSDKVersion == null) { - return def; - } - if (onapCCSDKVersion.startsWith("2.")) { - return "sodium-SR3 (0.11.3)"; - } - if (onapCCSDKVersion.startsWith("1.5.")) { - return "neon-SR1 (0.10.1)"; - } - if (onapCCSDKVersion.startsWith("1.4.")) { - return "neon-SR1 (0.10.1)"; - } - if (onapCCSDKVersion.startsWith("1.3.")) { - return "fluorine-SR2 (0.9.2)"; - } - if (onapCCSDKVersion.startsWith("1.2.")) { - return "sodium-SR3 (0.11.3)"; - } - return def; - } -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/SystemInfo.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/SystemInfo.java deleted file mode 100644 index 12b03ffe6..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/SystemInfo.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * ============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.http; - -import java.io.File; -import java.io.IOException; -import java.lang.management.ClassLoadingMXBean; -import java.lang.management.GarbageCollectorMXBean; -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryMXBean; -import java.lang.management.OperatingSystemMXBean; -import java.lang.management.RuntimeMXBean; -import java.lang.management.ThreadMXBean; -import java.lang.reflect.Method; -import java.nio.file.Files; -import java.nio.file.Path; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; -import java.util.Iterator; -import java.util.Locale; -import java.util.concurrent.Callable; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Stream; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; - -public class SystemInfo { - private static NumberFormat fmtI = new DecimalFormat("###,###", new DecimalFormatSymbols(Locale.ENGLISH)); - private static NumberFormat fmtDec = new DecimalFormat("###,###.##", new DecimalFormatSymbols(Locale.ENGLISH)); - private static NumberFormat fmtD = new DecimalFormat("###,##0.000", new DecimalFormatSymbols(Locale.ENGLISH)); - private static OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); - protected static boolean showMemoryPools = false; - - public static String getMdSalVersion(String def) { - return getMdSalVersion("", def); - } - - public static String getYangToolsVersion(String def) { - return getYangToolsVersion("", def); - } - - public static String getMdSalVersion(String baseOdlDirectory, String def) { - return getFeatureVersionByFolder(baseOdlDirectory, "system/org/opendaylight/mdsal/mdsal-binding-api/", def); - } - - public static String getYangToolsVersion(String baseOdlDirectory, String def) { - return getFeatureVersionByFolder(baseOdlDirectory, "system/org/opendaylight/yangtools/odl-yangtools-common/", - def); - } - - private static String getFeatureVersionByFolder(String baseOdlDirectory, String dir, String def) { - final String regex = "^[0-9]+\\.[0-9]+\\.[0-9]+(-SNAPSHOT)?$"; - Stream entries = null; - try { - if (baseOdlDirectory != null && baseOdlDirectory.length() > 0 && !baseOdlDirectory.endsWith("/")) { - baseOdlDirectory += "/"; - } - entries = Files.list(new File(baseOdlDirectory + dir).toPath()); - } catch (IOException e) { - - } - if (entries == null) { - return def; - } - final Pattern pattern = Pattern.compile(regex); - - Iterator it = entries.iterator(); - Path p; - File f; - while (it.hasNext()) { - p = it.next(); - f = p.toFile(); - if (f.isDirectory()) { - final Matcher matcher = pattern.matcher(f.getName().toString()); - if (matcher.find()) { - def = matcher.group(0); - break; - } - } - } - entries.close(); - return def; - } - - public static String get() throws Exception { - StringBuilder sb = new StringBuilder(); - int maxNameLen; - - RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); - ThreadMXBean threads = ManagementFactory.getThreadMXBean(); - MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); - ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean(); - - // - // print Karaf informations - // - maxNameLen = 25; - sb.append("Karaf\n"); - printValue(sb, "Karaf version", maxNameLen, System.getProperty("karaf.version")); - printValue(sb, "Karaf home", maxNameLen, System.getProperty("karaf.home")); - printValue(sb, "Karaf base", maxNameLen, System.getProperty("karaf.base")); - String osgi = getOsgiFramework(); - if (osgi != null) { - printValue(sb, "OSGi Framework", maxNameLen, osgi); - } - - sb.append("JVM\n"); - printValue(sb, "Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion()); - printValue(sb, "Version", maxNameLen, System.getProperty("java.version")); - printValue(sb, "Vendor", maxNameLen, runtime.getVmVendor()); - printValue(sb, "Pid", maxNameLen, getPid()); - printValue(sb, "Uptime", maxNameLen, printDuration(runtime.getUptime())); - try { - Class sunOS = Class.forName("com.sun.management.OperatingSystemMXBean"); - printValue(sb, "Process CPU time", maxNameLen, - printDuration(getValueAsLong(sunOS, "getProcessCpuTime") / 1000000.0)); - printValue(sb, "Process CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS, "getProcessCpuLoad"))); - printValue(sb, "System CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS, "getSystemCpuLoad"))); - } catch (Throwable t) { - } - try { - Class unixOS = Class.forName("com.sun.management.UnixOperatingSystemMXBean"); - printValue(sb, "Open file descriptors", maxNameLen, - printLong(getValueAsLong(unixOS, "getOpenFileDescriptorCount"))); - printValue(sb, "Max file descriptors", maxNameLen, - printLong(getValueAsLong(unixOS, "getMaxFileDescriptorCount"))); - } catch (Throwable t) { - } - printValue(sb, "Total compile time", maxNameLen, - printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime())); - - sb.append("Threads\n"); - printValue(sb, "Live threads", maxNameLen, Integer.toString(threads.getThreadCount())); - printValue(sb, "Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount())); - printValue(sb, "Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount())); - printValue(sb, "Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount())); - - sb.append("Memory\n"); - printValue(sb, "Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed())); - printValue(sb, "Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax())); - printValue(sb, "Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted())); - printValue(sb, "Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount())); - for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { - String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount() + ", Time = " - + printDuration(gc.getCollectionTime()); - printValue(sb, "Garbage collector", maxNameLen, val); - } - - // if (showMemoryPools) { - // List memoryPools = ManagementFactory.getMemoryPoolMXBeans(); - // sb.append("Memory Pools\n"); - // printValue(sb, "Total Memory Pools", maxNameLen, printLong(memoryPools.size())); - // String spaces4 = " "; - // for (MemoryPoolMXBean pool : memoryPools) { - // String name = pool.getName(); - // MemoryType type = pool.getType(); - // printValue(sb, spaces4 + "Pool (" + type + ")", maxNameLen, name); - // - // // PeakUsage/CurrentUsage - // MemoryUsage peakUsage = pool.getPeakUsage(); - // MemoryUsage usage = pool.getUsage(); - // - // if (usage != null && peakUsage != null) { - // long init = peakUsage.getInit(); - // long used = peakUsage.getUsed(); - // long committed = peakUsage.getCommitted(); - // long max = peakUsage.getMax(); - // sb.append(spaces4 + spaces4 + "Peak Usage\n"); - // printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init)); - // printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used)); - // printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed)); - // printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max)); - // - // init = usage.getInit(); - // used = usage.getUsed(); - // committed = usage.getCommitted(); - // max = usage.getMax(); - // sb.append(spaces4 + spaces4 + "Current Usage\n"); - // printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init)); - // printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used)); - // printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed)); - // printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max)); - // } - // } - // } - - sb.append("Classes\n"); - printValue(sb, "Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount())); - printValue(sb, "Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount())); - printValue(sb, "Total classes unloaded", maxNameLen, printLong(cl.getUnloadedClassCount())); - - sb.append("Operating system\n"); - printValue(sb, "Name", maxNameLen, os.getName() + " version " + os.getVersion()); - printValue(sb, "Architecture", maxNameLen, os.getArch()); - printValue(sb, "Processors", maxNameLen, Integer.toString(os.getAvailableProcessors())); - try { - printValue(sb, "Total physical memory", maxNameLen, - printSizeInKb(getSunOsValueAsLong(os, "getTotalPhysicalMemorySize"))); - printValue(sb, "Free physical memory", maxNameLen, - printSizeInKb(getSunOsValueAsLong(os, "getFreePhysicalMemorySize"))); - printValue(sb, "Committed virtual memory", maxNameLen, - printSizeInKb(getSunOsValueAsLong(os, "getCommittedVirtualMemorySize"))); - printValue(sb, "Total swap space", maxNameLen, - printSizeInKb(getSunOsValueAsLong(os, "getTotalSwapSpaceSize"))); - printValue(sb, "Free swap space", maxNameLen, - printSizeInKb(getSunOsValueAsLong(os, "getFreeSwapSpaceSize"))); - } catch (Throwable t) { - } - return sb.toString(); - } - - private static String getPid() { - // In Java 9 the new process API can be used: - // long pid = ProcessHandle.current().getPid(); - String name = ManagementFactory.getRuntimeMXBean().getName(); - String[] parts = name.split("@"); - return parts[0]; - } - - private static long getSunOsValueAsLong(OperatingSystemMXBean os, String name) throws Exception { - Method mth = os.getClass().getMethod(name); - return (Long) mth.invoke(os); - } - - private static long getValueAsLong(Class osImpl, String name) throws Exception { - if (osImpl.isInstance(os)) { - Method mth = osImpl.getMethod(name); - return (Long) mth.invoke(os); - } - return -1; - } - - private static double getValueAsDouble(Class osImpl, String name) throws Exception { - if (osImpl.isInstance(os)) { - Method mth = osImpl.getMethod(name); - return (Double) mth.invoke(os); - } - return -1; - } - - private static String printLong(long i) { - return fmtI.format(i); - } - - private static String printSizeInKb(double size) { - return fmtI.format((long) (size / 1024)) + " kbytes"; - } - - protected static String printDuration(double uptime) { - uptime /= 1000; - if (uptime < 60) { - return fmtD.format(uptime) + " seconds"; - } - uptime /= 60; - if (uptime < 60) { - long minutes = (long) uptime; - String s = fmtI.format(minutes) + (minutes > 1 ? " minutes" : " minute"); - return s; - } - uptime /= 60; - if (uptime < 24) { - long hours = (long) uptime; - long minutes = (long) ((uptime - hours) * 60); - String s = fmtI.format(hours) + (hours > 1 ? " hours" : " hour"); - if (minutes != 0) { - s += " " + fmtI.format(minutes) + (minutes > 1 ? " minutes" : " minute"); - } - return s; - } - uptime /= 24; - long days = (long) uptime; - long hours = (long) ((uptime - days) * 24); - String s = fmtI.format(days) + (days > 1 ? " days" : " day"); - if (hours != 0) { - s += " " + fmtI.format(hours) + (hours > 1 ? " hours" : " hour"); - } - return s; - } - - static void printSysValue(StringBuilder sb, String prop, int pad) { - printValue(sb, prop, pad, System.getProperty(prop)); - } - - static void printValue(StringBuilder sb, String name, int pad, String value) { - sb.append(" " + // SimpleAnsi.INTENSITY_BOLD + - name + // SimpleAnsi.INTENSITY_NORMAL + - spaces(pad - name.length()) + " " + value + "\n"); - } - - static String spaces(int nb) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < nb; i++) { - sb.append(' '); - } - return sb.toString(); - } - - static String getOsgiFramework() { - try { - Callable call = new Callable() { - @Override - public String call() throws Exception { - BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); - Bundle sysBundle = context.getBundle(0); - return sysBundle.getSymbolicName() + "-" + sysBundle.getVersion(); - } - }; - return call.call(); - } catch (Throwable t) { - // We're not in OSGi, just safely return null - return null; - } - } -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/YangSchemaHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/YangSchemaHttpServlet.java deleted file mode 100644 index 48862a6a5..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/YangSchemaHttpServlet.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * ============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.http; - -import java.io.IOException; -import java.text.ParseException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.YangFileProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class YangSchemaHttpServlet extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 1L; - private static final Logger LOG = LoggerFactory.getLogger(YangSchemaHttpServlet.class); - - private static final String schemaCachePath = "cache/schema/"; - - private final YangFileProvider fileProvider; - - public YangSchemaHttpServlet() { - this.fileProvider = new YangFileProvider(schemaCachePath); - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - - GetYangSchemaRequest request = null; - try { - request = new GetYangSchemaRequest(req); - } catch (Exception e) { - LOG.warn("bad request for yang-schema: {}", e); - } - if (request != null) { - int len; - LOG.debug("request for yang-schema for module {} with version {}", request.getModule(), - request.getVersion()); - if (request.hasVersion()) { - boolean has = false; - try { - has = this.fileProvider.hasFileOrNewerForModule(request.getModule(), request.getVersion()); - } catch (ParseException e1) { - LOG.warn("unable to parse revision: {}", e1); - } - if (has) { - - try { - resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentType("text/plain"); - len = this.fileProvider.writeOutput(request.getModule(), request.getVersion(), - resp.getOutputStream()); - resp.setContentLength(len); - - } catch (ParseException e) { - LOG.warn("unable to parse revision: {}", e); - } catch (IOException | IllegalStateException e) { - LOG.warn("unable to write out module {}@{}: {}", request.getModule(), request.getVersion(), e); - } - } else { - try { - resp.sendError(HttpServletResponse.SC_NOT_FOUND); - } catch (IOException | IllegalStateException e) { - LOG.warn("unable to write out 404 res not found: {}", e); - } - } - - } else if (this.fileProvider.hasFileForModule(request.getModule())) { - - try { - resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentType("text/plain"); - len = this.fileProvider.writeOutput(request.getModule(), null, resp.getOutputStream()); - resp.setContentLength(len); - } catch (ParseException e) { - LOG.warn(e.getMessage()); - } catch (IOException | IllegalStateException e) { - LOG.warn("unable to write out module {}: {}", request.getModule(), e); - } - - } else { - try { - resp.sendError(HttpServletResponse.SC_NOT_FOUND); - } catch (IOException | IllegalStateException e) { - LOG.warn("unable to write out 404 res not found: {}", e); - } - } - } else { - try { - resp.sendError(HttpServletResponse.SC_BAD_REQUEST); - } catch (IOException | IllegalStateException e) { - LOG.warn("unable to write out 400 bad request: {}", e); - } - } - - } - -} 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 new file mode 100644 index 000000000..9ac0cc0c3 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java @@ -0,0 +1,385 @@ +/* + * ============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.http.about; + +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.jar.Attributes; +import java.util.jar.Manifest; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +//import org.apache.karaf.bundle.core.BundleInfo; +//import org.apache.karaf.bundle.core.BundleService; +import org.onap.ccsdk.features.sdnr.wt.common.Resources; +import org.onap.ccsdk.features.sdnr.wt.common.file.PomFile; +import org.onap.ccsdk.features.sdnr.wt.common.file.PomPropertiesFile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AboutHttpServlet extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = 1L; + private static final Logger LOG = LoggerFactory.getLogger(AboutHttpServlet.class); + private static final String UNKNOWN = "unknown"; + private static final String METAINF_MAVEN = "/META-INF/maven/"; + private static final String EXCEPTION_FORMAT_UNABLE_TO_READ_INNER_POMFILE = "unable to read inner pom file: {}"; + + private static final String URI_PRE = "/about"; + private static final String RES_BASEPATH = "about/"; + + private static final String PLACEHOLDER_ONAP_RELEASENAME = "{release-name}"; + private static final String PLACEHOLDER_ONAP_RELEASEVERSION = "{release-version}"; + private static final String PLACEHOLDER_ODL_RELEASENAME = "{odl-version}"; + private static final String PLACEHOLDER_BUILD_TIMESTAMP = "{build-time}"; + private static final String PLACEHOLDER_ODLUX_REVISION = "{odlux-revision}"; + private static final String PLACEHOLDER_PACKAGE_GITHASH = "{package-githash}"; + private static final String PLACEHOLDER_PACAKGE_VERSION = "{package-version}"; + private static final String PLACEHOLDER_CCSDK_VERSION = "{ccsdk-version}"; + private static final String PLACEHOLDER_CLUSTER_SIZE = "{cluster-size}"; + private static final String PLACEHOLDER_MDSAL_VERSION = "{mdsal-version}"; + private static final String PLACEHOLDER_YANGTOOLS_VERSION = "{yangtools-version}"; + private static final String PLACEHOLDER_KARAF_INFO = "{karaf-info}"; + private static final String PLACEHOLDER_DEVICEMANAGER_TABLE = "{devicemanagers}"; + private static final String README_FILE = "README.md"; + + private final String groupId = "org.onap.ccsdk.features.sdnr.wt"; + private final String artifactId = "sdnr-wt-data-provider-provider"; + + private final Map data; + private final String readmeContent; + // private BundleService bundleService; + + + public AboutHttpServlet() { + + this.data = new HashMap<>(); + this.collectStaticData(); + this.readmeContent = this.render(this.getResourceFileContent(README_FILE)); + //BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); + + } + + // public void setBundleService(BundleService bundleService) { + // this.bundleService = bundleService; + // } + + /** + * collect static versioning data + */ + private void collectStaticData() { + PomPropertiesFile props = this.getPomProperties(); + final String ccsdkVersion = this.getPomParentVersion(); + this.data.put(PLACEHOLDER_ONAP_RELEASENAME, ODLVersionLUT.getONAPReleaseName(ccsdkVersion, UNKNOWN)); + this.data.put(PLACEHOLDER_ODL_RELEASENAME, ODLVersionLUT.getOdlVersion(ccsdkVersion, UNKNOWN)); + this.data.put(PLACEHOLDER_BUILD_TIMESTAMP, props != null ? props.getBuildDate().toString() : ""); + this.data.put(PLACEHOLDER_PACAKGE_VERSION, this.getManifestValue("Bundle-Version")); + this.data.put(PLACEHOLDER_CCSDK_VERSION, ccsdkVersion); + this.data.put(PLACEHOLDER_ONAP_RELEASEVERSION, "2.0.0-SNAPSHOT"); + this.data.put(PLACEHOLDER_MDSAL_VERSION, SystemInfo.getMdSalVersion(UNKNOWN)); + this.data.put(PLACEHOLDER_YANGTOOLS_VERSION, SystemInfo.getYangToolsVersion(UNKNOWN)); + this.data.put(PLACEHOLDER_PACKAGE_GITHASH, this.getGitHash(UNKNOWN)); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + String uri = req.getRequestURI().substring(URI_PRE.length()); + LOG.debug("request for {}", uri); + if (uri.length() <= 0 || uri.equals("/")) { + // collect data + this.collectData(); + // render readme + String content = this.render(); + byte[] output = content != null ? content.getBytes() : new byte[0]; + // output + resp.setStatus(HttpServletResponse.SC_OK); + resp.setContentLength(output.length); + resp.setContentType("text/plain"); + ServletOutputStream os = null; + try { + os = resp.getOutputStream(); + os.write(output); + } catch (IOException e) { + LOG.warn("problem writing response for {}: {}", uri, e); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + LOG.warn("problem closing response stream: {}", e); + } + } + } + + } else { + this.doGetFile(uri, resp); + } + } + + /** + * load git.commit.id from jar /META-INF/git.properties + * + * @param def + */ + private String getGitHash(String def) { + String content = Resources.getFileContent(AboutHttpServlet.class, "/META-INF/git.properties"); + if (content == null) { + return def; + } + String lines[] = content.split("\n"); + for (String line : lines) { + if (line.startsWith("git.commit.id")) { + def = line.substring("git.commit.id=".length()); + break; + } + } + return def; + } + + private String getResourceFileContent(String filename) { + LOG.debug("try ti get content of {}", filename); + return Resources.getFileContent(AboutHttpServlet.class, RES_BASEPATH + filename); + } + + /** + * collect dynamic data for about.md + */ + private void collectData() { + LOG.info("collecting dynamic data"); + try { + this.data.put(PLACEHOLDER_KARAF_INFO, SystemInfo.get()); + this.data.put(PLACEHOLDER_DEVICEMANAGER_TABLE, this.getDevicemanagerBundles()); + } catch (Exception e) { + LOG.warn("problem collecting system data: {}", e); + } + } + + /** + * get value for key out of /META-INF/MANIFEST.MF + * + * @param key + * @return + */ + private String getManifestValue(String key) { + URL url = Resources.getUrlForRessource(AboutHttpServlet.class, "/META-INF/MANIFEST.MF"); + if (url == null) { + return null; + } + Manifest manifest; + try { + manifest = new Manifest(url.openStream()); + Attributes attr = manifest.getMainAttributes(); + return attr.getValue(key); + } catch (IOException e) { + LOG.warn("problem reading manifest: {}", e); + } + return null; + + } + + /** + * get object representation of /META-INF/maven/groupId/artifactId/pom.properties + * + * @return + */ + private PomPropertiesFile getPomProperties() { + URL url = Resources.getUrlForRessource(AboutHttpServlet.class, + METAINF_MAVEN + groupId + "/" + artifactId + "/pom.properties"); + PomPropertiesFile propfile; + if (url == null) { + return null; + } + try { + propfile = new PomPropertiesFile(url.openStream()); + return propfile; + } catch (Exception e) { + LOG.warn(EXCEPTION_FORMAT_UNABLE_TO_READ_INNER_POMFILE, e); + } + return null; + } + + /** + * get value for key out of /META-INF/maven/groupId/artifactId/pom.xml in properties section + * + * @param key + * @return + */ + private String getPomProperty(String key) { + LOG.info("try to get pom property for {}", key); + URL url = Resources.getUrlForRessource(AboutHttpServlet.class, + METAINF_MAVEN + groupId + "/" + artifactId + "/pom.xml"); + if (url == null) { + return null; + } + PomFile pomfile; + try { + pomfile = new PomFile(url.openStream()); + return pomfile.getProperty(key); + } catch (Exception e) { + LOG.warn(EXCEPTION_FORMAT_UNABLE_TO_READ_INNER_POMFILE, e); + } + return null; + } + + /** + * get parent pom version out of /META-INF/maven/groupId/artifactId/pom.xml + * + * @return + */ + private String getPomParentVersion() { + LOG.info("try to get pom parent version"); + URL url = Resources.getUrlForRessource(AboutHttpServlet.class, + METAINF_MAVEN + groupId + "/" + artifactId + "/pom.xml"); + if (url == null) { + return null; + } + PomFile pomfile; + try { + pomfile = new PomFile(url.openStream()); + return pomfile.getParentVersion(); + } catch (Exception e) { + LOG.warn(EXCEPTION_FORMAT_UNABLE_TO_READ_INNER_POMFILE, e); + } + return null; + } + + private String getDevicemanagerBundles() { + // if(this.bundleService==null) { + // LOG.debug("no bundle service available"); + // return ""; + // } + // + // List ids = new ArrayList(); + // List bundles = bundleService.selectBundles("0", ids , true); + // if(bundles==null || bundles.size()<=0) { + // LOG.debug("no bundles found"); + // return ""; + // } + // LOG.debug("found {} bundles",bundles.size()); + // MarkdownTable table = new MarkdownTable(); + // for(Bundle bundle:bundles) { + // BundleInfo info = this.bundleService.getInfo(bundle); + // table.addRow(new String[] {String.valueOf(info.getBundleId()),info.getVersion(),info.getName(),info.getState().toString()}); + // } + // return table.toMarkDown(); + return ""; + } + + /** + * get file by uri from resources and write out to response stream + * + * @param uri + * @param resp + */ + private void doGetFile(String uri, HttpServletResponse resp) { + String content = this.getResourceFileContent(uri); + if (content == null) { + try { + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + } catch (IOException e) { + LOG.debug("unable to send error response : {}", e); + } + } else { + byte[] data = content.getBytes(); + resp.setStatus(HttpServletResponse.SC_OK); + resp.setContentType(this.getContentType(uri)); + try { + resp.getOutputStream().write(data); + } catch (IOException e) { + LOG.debug("unable to send data : {}", e); + } + } + + } + + /** + * create http response contentType by filename + * + * @param filename + * @return + */ + private String getContentType(String filename) { + String ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase(); + switch (ext) { + case "jpg": + case "jpeg": + case "svg": + case "png": + case "gif": + case "bmp": + return "image/" + ext; + case "json": + return "application/json"; + case "html": + case "htm": + return "text/html"; + case "txt": + case "md": + default: + return "text/plain"; + } + } + + /** + * render this.readmeContent with this.data + * + * @return + */ + private String render() { + return this.render(null); + } + + /** + * render content with this.data + * + * @param content + * @return + */ + private String render(String content) { + if (content == null) { + content = this.readmeContent; + } + if (content == null) { + return null; + } + for (Entry entry : this.data.entrySet()) { + if (entry.getValue() != null && content.contains(entry.getKey())) { + content = content.replace(entry.getKey(), entry.getValue()); + } + } + + return content; + } + + public void setClusterSize(String value) { + this.data.put(PLACEHOLDER_CLUSTER_SIZE, value); + } +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java new file mode 100644 index 000000000..9fd6975b6 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/MarkdownTable.java @@ -0,0 +1,75 @@ +/* + * ============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.about; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Michael Dürre + * + */ +public class MarkdownTable { + + private String[] columns; + private final List rows; + + public MarkdownTable() { + this.rows = new ArrayList<>(); + } + + public void setHeader(String[] cols) { + this.columns = cols; + } + + public void addRow(String[] values) { + this.rows.add(values); + } + + public String toMarkDown() { + StringBuilder sb = new StringBuilder(); + final int cols = + this.columns != null ? this.columns.length : this.rows.size() > 0 ? this.rows.get(0).length : 0; + if (cols > 0) { + sb.append("|"); + for (int i = 0; i < cols; i++) { + sb.append(String.format(" %s |", this.columns != null ? this.columns[i] : "")); + } + sb.append("\n"); + sb.append("|"); + for (int i = 0; i < cols; i++) { + sb.append(" --- |"); + } + sb.append("\n"); + sb.append("|"); + for (String[] row : this.rows) { + for (int i = 0; i < cols; i++) { + sb.append(String.format(" %s |", row[i])); + } + sb.append("\n"); + } + + + } + return sb.toString(); + } +} 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 new file mode 100644 index 000000000..bd8fae6a0 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java @@ -0,0 +1,70 @@ +/* + * ============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.http.about; + +public class ODLVersionLUT { + + public static String getONAPReleaseName(String onapCCSDKVersion, String def) { + if (onapCCSDKVersion == null) { + return def; + } + if (onapCCSDKVersion.startsWith("2.0.")) { + return "ONAP Guilin"; + } + if (onapCCSDKVersion.startsWith("1.5.")) { + return "ONAP Frankfurt"; + } + if (onapCCSDKVersion.startsWith("1.4.")) { + return "ONAP El Alto"; + } + if (onapCCSDKVersion.startsWith("1.3.")) { + return "ONAP El Alto"; + } + if (onapCCSDKVersion.startsWith("1.2.")) { + return "ONAP Guilin"; + } + return def; + } + + public static String getOdlVersion(String onapCCSDKVersion, String def) { + + if (onapCCSDKVersion == null) { + return def; + } + if (onapCCSDKVersion.startsWith("2.")) { + return "sodium-SR3 (0.11.3)"; + } + if (onapCCSDKVersion.startsWith("1.5.")) { + return "neon-SR1 (0.10.1)"; + } + if (onapCCSDKVersion.startsWith("1.4.")) { + return "neon-SR1 (0.10.1)"; + } + if (onapCCSDKVersion.startsWith("1.3.")) { + return "fluorine-SR2 (0.9.2)"; + } + if (onapCCSDKVersion.startsWith("1.2.")) { + return "sodium-SR3 (0.11.3)"; + } + return def; + } +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java new file mode 100644 index 000000000..1497362a6 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java @@ -0,0 +1,337 @@ +/* + * ============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.http.about; + +import java.io.File; +import java.io.IOException; +import java.lang.management.ClassLoadingMXBean; +import java.lang.management.GarbageCollectorMXBean; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.lang.management.OperatingSystemMXBean; +import java.lang.management.RuntimeMXBean; +import java.lang.management.ThreadMXBean; +import java.lang.reflect.Method; +import java.nio.file.Files; +import java.nio.file.Path; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.NumberFormat; +import java.util.Iterator; +import java.util.Locale; +import java.util.concurrent.Callable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; + +public class SystemInfo { + private static NumberFormat fmtI = new DecimalFormat("###,###", new DecimalFormatSymbols(Locale.ENGLISH)); + private static NumberFormat fmtDec = new DecimalFormat("###,###.##", new DecimalFormatSymbols(Locale.ENGLISH)); + private static NumberFormat fmtD = new DecimalFormat("###,##0.000", new DecimalFormatSymbols(Locale.ENGLISH)); + private static OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); + protected static boolean showMemoryPools = false; + + public static String getMdSalVersion(String def) { + return getMdSalVersion("", def); + } + + public static String getYangToolsVersion(String def) { + return getYangToolsVersion("", def); + } + + public static String getMdSalVersion(String baseOdlDirectory, String def) { + return getFeatureVersionByFolder(baseOdlDirectory, "system/org/opendaylight/mdsal/mdsal-binding-api/", def); + } + + public static String getYangToolsVersion(String baseOdlDirectory, String def) { + return getFeatureVersionByFolder(baseOdlDirectory, "system/org/opendaylight/yangtools/odl-yangtools-common/", + def); + } + + private static String getFeatureVersionByFolder(String baseOdlDirectory, String dir, String def) { + final String regex = "^[0-9]+\\.[0-9]+\\.[0-9]+(-SNAPSHOT)?$"; + Stream entries = null; + try { + if (baseOdlDirectory != null && baseOdlDirectory.length() > 0 && !baseOdlDirectory.endsWith("/")) { + baseOdlDirectory += "/"; + } + entries = Files.list(new File(baseOdlDirectory + dir).toPath()); + } catch (IOException e) { + + } + if (entries == null) { + return def; + } + final Pattern pattern = Pattern.compile(regex); + + Iterator it = entries.iterator(); + Path p; + File f; + while (it.hasNext()) { + p = it.next(); + f = p.toFile(); + if (f.isDirectory()) { + final Matcher matcher = pattern.matcher(f.getName().toString()); + if (matcher.find()) { + def = matcher.group(0); + break; + } + } + } + entries.close(); + return def; + } + + public static String get() throws Exception { + StringBuilder sb = new StringBuilder(); + int maxNameLen; + + RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); + ThreadMXBean threads = ManagementFactory.getThreadMXBean(); + MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); + ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean(); + + // + // print Karaf informations + // + maxNameLen = 25; + sb.append("Karaf\n"); + printValue(sb, "Karaf version", maxNameLen, System.getProperty("karaf.version")); + printValue(sb, "Karaf home", maxNameLen, System.getProperty("karaf.home")); + printValue(sb, "Karaf base", maxNameLen, System.getProperty("karaf.base")); + String osgi = getOsgiFramework(); + if (osgi != null) { + printValue(sb, "OSGi Framework", maxNameLen, osgi); + } + + sb.append("JVM\n"); + printValue(sb, "Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion()); + printValue(sb, "Version", maxNameLen, System.getProperty("java.version")); + printValue(sb, "Vendor", maxNameLen, runtime.getVmVendor()); + printValue(sb, "Pid", maxNameLen, getPid()); + printValue(sb, "Uptime", maxNameLen, printDuration(runtime.getUptime())); + try { + Class sunOS = Class.forName("com.sun.management.OperatingSystemMXBean"); + printValue(sb, "Process CPU time", maxNameLen, + printDuration(getValueAsLong(sunOS, "getProcessCpuTime") / 1000000.0)); + printValue(sb, "Process CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS, "getProcessCpuLoad"))); + printValue(sb, "System CPU load", maxNameLen, fmtDec.format(getValueAsDouble(sunOS, "getSystemCpuLoad"))); + } catch (Throwable t) { + } + try { + Class unixOS = Class.forName("com.sun.management.UnixOperatingSystemMXBean"); + printValue(sb, "Open file descriptors", maxNameLen, + printLong(getValueAsLong(unixOS, "getOpenFileDescriptorCount"))); + printValue(sb, "Max file descriptors", maxNameLen, + printLong(getValueAsLong(unixOS, "getMaxFileDescriptorCount"))); + } catch (Throwable t) { + } + printValue(sb, "Total compile time", maxNameLen, + printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime())); + + sb.append("Threads\n"); + printValue(sb, "Live threads", maxNameLen, Integer.toString(threads.getThreadCount())); + printValue(sb, "Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount())); + printValue(sb, "Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount())); + printValue(sb, "Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount())); + + sb.append("Memory\n"); + printValue(sb, "Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed())); + printValue(sb, "Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax())); + printValue(sb, "Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted())); + printValue(sb, "Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount())); + for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) { + String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount() + ", Time = " + + printDuration(gc.getCollectionTime()); + printValue(sb, "Garbage collector", maxNameLen, val); + } + + // if (showMemoryPools) { + // List memoryPools = ManagementFactory.getMemoryPoolMXBeans(); + // sb.append("Memory Pools\n"); + // printValue(sb, "Total Memory Pools", maxNameLen, printLong(memoryPools.size())); + // String spaces4 = " "; + // for (MemoryPoolMXBean pool : memoryPools) { + // String name = pool.getName(); + // MemoryType type = pool.getType(); + // printValue(sb, spaces4 + "Pool (" + type + ")", maxNameLen, name); + // + // // PeakUsage/CurrentUsage + // MemoryUsage peakUsage = pool.getPeakUsage(); + // MemoryUsage usage = pool.getUsage(); + // + // if (usage != null && peakUsage != null) { + // long init = peakUsage.getInit(); + // long used = peakUsage.getUsed(); + // long committed = peakUsage.getCommitted(); + // long max = peakUsage.getMax(); + // sb.append(spaces4 + spaces4 + "Peak Usage\n"); + // printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init)); + // printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used)); + // printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed)); + // printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max)); + // + // init = usage.getInit(); + // used = usage.getUsed(); + // committed = usage.getCommitted(); + // max = usage.getMax(); + // sb.append(spaces4 + spaces4 + "Current Usage\n"); + // printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init)); + // printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used)); + // printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed)); + // printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max)); + // } + // } + // } + + sb.append("Classes\n"); + printValue(sb, "Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount())); + printValue(sb, "Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount())); + printValue(sb, "Total classes unloaded", maxNameLen, printLong(cl.getUnloadedClassCount())); + + sb.append("Operating system\n"); + printValue(sb, "Name", maxNameLen, os.getName() + " version " + os.getVersion()); + printValue(sb, "Architecture", maxNameLen, os.getArch()); + printValue(sb, "Processors", maxNameLen, Integer.toString(os.getAvailableProcessors())); + try { + printValue(sb, "Total physical memory", maxNameLen, + printSizeInKb(getSunOsValueAsLong(os, "getTotalPhysicalMemorySize"))); + printValue(sb, "Free physical memory", maxNameLen, + printSizeInKb(getSunOsValueAsLong(os, "getFreePhysicalMemorySize"))); + printValue(sb, "Committed virtual memory", maxNameLen, + printSizeInKb(getSunOsValueAsLong(os, "getCommittedVirtualMemorySize"))); + printValue(sb, "Total swap space", maxNameLen, + printSizeInKb(getSunOsValueAsLong(os, "getTotalSwapSpaceSize"))); + printValue(sb, "Free swap space", maxNameLen, + printSizeInKb(getSunOsValueAsLong(os, "getFreeSwapSpaceSize"))); + } catch (Throwable t) { + } + return sb.toString(); + } + + private static String getPid() { + // In Java 9 the new process API can be used: + // long pid = ProcessHandle.current().getPid(); + String name = ManagementFactory.getRuntimeMXBean().getName(); + String[] parts = name.split("@"); + return parts[0]; + } + + private static long getSunOsValueAsLong(OperatingSystemMXBean os, String name) throws Exception { + Method mth = os.getClass().getMethod(name); + return (Long) mth.invoke(os); + } + + private static long getValueAsLong(Class osImpl, String name) throws Exception { + if (osImpl.isInstance(os)) { + Method mth = osImpl.getMethod(name); + return (Long) mth.invoke(os); + } + return -1; + } + + private static double getValueAsDouble(Class osImpl, String name) throws Exception { + if (osImpl.isInstance(os)) { + Method mth = osImpl.getMethod(name); + return (Double) mth.invoke(os); + } + return -1; + } + + private static String printLong(long i) { + return fmtI.format(i); + } + + private static String printSizeInKb(double size) { + return fmtI.format((long) (size / 1024)) + " kbytes"; + } + + protected static String printDuration(double uptime) { + uptime /= 1000; + if (uptime < 60) { + return fmtD.format(uptime) + " seconds"; + } + uptime /= 60; + if (uptime < 60) { + long minutes = (long) uptime; + String s = fmtI.format(minutes) + (minutes > 1 ? " minutes" : " minute"); + return s; + } + uptime /= 60; + if (uptime < 24) { + long hours = (long) uptime; + long minutes = (long) ((uptime - hours) * 60); + String s = fmtI.format(hours) + (hours > 1 ? " hours" : " hour"); + if (minutes != 0) { + s += " " + fmtI.format(minutes) + (minutes > 1 ? " minutes" : " minute"); + } + return s; + } + uptime /= 24; + long days = (long) uptime; + long hours = (long) ((uptime - days) * 24); + String s = fmtI.format(days) + (days > 1 ? " days" : " day"); + if (hours != 0) { + s += " " + fmtI.format(hours) + (hours > 1 ? " hours" : " hour"); + } + return s; + } + + static void printSysValue(StringBuilder sb, String prop, int pad) { + printValue(sb, prop, pad, System.getProperty(prop)); + } + + static void printValue(StringBuilder sb, String name, int pad, String value) { + sb.append(" " + // SimpleAnsi.INTENSITY_BOLD + + name + // SimpleAnsi.INTENSITY_NORMAL + + spaces(pad - name.length()) + " " + value + "\n"); + } + + static String spaces(int nb) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < nb; i++) { + sb.append(' '); + } + return sb.toString(); + } + + static String getOsgiFramework() { + try { + Callable call = new Callable() { + @Override + public String call() throws Exception { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + Bundle sysBundle = context.getBundle(0); + return sysBundle.getSymbolicName() + "-" + sysBundle.getVersion(); + } + }; + return call.call(); + } catch (Throwable t) { + // We're not in OSGi, just safely return null + return null; + } + } +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/GetYangSchemaRequest.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/GetYangSchemaRequest.java new file mode 100644 index 000000000..cc1a2c39c --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/GetYangSchemaRequest.java @@ -0,0 +1,61 @@ +/* + * ============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.http.yangschema; + +import javax.servlet.http.HttpServletRequest; + +public class GetYangSchemaRequest { + + private static final String URI_PREFIX = "/yang-schema/"; + private final String module; + private final String version; + + public String getModule() { + return this.module; + } + + public String getVersion() { + return this.version; + } + + public boolean hasVersion() { + return this.version != null; + } + + public GetYangSchemaRequest(HttpServletRequest req) throws Exception { + String uri = req.getRequestURI().substring(URI_PREFIX.length()); + + String[] hlp = uri.split("/"); + if (hlp.length < 1) { + throw new Exception("no module request found"); + + } else if (hlp.length == 1) { + this.module = hlp[0]; + this.version = null; + } else { + this.module = hlp[0]; + this.version = hlp[1]; + } + + } + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFileProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFileProvider.java new file mode 100644 index 000000000..0d46ad098 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFileProvider.java @@ -0,0 +1,208 @@ +/* + * ============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.http.yangschema; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Path; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Date; +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class YangFileProvider { + + private static final Logger LOG = LoggerFactory.getLogger(YangFileProvider.class); + + private static final FilenameFilter yangFilenameFilter = new FilenameFilter() { + + @Override + public boolean accept(File dir, String name) { + return name.toLowerCase().endsWith(".yang"); + } + }; + + private static final int BUFFER_SIZE = 1024; + + private final Path mainSourcePath; + private final List additionalSources; + + public YangFileProvider(String path) { + this.mainSourcePath = new File(path).toPath(); + this.additionalSources = new ArrayList<>(); + } + + public boolean hasFileForModule(String module, String version) { + return this.mainSourcePath.resolve(YangFilename.createFilename(module, version)).toFile().exists(); + } + + public boolean hasFileForModule(String module) { + return this.findYangFiles(module).size() > 0; + } + + private List findYangFiles(String module) { + List list = new ArrayList<>(); + String[] files = this.mainSourcePath.toFile().list(yangFilenameFilter); + YangFilename yangfile; + for (String file : files) { + files = this.mainSourcePath.toFile().list(yangFilenameFilter); + for (String fn : files) { + try { + yangfile = new YangFilename(this.mainSourcePath.resolve(fn).toString()); + if (yangfile.getModule().equals(module)) { + list.add(yangfile); + } + } catch (ParseException e) { + LOG.warn("unable to handle yangfile {}: {}", file, e); + } + } + } + for (Path addPath : this.additionalSources) { + files = addPath.toFile().list(yangFilenameFilter); + for (String file : files) { + try { + yangfile = new YangFilename(addPath.resolve(file).toString()); + if (yangfile.getModule().equals(module)) { + list.add(yangfile); + } + } catch (ParseException e) { + LOG.warn("unable to handle yangfile {}: {}", file, e); + } + } + } + return list; + } + + /** + * get yang file from source with specified version or least newer one if version is null then the latest one + * + * @param module + * @param version + * @return + * @throws ParseException + */ + private @Nullable YangFilename getYangFile(@Nonnull String module, @Nullable String version) throws ParseException { + YangFilename f = null; + List list = this.findYangFiles(module); + + list.sort(SortByDateAscComparator.getInstance()); + + // find specific version or nearest oldest + if (version != null) { + Date rev = YangFilename.parseRevision(version); + for (YangFilename item : list) { + if (rev.equals(item.getRevision())) { + f = item; + break; + } + if (item.getRevision().after(rev)) { + f = item; + break; + } + } + } + // get latest + else { + f = list.get(list.size() - 1); + } + return f; + } + + /** + * write filestream directly to output stream easier for http handling + * + * @param module + * @param version + * @param outputStream + * @return + * @throws IOException + * @throws ParseException + */ + public int writeOutput(@Nonnull String module, @Nullable String version, @Nonnull OutputStream outputStream) + throws IOException, ParseException { + YangFilename fn = this.getYangFile(module, version); + if (fn == null) { + return 0; + } + byte[] buffer = new byte[BUFFER_SIZE]; + int bytesRead = -1; + int sumlen = 0; + InputStream inputStream = null; + try { + inputStream = new FileInputStream(fn.getFilename()); + + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + sumlen += bytesRead; + } + } catch (IOException e) { + LOG.warn("problem sending {}: {}", fn.getFilename(), e); + } finally { + if (inputStream != null) { + inputStream.close(); + } + } + return sumlen; + } + + private static class SortByDateAscComparator implements Comparator { + + private static SortByDateAscComparator instance; + + @Override + public int compare(YangFilename o1, YangFilename o2) { + return o1.getRevision().compareTo(o2.getRevision()); + } + + public static Comparator getInstance() { + if (instance == null) { + instance = new SortByDateAscComparator(); + } + return instance; + } + + } + + public YangFilename getFileForModule(String module, String rev) throws ParseException { + return this.getYangFile(module, rev); + } + + public YangFilename getFileForModule(String module) throws ParseException { + return this.getFileForModule(module, null); + } + + public boolean hasFileOrNewerForModule(String module, String version) throws ParseException { + return this.getYangFile(module, version) != null; + } + +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFilename.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFilename.java new file mode 100644 index 000000000..eb4961a66 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangFilename.java @@ -0,0 +1,74 @@ +/* + * ============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.http.yangschema; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class YangFilename { + + private static final String REGEX = "([^\\/]*)@([0-9]{4}-[0-9]{2}-[0-9]{2}).yang"; + private static final Pattern pattern = Pattern.compile(REGEX, Pattern.MULTILINE); + private final String filename; + private final Matcher matcher; + private Date revision; + private String module; + + public static Date parseRevision(String sRevision) throws ParseException { + final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); + return fmt.parse(sRevision); + } + + public YangFilename(String fn) throws ParseException { + this.filename = fn; + matcher = pattern.matcher(this.filename); + if (!matcher.find()) { + throw new ParseException("unknown filename format", 0); + } + this.module = matcher.group(1); + this.revision = parseRevision(matcher.group(2)); + + } + + public static String createFilename(String module, String rev) { + return String.format("%s@%s.yang", module, rev); + } + + public YangFilename(String module, String rev) throws ParseException { + this(createFilename(module, rev)); + } + + public String getFilename() { + return this.filename; + } + + public Date getRevision() { + return this.revision; + } + + public String getModule() { + return this.module; + } +} 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 new file mode 100644 index 000000000..83518ecb2 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/yangschema/YangSchemaHttpServlet.java @@ -0,0 +1,122 @@ +/* + * ============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.http.yangschema; + +import java.io.IOException; +import java.text.ParseException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class YangSchemaHttpServlet extends HttpServlet { + /** + * + */ + private static final long serialVersionUID = 1L; + private static final Logger LOG = LoggerFactory.getLogger(YangSchemaHttpServlet.class); + + private static final String schemaCachePath = "cache/schema/"; + + private final YangFileProvider fileProvider; + + public YangSchemaHttpServlet() { + this.fileProvider = new YangFileProvider(schemaCachePath); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + GetYangSchemaRequest request = null; + try { + request = new GetYangSchemaRequest(req); + } catch (Exception e) { + LOG.warn("bad request for yang-schema: {}", e); + } + if (request != null) { + int len; + LOG.debug("request for yang-schema for module {} with version {}", request.getModule(), + request.getVersion()); + if (request.hasVersion()) { + boolean has = false; + try { + has = this.fileProvider.hasFileOrNewerForModule(request.getModule(), request.getVersion()); + } catch (ParseException e1) { + LOG.warn("unable to parse revision: {}", e1); + } + if (has) { + + try { + resp.setStatus(HttpServletResponse.SC_OK); + resp.setContentType("text/plain"); + len = this.fileProvider.writeOutput(request.getModule(), request.getVersion(), + resp.getOutputStream()); + resp.setContentLength(len); + + } catch (ParseException e) { + LOG.warn("unable to parse revision: {}", e); + } catch (IOException | IllegalStateException e) { + LOG.warn("unable to write out module {}@{}: {}", request.getModule(), request.getVersion(), e); + } + } else { + try { + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + } catch (IOException | IllegalStateException e) { + LOG.warn("unable to write out 404 res not found: {}", e); + } + } + + } else if (this.fileProvider.hasFileForModule(request.getModule())) { + + try { + resp.setStatus(HttpServletResponse.SC_OK); + resp.setContentType("text/plain"); + len = this.fileProvider.writeOutput(request.getModule(), null, resp.getOutputStream()); + resp.setContentLength(len); + } catch (ParseException e) { + LOG.warn(e.getMessage()); + } catch (IOException | IllegalStateException e) { + LOG.warn("unable to write out module {}: {}", request.getModule(), e); + } + + } else { + try { + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + } catch (IOException | IllegalStateException e) { + LOG.warn("unable to write out 404 res not found: {}", e); + } + } + } else { + try { + resp.sendError(HttpServletResponse.SC_BAD_REQUEST); + } catch (IOException | IllegalStateException e) { + LOG.warn("unable to write out 400 bad request: {}", e); + } + } + + } + +} 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 f9e0fcbc2..ac0ee92f1 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 @@ -22,10 +22,10 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.impl; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.AboutHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.ReadyHttpServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider; 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 4b8564395..6eabc969b 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 @@ -21,11 +21,11 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.impl; +import com.google.common.util.concurrent.ListenableFuture; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.concurrent.TimeUnit; - 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; @@ -94,8 +94,6 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.util.concurrent.ListenableFuture; - public class DataProviderServiceImpl implements DataProviderService, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(DataProviderServiceImpl.class); @@ -116,7 +114,7 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab esConfig.getBasicAuthPassword(), esConfig.trustAllCerts()); this.dataProvider.waitForYellowDatabaseStatus(DATABASE_TIMEOUT_MS, TimeUnit.MILLISECONDS); this.mediatorServerDataProvider = new MediatorServerDataProvider(esConfig.getHosts(), - esConfig.getBasicAuthUsername(), esConfig.getBasicAuthPassword()); + esConfig.getBasicAuthUsername(), esConfig.getBasicAuthPassword(),esConfig.trustAllCerts()); mediatorServerServlet.setDataProvider(this.mediatorServerDataProvider); // Register ourselves as the REST API RPC implementation LOG.info("Register RPC Service " + DataProviderServiceImpl.class.getSimpleName()); diff --git a/sdnr/wt/data-provider/provider/src/main/resources/about/README.md b/sdnr/wt/data-provider/provider/src/main/resources/about/README.md index 58091d5da..17c3825fd 100644 --- a/sdnr/wt/data-provider/provider/src/main/resources/about/README.md +++ b/sdnr/wt/data-provider/provider/src/main/resources/about/README.md @@ -9,7 +9,6 @@ | Yangtools version | {yangtools-version} | | MD-SAL version | {mdsal-version} | | SDN-R packages version | {package-version} ({package-githash}) | -| ODLUX version | {odlux-revision} | | Cluster size | {cluster-size} | ## Device manager diff --git a/sdnr/wt/data-provider/provider/src/main/resources/es-init.replaced.sh b/sdnr/wt/data-provider/provider/src/main/resources/es-init.replaced.sh new file mode 100755 index 000000000..67d495aa0 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/resources/es-init.replaced.sh @@ -0,0 +1,446 @@ +#!/bin/bash +# ============LICENSE_START======================================================================== +# ONAP : ccsdk feature sdnr wt +# ================================================================================================= +# 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========================================================================== +# +# Version 2 +# Usage .. see help below + +SDNRNAME=sdnrdb +REPLICAS=1 +SHARDS=5 +PREFIX="" +VERSION="-v1" +VERBOSE=0 +INITFILENAME="Init.script" + +#declare -a ALIAS +#declare -a MAPPING + +# ------------------------------------------------------------ +# Function with definition of mappings +# $1: alias name for index +# $2: mapping properties and additonal parameter for this section + +set_definition() { + def "connectionlog" '{"node-id": {"type": "keyword"},"timestamp": {"type": "date"},"status": {"type": "keyword"}}' + def "maintenancemode" '{"node-id": {"type": "keyword"},"start": {"type": "date"},"end": {"type": "date"},"description": {"type": "keyword"},"active": {"type": "boolean"}},"date_detection":false}}' + def "faultlog" '{"node-id": {"type": "keyword"},"severity": {"type": "keyword"},"timestamp": {"type": "date"},"problem": {"type": "keyword"},"counter": {"type": "long"},"object-id":{"type": "keyword"},"source-type":{"type": "keyword"}}' + def "faultcurrent" '{"node-id": {"type": "keyword"},"severity": {"type": "keyword"},"timestamp": {"type": "date"},"problem": {"type": "keyword"},"counter": {"type": "long"},"object-id":{"type": "keyword"}}' + def "eventlog" '{"node-id": {"type": "keyword"},"source-type": {"type": "keyword"},"timestamp": {"type": "date"},"new-value": {"type": "keyword"},"attribute-name": {"type": "keyword"},"counter": {"type": "long"},"object-id": {"type": "keyword"}}' + def "inventoryequipment" '{"date": {"type": "keyword"},"model-identifier": {"type": "keyword"},"manufacturer-identifier": {"type": "keyword"},"type-name": {"type": "keyword"},"description": {"type": "keyword"},"uuid": {"type": "keyword"},"version": {"type": "keyword"},"parent-uuid": {"type": "keyword"},"contained-holder": {"type": "keyword"},"node-id": {"type": "keyword"},"tree-level": {"type": "long"},"part-type-id": {"type": "keyword"},"serial": {"type": "keyword"}}' + def "historicalperformance24h" '{"node-name":{"type": "keyword"},"timestamp":{"type": "date"},"suspect-interval-flag":{"type":"boolean"},"scanner-id":{"type": "keyword"},"uuid-interface":{"type": "keyword"},"layer-protocol-name":{"type": "keyword"},"granularity-period":{"type": "keyword"},"radio-signal-id":{"type": "keyword"}}' + def "historicalperformance15min" '{"node-name":{"type": "keyword"},"timestamp":{"type": "date"},"suspect-interval-flag":{"type":"boolean"},"scanner-id":{"type": "keyword"},"uuid-interface":{"type": "keyword"},"layer-protocol-name":{"type": "keyword"},"granularity-period":{"type": "keyword"},"radio-signal-id":{"type": "keyword"}}' + def "mediator-server" '{"url":{"type": "keyword"},"name":{"type": "keyword"}}' + def "networkelement-connection" '{"node-id": {"type": "keyword"},"host": {"type": "keyword"},"port": {"type": "long"},"username": {"type": "keyword"},"password": {"type": "keyword"},"core-model-capability": {"type": "keyword"},"device-type": {"type": "keyword"},"is-required": {"type": "boolean"},"status": {"type": "keyword"}},"date_detection":false' +} + +# ------------------------------------------------------------ +# Functions + +# Get ip of container with database +getsdnrurl() { + if [ ! -z "$DBURL" ]; then + return + fi + cmd=$(which docker) + if [ ! -z "$cmd" ]; then + SDNRIP=$($cmd inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$SDNRNAME") + if [ "$?" = "1" ] ; then + echo "WARN: Container $SDNRNAME not running. Start the sdnrdb container or enter a database url." + echo "continuing with localhost" + SDNRIP="localhost" + fi + else + # if no docker and no db url given + if [ -z "$DBURL" ]; then + echo "WARN: Please enter a database url." + echo "continuing with localhost" + SDNRIP="localhost" + fi + fi + DBURL="http://$SDNRIP:9200" +} + +# Add elements to the array ALIAS and MAPPING +# $1 alias +# $2 mapping properties +def() { + ALIAS=("${ALIAS[@]}" "$1") + MAPPING=("${MAPPING[@]}" "$2") +} + +# $1 Response +print_response() { + response="$1" + body=$(echo $response | sed -E 's/HTTPSTATUS\:[0-9]{3}$//') + code=$(echo $response | tr -d '\n' | sed -E 's/.*HTTPSTATUS:([0-9]{3})$/\1/') + if [ "$VERBOSE" = "0" -a "$code" -ne "200" ] ; then + echo "Error response $code $body" + fi + if [ "$VERBOSE" -ge 1 ] ; then + echo "response $code" + fi + if [ "$VERBOSE" -ge 2 ] ; then + echo "content: $body" + fi +} + +#Write ini file for elasticsearch +# $1 index +# $1 data +file_append() { + echo "PUT:"$1"/:"$2 >> $INITFILENAME +} + +# Send get request to database +# USes DBURL +# $1 url path +# $2 data +http_get_request() { + url="$DBURL/$1" + if [ "$VERBOSE" -ge 2 ] ; then + echo "PUT to $url data $data" + fi + response=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X GET -H "Content-Type: application/json" "$url") + print_response "$response" +} + +# Send put request to database +# USes DBURL +# $1 url path +# $2 data +http_put_request() { + url="$DBURL/$1" + if [ "$VERBOSE" -ge 2 ] ; then + echo "PUT to $url data $data" + fi + response=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X PUT -H "Content-Type: application/json" -d "$2" "$url") + print_response "$response" +} + +# Send delete request to database +# $1 url +http_delete_request() { + url="$DBURL/$1" + if [ "$VERBOSE" -ge 2 ] ; then + echo "DELETE to $url" + fi + echo "DELETE to $url" + response=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X DELETE -H "Content-Type: application/json" $url) + print_response "$response" +} + +# Delete index and alias +# $1 alias +delete_index_alias() { + + echo "deleting alias $alias" + # Delete alias + alias="$PREFIX$1" + index="$PREFIX$1$VERSION" + + url="$index/_alias/$alias" + http_delete_request "$url" + + # Delete index + echo "deleting index $index" + url="$index" + http_delete_request "$url" + + # Delete alias that was falsely autocreated as index + echo "deleting index $index" + url="$alias" + http_delete_request "$url" +} + +# Write mappings +# Uses version, SHARDS and REPLICAS parameters +# $1 alias and datatype "mydatatype" +# $2 mapping properties +# $3 filename or empty for WEB +create_index_alias() { + # Create index + alias="$PREFIX$1" + index="$PREFIX$1$VERSION" + mappings='"mappings":{"'$1'":{"properties":'$2'}}' + settings='"settings":{"index":{"number_of_shards":'$SHARDS',"number_of_replicas":'$REPLICAS'},"analysis":{"analyzer":{"content":{"type":"custom","tokenizer":"whitespace"}}}}' + + if [ -z "$mappings" ]; then + data="{$settings}" + else + data="{$settings,$mappings}" + fi + + url=$index + echo "creating index $index" + if [ -z "$3" ] ; then + http_put_request "$url" "$data" + else + file_append "$url" "$data" + fi + + #Create alias + url="$index/_alias/$alias" + echo "creating alias $alias for $index" + if [ -z "$3" ] ; then + http_put_request "$url" + else + file_append "$url" "{}" + fi +} + +# Wait for status +# $1 time to wait +es_wait_yellow() { + ESSTATUS="yellow" + attempt_counter=0 + max_attempts=5 + echo "Wait up to $max_attempts attempts for $DBURL availability" + until $(curl --output /dev/null --silent --head --fail $DBURL); do + if [ ${attempt_counter} -eq ${max_attempts} ];then + echo "Error: Max attempts reached." + exit 3 + fi + attempt_counter=$(($attempt_counter+1)) + printf '.' + sleep 5 + done + sleep 2 + echo "Wait up to $1 for status $ESSTATUS" + RES=$(curl GET "$DBURL/_cluster/health?wait_for_status=$ESSTATUS&timeout=$1&pretty" 2>/dev/null) + if [ "$?" = "0" ] ; then + if [[ "$RES" =~ .*status.*:.*yellow.* || "$RES" =~ .*status.*:.*green.* ]] ; then + echo "Status $ESSTATUS reached: $RES" + else + echo "Error: DB Reachable, but status $ESSTATUS not reached" + exit 2 + fi + else + echo "Error: $DBURL not reachable" + exit 2 + fi +} + +# Commands + +cmd_create() { + if [ -n "$WAITYELLOW" ] ; then + es_wait_yellow "$WAITYELLOW" + fi + for i in "${!ALIAS[@]}"; do + create_index_alias "${ALIAS[$i]}" "${MAPPING[$i]}" + done +} + +cmd_delete() { + if [ -n "$WAITYELLOW" ] ; then + es_wait_yellow "$WAITYELLOW" + fi + for i in "${!ALIAS[@]}"; do + delete_index_alias "${ALIAS[$i]}" + done + for i in "${!ALIAS[@]}"; do + delete_index_alias "${ALIAS[$i]}" + done +} +cmd_purge() { +# http_get_request '_cat/aliases' +# body=$(echo $response | sed -E 's/HTTPSTATUS\:[0-9]{3}$//') +# echo "$response" | awk '/^([^ ]*)[ ]*([^ ]*).*$/{ print $2"/_alias/"$1 }' +# http_get_request '_cat/indices' +# echo "indices" +# echo "$response" +# echo "$response" | awk '/^[^ ]*[ ]*[^ ]*[ ]*([^ ]*).*$/{ print $3 }' + echo "not yet implemented" +} +cmd_initfile() { + echo "Create script initfile: $INITFILENAME" + if [ -f "$INITFILENAME" ] ; then + rm $INITFILENAME + else + mkdir -p $(dirname $INITFILENAME ) + fi + for i in "${!ALIAS[@]}"; do + create_index_alias "${ALIAS[$i]}" "${MAPPING[$i]}" file + done +} + +# Prepare database startup +cmd_startup() { + ESWAIT=30s + echo "Startup ElasticSearch DBURL=$DBURL CMD=$STARTUP_CMD CLUSTER=$CLUSTER_ENABLED INDEX=$NODE_INDEX" + if $CLUSTER_ENABLED ; then + if [ "$NODE_INDEX" = "0" ] ; then + echo "Cluster node 0 detected .. create" + es_wait_yellow $ESWAIT + cmd_create + else + echo "Cluster node > 0 detected .. do nothing" + fi + else + echo "No cluster" + es_wait_yellow $ESWAIT + cmd_create + fi +} + +# Parse arguments +parse_args() { + while [[ $# -gt 0 ]] + do + par=($(echo $1 | tr '=' '\n')) + echo "" + if [ ${#par[@]} == "2" ] ; then + # Equal sign found + key=${par[0]} + value=${par[1]} + else + # No equal sign + key="$1" + value="$2" + fi + shift + #Further shift if parameter is used + case $key in + -db|--dburl|--database) + DBURL="$value" + shift + ;; + -r|--replicas) + REPLICAS="$value" + shift + ;; + -s|--shards) + SHARDS="$value" + shift + ;; + -p|--prefix) + PREFIX="$value" + shift + ;; + -f|--file) + INITFILENAME="$value" + shift + ;; + -x|--verbose) + VERBOSE="${value:-0}" + shift + ;; + -v|--version) + VERSION="${value:--v1}" + shift + ;; + -vx|--versionx) + VERSION="" + ;; + -w|--wait) + WAITYELLOW="${value:-30s}" + shift + ;; + --cmd) + STARTUP_CMD="$value" + shift + ;; + --odlcluster) + CLUSTER_ENABLED="$value" + shift + ;; + --index) + NODE_INDEX="$value" + shift + ;; + *) + ;; + esac; + done +} + +# ----------------------------------------- +# Main starts here + +TASK=$1 +shift +parse_args "$@" + +set_definition + + +echo "------------------------------" +echo "Elasticsearch for SDN-R helper" +echo "------------------------------" +echo "Uses database container $SDNRNAME" +echo "Database url $DBURL" +echo " shards=$SHARDS replicas=$REPLICAS prefix=$PREFIX verbose=$VERBOSE version='$VERSION'" + + +case "$TASK" in + "create") + getsdnrurl + if [ -z "$DBURL" ] ; then + echo "Error: unable to detect database url." + exit 1 + fi + cmd_create + ;; + "delete") + getsdnrurl + if [ -z "$DBURL" ] ; then + echo "Error: unable to detect database url." + exit 1 + fi + cmd_delete + ;; + "purge") + getsdnrurl + if [ -z "$DBURL" ] ; then + echo "Error: unable to detect database url." + exit 1 + fi + cmd_purge + ;; + "initfile") + cmd_initfile + ;; + "startup") + cmd_startup + ;; + *) + echo "usage:" + echo " es-init.sh COMMAND [OPTIONS]" + echo " Commands:" + echo " create create SDN-R used indices and aliases" + echo " delete delete SDN-R used indices and aliases" + echo " initfile Create initfile for java unit tests" + echo " purge Clear complete database (indices and aliases)" + echo " startup Initial database write if node number 01" + echo " Options:" + echo -e " -db\--database DATABASEURL" + echo -e " -r\--replicas REPLICAS" + echo -e " -s\--shards SHARDS" + echo -e " -p\--prefix DATABASE-PREFIX" + echo -e " -f\--file init filename" + echo -e " -x\--verbose Verbose level less 0 .. 2 full" + echo -e " -v\--version Version prefix" + echo -e " -vx\--versionx Version prefix empty" + echo -e " -i\--ignore Ignore error responses" + echo -e " --odlcluster true/false if odl configured as cluster" + echo -e " --index Cluster node 0.." + echo -e " --cmd startup sub command" + echo " examples:" + echo " single node db:" + echo " es-init.sh create -db http://sdnrdb:9200 -r 0" + ;; +esac diff --git a/sdnr/wt/data-provider/provider/src/main/resources/es-init.sh b/sdnr/wt/data-provider/provider/src/main/resources/es-init.sh new file mode 100755 index 000000000..1cbfd7d7a --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/resources/es-init.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# ============LICENSE_START======================================================================== +# ONAP : ccsdk feature sdnr wt +# ================================================================================================= +# 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========================================================================== +# +# Version 2 +# Usage .. see help below + +echo "Depricated. Please use init container and jar directly" +java -jar $ODL_HOME/system/org/onap/ccsdk/features/sdnr/wt/sdnr-wt-data-provider-setup/$FEATURES_SDNR/sdnr-dmt.jar -c init -db $SDNRDBURL -dbu $SDNRDBUSERNAME -dbp $SDNRDBPASSWORD 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 7235b9042..ad9661f66 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 @@ -43,7 +43,7 @@ + class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet"> + class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.yangschema.YangSchemaHttpServlet"> diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java index 5d9011ab0..1e6752764 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java @@ -24,7 +24,8 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.AboutHttpServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet; + import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; 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 9c95a7d98..ccb1ea53f 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 @@ -38,7 +38,7 @@ 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.data.ElasticSearchDataProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.entity.HtDatabaseEventsService; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java index 5c2a66e75..717b7add6 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java @@ -34,7 +34,7 @@ import org.mockito.Mockito; import org.mockito.stubbing.Answer; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.QueryByFilter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryByFilter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SortOrder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java index 2aedabee4..aa010939d 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java @@ -28,9 +28,9 @@ import java.util.Set; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section; import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.AboutHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey; import org.opendaylight.mdsal.binding.api.RpcProviderService; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java index e757e24d3..b8fa5d668 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java @@ -32,7 +32,7 @@ import org.json.JSONObject; import org.junit.Test; import org.mockito.Mockito; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.QueryByFilter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryByFilter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.FilterBuilder; 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 4221891b3..d8d424174 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 @@ -209,7 +209,6 @@ public class TestYangGenSalMapping { out(generatedNode.toString()); // Print it with specified indentation } - @Test public void test5() throws IOException { // @formatter:off @@ -270,10 +269,8 @@ public class TestYangGenSalMapping { // Map to JSON String to Object Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class); out(generatedNode.toString()); // Print it with specified indentation - } - @Test public void test6() throws Exception { out(method()); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java index 244d6b053..a2b90074e 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java @@ -45,9 +45,10 @@ import javax.servlet.http.HttpServletResponse; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.YangFileProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.YangFilename; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.YangSchemaHttpServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.yangschema.YangFileProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.yangschema.YangFilename; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.yangschema.YangSchemaHttpServlet; + import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -- cgit 1.2.3-korg