From 25b3759a0907d06e0d8e391f751c6fcf067087f5 Mon Sep 17 00:00:00 2001 From: highstreetherbert Date: Wed, 15 Jul 2020 15:44:23 +0200 Subject: SDN-R data-provider with ES7 Extend to ES 7.x and DB setup Issue-ID: SDNC-1288 Signed-off-by: highstreetherbert Change-Id: Id7778322b793bfa7472a14a90bc0d1fd953c8c73 Signed-off-by: highstreetherbert --- sdnr/wt/data-provider/installer/pom.xml | 2 +- .../sdnr/wt/dataprovider/model/DataProvider.java | 13 +- .../model/src/main/yang/data-provider.yang | 1662 ------------------- .../src/main/yang/data-provider@2019-08-01.yang | 1674 ++++++++++++++++++++ sdnr/wt/data-provider/provider/pom.xml | 14 +- .../wt/dataprovider/data/DataObjectAcessor.java | 35 +- .../wt/dataprovider/data/DataObjectAcessorPm.java | 93 +- .../dataprovider/data/DataObjectAcessorStatus.java | 4 +- .../dataprovider/data/DataObjectAcessorWithId.java | 41 + .../wt/dataprovider/data/DataTreeChildObject.java | 46 - .../sdnr/wt/dataprovider/data/DataTreeObject.java | 32 - .../data/ElasticSearchDataProvider.java | 37 +- .../dataprovider/data/HtDatabaseEventsService.java | 66 +- .../data/HtDatabaseMaintenanceService.java | 6 +- .../data/MediatorServerDataProvider.java | 4 +- .../sdnr/wt/dataprovider/data/ODLVersionLUT.java | 64 - .../sdnr/wt/dataprovider/data/QueryByFilter.java | 158 +- .../wt/dataprovider/data/QueryByFilterStatic.java | 336 ++++ .../sdnr/wt/dataprovider/data/QueryResult.java | 13 +- .../sdnr/wt/dataprovider/data/SystemInfo.java | 337 ---- .../database/EsDataObjectReaderWriter.java | 357 ----- .../database/EsDataObjectReaderWriter2.java | 129 +- .../wt/dataprovider/http/AboutHttpServlet.java | 43 +- .../wt/dataprovider/http/DataTreeChildObject.java | 192 +++ .../wt/dataprovider/http/DataTreeHttpServlet.java | 189 ++- .../sdnr/wt/dataprovider/http/DataTreeObject.java | 140 ++ .../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 | 1 - .../wt/dataprovider/impl/DataProviderImpl.java | 6 + .../wt/dataprovider/impl/DataTreeProviderImpl.java | 321 ++++ .../sdnr/wt/dataprovider/impl/EsConfig.java | 4 +- .../dataprovider/yangtools/YangToolsMapper2.java | 39 +- .../provider/src/main/resources/about/README.md | 7 +- .../provider/src/main/resources/es-init.sh | 446 ------ .../org/opendaylight/blueprint/impl-blueprint.xml | 16 +- .../sdnr/wt/dataprovider/test/TestAbout.java | 1 - .../wt/dataprovider/test/TestCRUDforDatabase.java | 5 +- .../sdnr/wt/dataprovider/test/TestConfig.java | 40 +- .../test/TestDataTreeSerialization.java | 33 - .../wt/dataprovider/test/TestEventService.java | 7 +- .../wt/dataprovider/test/TestFilterConversion.java | 69 +- .../wt/dataprovider/test/TestImplementation.java | 19 +- .../test/TestMaintenanceServiceData.java | 7 +- .../test/TestMediatorServerService.java | 14 +- .../sdnr/wt/dataprovider/test/TestNuMappings.java | 38 +- .../wt/dataprovider/test/TestTimestampFilter.java | 85 +- .../sdnr/wt/dataprovider/test/TestTree.java | 81 + .../dataprovider/test/TestYangGenSalMapping.java | 314 ++-- .../wt/dataprovider/test/TestYangProvider.java | 1 - .../wt/dataprovider/test/util/HostInfoForTest.java | 53 + .../src/test/resources/simplelogger.properties | 4 +- sdnr/wt/data-provider/setup/pom.xml | 12 +- .../setup/DataMigrationProviderImpl.java | 41 +- .../sdnr/wt/dataprovider/setup/Program.java | 114 +- .../wt/dataprovider/setup/ReleaseInformation.java | 8 +- .../wt/dataprovider/setup/data/DatabaseInfo.java | 2 +- .../wt/dataprovider/setup/data/DatabaseInfo7.java | 44 + .../setup/data/MavenDatabasePluginInitFile.java | 1 + .../sdnr/wt/dataprovider/setup/data/Release.java | 12 +- .../wt/dataprovider/setup/data/ReleaseGroup.java | 66 + .../setup/data/SearchHitConverter.java | 17 +- .../frankfurt/FrankfurtReleaseInformation.java | 2 +- .../frankfurt/FrankfurtReleaseInformationR2.java | 102 ++ .../setup/guilin/GuilinReleaseInformation.java | 11 +- .../setup/guilin/GuilinReleaseInformationR2.java | 81 + .../sdnr/wt/dataprovider/setup/TestData.java | 97 +- .../dataprovider/setup/TestMigrationProvider.java | 13 +- sdnr/wt/data-provider/setup/tmp.log | 1 - 70 files changed, 4792 insertions(+), 3612 deletions(-) delete mode 100644 sdnr/wt/data-provider/model/src/main/yang/data-provider.yang create mode 100644 sdnr/wt/data-provider/model/src/main/yang/data-provider@2019-08-01.yang create 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/DataTreeChildObject.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataTreeObject.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ODLVersionLUT.java create 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/SystemInfo.java delete mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MarkdownTable.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ODLVersionLUT.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/SystemInfo.java create mode 100644 sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java delete mode 100755 sdnr/wt/data-provider/provider/src/main/resources/es-init.sh delete mode 100644 sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataTreeSerialization.java create mode 100644 sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java create mode 100644 sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/HostInfoForTest.java create mode 100644 sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo7.java create mode 100644 sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ReleaseGroup.java create mode 100644 sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/frankfurt/FrankfurtReleaseInformationR2.java create mode 100644 sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/guilin/GuilinReleaseInformationR2.java delete mode 100644 sdnr/wt/data-provider/setup/tmp.log (limited to 'sdnr/wt') diff --git a/sdnr/wt/data-provider/installer/pom.xml b/sdnr/wt/data-provider/installer/pom.xml index 5b3a5df13..dcb688468 100755 --- a/sdnr/wt/data-provider/installer/pom.xml +++ b/sdnr/wt/data-provider/installer/pom.xml @@ -69,7 +69,7 @@ ${application.name}-setup ${project.version} - + diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java index a9e334668..f4578d5dc 100644 --- a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java @@ -1,4 +1,4 @@ -/** +/* * ============LICENSE_START======================================================================== * ONAP : ccsdk feature sdnr wt * ================================================================================================= @@ -19,7 +19,6 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.model; import java.util.Date; import java.util.List; - import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity; @@ -67,7 +66,7 @@ public interface DataProvider extends ArchiveCleanProvider { /** * write internal equipment to database - * + * * @param internalEquipment with mandatory fields. */ void writeInventory(Inventory internalEquipment); @@ -76,17 +75,19 @@ public interface DataProvider extends ArchiveCleanProvider { * * @param networkElementConnectionEntitiy to wirte to DB * @param nodeId Id for this DB element + * @return if succeeded */ - void updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy, + boolean updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy, String nodeId); /** * Update after new mountpoint registration - * + * * @param networkElementConnectionEntitiy data * @param nodeId of device (mountpoint name) + * @return if succeeded */ - void updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy, String nodeId); + boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy, String nodeId); void removeNetworkConnection(String nodeId); diff --git a/sdnr/wt/data-provider/model/src/main/yang/data-provider.yang b/sdnr/wt/data-provider/model/src/main/yang/data-provider.yang deleted file mode 100644 index ef65104e5..000000000 --- a/sdnr/wt/data-provider/model/src/main/yang/data-provider.yang +++ /dev/null @@ -1,1662 +0,0 @@ -module data-provider { - - yang-version 1.1; - namespace "urn:opendaylight:params:xml:ns:yang:data-provider"; - prefix odluxprovider; - - import ietf-yang-types { - prefix yang; - reference - "RFC 6991: Common YANG Data Types."; - } - - organization - "highstreet technologies GmbH"; - contact - "Web: - ONAP: "; - - description - "This module defines the API for the data-provider component. - - Copyright 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."; - - revision 2019-08-01 { - description - "Initial revision"; - reference - "https://jira.onap.org/browse/SDNC-879"; - } - - // --- typedef - - typedef Entity { - type enumeration { - enum connectionlog { - description - "logs mountpoint connection state changes"; - } - enum faultcurrent { - description - "current faults"; - } - enum eventlog { - description - "logs for all notifications e.g. NetConf, ves and internal events"; - } - enum faultlog { - description - "faultlog information"; - } - enum historicalperformance15min { - description - "performance data"; - } - enum historicalperformance24h { - description - "performance data"; - } - enum mediator-server { - description - "list of mediator servers"; - } - enum networkelement-connection { - description - "list of mountpoints for NetConf devices (joint required-network-element+mdsal - state"; - } - enum inventoryequipment { - description - "list of equipment inventory"; - } - enum maintenancemode { - description - "list of maintenance setting"; - } - } - description - "Data type and alias for elasticsearch or table name for SQL database."; - } - - typedef SortOrder { - type enumeration { - enum ascending { - description - "Self explaining."; - } - enum descending { - description - "Self explaining."; - } - } - description - "Entities for odlux clients"; - } - - typedef FilterProperty { - type string; - description - "A string type describing a property (attribute, column, parameter) - filter"; - } - - typedef NotificationType { - type enumeration { - enum ProblemNotificationXml { - description - "A fault (alarm, problem) notification type in XML format."; - } - enum AttributeValueChangedNotificationXml { - description - "An attribute value change notification type in XML format."; - } - } - description - "An enumeration describing the found notification type."; - } - - typedef ConnectionLogStatus { - type enumeration { - enum Mounted { - description - "Mountpoint created"; - } - enum Unmounted { - description - "Mountpoint removed"; - } - enum Connecting { - description - "Mountpoint establishing connection"; - } - enum Connected { - description - "Mountpoint connection established"; - } - enum UnableToConnect { - description - "Mountpoint connection not possible"; - } - enum Disconnected { - description - "Required and mountpoint removed"; - } - enum Undefined { - description - "Status not available"; - } - } - description - "An enumeration describing connection states."; - } - - typedef NetworkElementDeviceType { - type enumeration { - enum Wireless { - description - "implements microwave-model.yang or air-interface.yang"; - } - enum RAN { - description - "implements sth. like o-ran*.yang"; - } - enum ORAN { - description - "implements RAN according to o-ran*.yang"; - } - enum RAN3GPP { - description - "implements RAN according to _3gpp-ran*.yang"; - } - enum Optical { - description - "implements tapi-*.yang or org-openroadm*.yang"; - } - enum Router { - description - "implements vlan-interface.yang"; - } - enum NtsManager { - description - "Simulation of device"; - } - enum Nonsupported { - description - "Device type known, but not support"; - } - enum Unknown { - description - "Device type at this point of time unknown"; - } - } - description - "An enumeration as identification of the device."; - } - - typedef severity-type { - type enumeration { - enum NonAlarmed { - description - "problem cleared indication"; - } - enum Warning { - description - "problem level"; - } - enum Minor { - description - "problem level"; - } - enum Major { - description - "problem level"; - } - enum Critical { - description - "problem level"; - } - } - description - "According to ITU-T M.3160"; - } - - typedef source-type { - type enumeration { - enum Ves { - description - "VES Interface"; - } - enum Netconf { - description - "NetConf Interface"; - } - enum Controller { - description - "SDN Controller"; - } - enum Unknown { - description - "Unknown source"; - } - } - description - "An enumeration for the information source of an event/notification."; - } - - typedef granularity-period-type { - type enumeration { - enum unknown { - description - "none"; - } - enum period-15-min { - description - "none"; - } - enum period-24-hours { - description - "none"; - } - } - description - "The enumeration with the options for granularity period of the - performance data similar to g.874.1-model"; - } - - // --- grouping and builder-container - - grouping connectionlog-entity { - leaf id { - type string; - description - "database id"; - } - leaf node-id { - type string; - description - "the node/mountpoint which connection state has changed"; - } - leaf timestamp { - type yang:date-and-time; - description - "timestamp when event happened, preferred in UTC time format."; - } - leaf status { - type ConnectionLogStatus; - description - "new state of the connection of the device"; - } - description - "An object class describing an entry in the connection status log."; - } - - container connectionlog { - description - "builder"; - uses connectionlog-entity; - } - - grouping object-change-reference { - description - "Reference of of object (e.g. Interface pack) owned by a node"; - leaf node-id { - type string; - description - "A network wide unique identifier of the NetConf server."; - } - leaf counter { - type int32; - description - "An arbitrary counter value."; - } - leaf timestamp { - type yang:date-and-time; - description - "The time of the reported change, preferred in UTC time format. "; - } - leaf object-id { - type string; - description - "The identifier of the reporting object (resource)."; - } - } - - grouping source-reference { - description - "Identify a source"; - leaf source-type { - type source-type; - description - "The source type."; - } - } - - grouping fault { - description - "Fault event of an object"; - leaf problem { - type string; - description - "The alarm type identifier."; - } - leaf severity { - type severity-type; - description - "The reported severity of the fault (alarm)."; - } - } - - grouping attribute-change { - description - "update change of an attribute"; - leaf attribute-name { - type string; - description - "The attribute name which was changed."; - } - leaf new-value { - type string; - description - "The new value of the attribute converted to a string format."; - } - } - - grouping entity-id { - description - "Unique database id of entity"; - leaf id { - type string; - description - "The unique identifier of the entity."; - } - } - - grouping faultcurrent-entity { - description - "Current fault status"; - uses object-change-reference; - uses fault; - uses entity-id; - } - - container faultcurrent { - description - "builder"; - uses faultcurrent-entity; - } - - grouping faultlog-entity { - description - "Changed fault indication"; - uses source-reference; - uses object-change-reference; - uses fault; - uses entity-id; - } - - container faultlog { - description - "builder"; - uses faultlog-entity; - } - - grouping eventlog-entity { - description - "One change event of devices"; - uses source-reference; - uses object-change-reference; - uses attribute-change; - uses entity-id; - } - - container eventlog { - description - "builder"; - uses eventlog-entity; - } - - grouping filter { - leaf description { - type string; - description - "Filter specific description"; - } - leaf start { - type yang:date-and-time; - description - "begin of maintenance-mode"; - } - leaf end { - type yang:date-and-time; - description - "end of maintenance-mode"; - } - leaf object-id-ref { - type string; - description - "object id to filter on, or empty for all"; - } - leaf problem { - type string; - description - "name of the problem to filter or empty for all"; - } - description - "An object class describing a generic filter of an interval for - faults (alarms)."; - } - - grouping maintenance-entity { - description - "Maintenance mode for a device. "; - leaf id { - type string; - mandatory true; - description - "Key to get/set configuration entry in database. Normally Mountpoint - name is used as key id of node."; - } - leaf node-id { - type string; - mandatory true; - description - "A network wide unique identifier of the NetConf server."; - } - leaf active { - type boolean; - description - "Configuration to activate or deactivate this entry"; - } - uses filter; - } - - container maintenance { - presence "false"; - description - "builder"; - uses maintenance-entity; - } - - grouping mediator-server-entity { - leaf id { - type string; - mandatory true; - description - "A network unique identifier of the mediator server."; - } - leaf url { - type string; - description - "The ULR to reach the REST interface of the mediator server."; - } - leaf name { - type string; - description - "A human readable name of the mediator server."; - } - description - "An object class describing a mediator server entity."; - } - - grouping pmdata-base { - description - "Performance data base information"; - leaf node-name { - type string; - description - "A network unique identifier of reporting NetConf server."; - } - leaf uuid-interface { - type string; - description - "A universal unique identifier of the performance monitoring point."; - } - leaf layer-protocol-name { - type string; - description - "The name of the measured transport layer."; - } - leaf radio-signal-id { - type string; - description - "The value exists only of wireless transport devices."; - } - leaf time-stamp { - type yang:date-and-time; - description - "The time-stamp of the measurement, preferred in UTC format."; - } - leaf suspect-interval-flag { - type boolean; - description - "If false, the measurement is not completed and should not be used - for performance analysis. "; - } - leaf granularity-period { - type granularity-period-type; - description - "The expected measurement interval."; - } - leaf scanner-id { - type string; - description - "See ITU-T X.739 chapter 8.1.1.2."; - } - } - - grouping pmdata-microwave { - description - "Consolidated performance information of all microwave model interface - PACs"; - leaf es { - type int32; - units "s"; - default "-1"; - config false; - description - "Number of errored seconds."; - } - leaf ses { - type int32; - units "s"; - default "-1"; - config false; - description - "Number of severely errored seconds."; - } - leaf cses { - type int32; - units "s"; - default "-1"; - config false; - description - "Number of consecutive severely errored seconds."; - } - leaf unavailability { - type int32; - units "s"; - default "-1"; - config false; - description - "Total time of unavailability in seconds."; - } - leaf tx-level-min { - type int8; - units "dBm"; - default "99"; - config false; - description - "Minimum transmit power. Signed integers are required."; - } - leaf tx-level-max { - type int8; - units "dBm"; - default "99"; - config false; - description - "Maximum transmit power. Signed integers are required."; - } - leaf tx-level-avg { - type int8; - units "dBm"; - default "99"; - config false; - description - "Averaged transmit power. Signed integers are required."; - } - leaf rx-level-min { - type int8; - units "dBm"; - default "99"; - config false; - description - "Minimum receive level. Signed integers are required."; - } - leaf rx-level-max { - type int8; - units "dBm"; - default "99"; - config false; - description - "Maximum receive level. Signed integers are required."; - } - leaf rx-level-avg { - type int8; - units "dBm"; - default "99"; - config false; - description - "Averaged receive level. Signed integers are required."; - } - leaf time2-states { - type int32; - units "s"; - default "-1"; - config false; - description - "Sum of all seconds the transmitter operated in e.g. BPSK."; - } - leaf time4-states-s { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time4-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time8-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time16-states-s { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time16-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time32-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time64-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time128-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time256-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time512-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time512-states-l { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time1024-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time1024-states-l { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time2048-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time2048-states-l { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time4096-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time4096-states-l { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time8192-states { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf time8192-states-l { - type int32; - units "s"; - default "-1"; - config false; - description - "none"; - } - leaf snir-min { - type int8; - units "dB"; - default "-99"; - config false; - description - "Minimum signal to (noise+interference) ratio."; - } - leaf snir-max { - type int8; - units "dB"; - default "-99"; - config false; - description - "Maximum signal to (noise+interference) ratio."; - } - leaf snir-avg { - type int8; - units "dB"; - default "-99"; - config false; - description - "Averaged signal to (noise+interference) ratio."; - } - leaf xpd-min { - type int8; - units "dB"; - default "-99"; - config false; - description - "Minimum cross polarization discrimination."; - } - leaf xpd-max { - type int8; - units "dB"; - default "-99"; - config false; - description - "Maximum cross polarization discrimination."; - } - leaf xpd-avg { - type int8; - units "dB"; - default "-99"; - config false; - description - "Averaged cross polarization discrimination."; - } - leaf rf-temp-min { - type int8; - units "C"; - default "-99"; - config false; - description - "Lowest temperature (in degree Celsius) of the radio module inside the - outdoor unit."; - } - leaf rf-temp-max { - type int8; - units "C"; - default "-99"; - config false; - description - "Highest temperature (in degree Celsius) of the radio module inside the - outdoor unit."; - } - leaf rf-temp-avg { - type int8; - units "C"; - default "-99"; - config false; - description - "Averaged temperature (in degree Celsius) of the radio module inside - the outdoor unit."; - } - leaf defect-blocks-sum { - type int16; - units "blocks"; - default "-1"; - config false; - description - "Total number of blocks that were defect after receiving and could not - be corrected by the FEC."; - } - leaf time-period { - type int32; - units "s"; - default "-1"; - config false; - description - "Total length of the measurement period."; - } - } - - grouping pmdata-ethernet { - description - "Consolidated performance information for Ethernet."; - leaf tx-ethernet-bytes-max-s { - type int32; - units "Bytes/s"; - default "-1"; - config false; - description - "Counts the number of Bytes of Ethernet traffic (before header - compression) transmitted within a second and keeps the highest value - within the measurement period. Field to be left blank for all types of - TDM containers."; - } - leaf tx-ethernet-bytes-max-m { - type int64; - units "Bytes/min"; - default "-1"; - config false; - description - "Counts the number of Bytes of Ethernet traffic (before header - compression) transmitted within a minute and keeps the highest value - with in the measurement period. Field to be left blank for all types - of TDM containers."; - } - leaf tx-ethernet-bytes-sum { - type int64; - units "Bytes"; - default "-1"; - config false; - description - "Total number of Bytes of Ethernet traffic (before header compression) - transmitted (in direction out of the device) during the measurement - period. Field to be left blank for all types of TDM containers."; - } - } - - container pmdata-entity { - description - "builder"; - uses pmdata-base; - container performance-data { - uses pmdata-microwave; - uses pmdata-ethernet; - description - "An object combining different performance monitoring data."; - } - } - - grouping pmdata15m-entity { - uses pmdata-base; - container performance-data { - uses pmdata-microwave; - uses pmdata-ethernet; - description - "An object combining different performance monitoring data."; - } - description - "An object class describing a 15 minute performance monitoring entity."; - } - - grouping pmdata24h-entity { - uses pmdata-base; - container performance-data { - uses pmdata-microwave; - uses pmdata-ethernet; - description - "An object combining different performance monitoring data."; - } - description - "An object class describing a 24 hour performance monitoring entity."; - } - - grouping inventory-entity { - description - "One equipment entity in a list of a network element that could be rack, - card, backplane, module"; - leaf id { - type string; - mandatory true; - description - "Unique database id, node-id/uuid"; - } - leaf tree-level { - type uint32; - description - "Containment level, starting with 0.."; - } - leaf parent-uuid { - type string; - description - "Unique inventory id of holder"; - } - leaf node-id { - type string; - description - "Unique node id of network element"; - } - leaf uuid { - type string; - description - "Unique inventory id of this node for this equipment, provided by - network element"; - } - leaf-list contained-holder { - type string; - description - "List of uuid of contained equipment"; - } - leaf manufacturer-name { - type string; - description - "manufactured-thing/manufacturer-properties/manufacturer-name"; - } - leaf manufacturer-identifier { - type string; - description - "manufactured-thing/manufacturer-properties/manufacturer-identifier"; - } - leaf serial { - type string; - description - "manufactured-thing/equipment-instance/serial"; - } - leaf date { - type string; - description - "manufactured-thing/equipment-instance/manufacture-date: Date - information provided by manufacturer. No specific format. ()"; - } - leaf version { - type string; - description - "manufactured-thing/equipment-type/version"; - } - leaf description { - type string; - description - "manufactured-thing/equipment-type/description"; - } - leaf part-type-id { - type string; - description - "manufactured-thing/equipment-type/part-type-identifier"; - } - leaf model-identifier { - type string; - description - "manufactured-thing/equipment-type/model-identifier"; - } - leaf type-name { - type string; - description - "manufactured-thing/equipment-type/type-name"; - } - } - - container inventory { - presence "false"; - description - "builder"; - uses inventory-entity; - } - - grouping node-details-g { - leaf-list available-capabilities { - type string; - description - "The list of available yang capabilities."; - } - leaf-list unavailable-capabilities { - type string; - description - "The list of unavailable yang capabilities."; - } - description - "An object class description the available and unavailable yang - capabilities."; - } - - grouping network-element-connection-entity { - leaf id { - type string; - description - "database id/key. here is equal to node-id"; - } - leaf node-id { - type string; - description - "mountpoint name of device in controller"; - } - leaf host { - type string; - description - "NetConf server host name or IP address of device"; - } - leaf port { - type uint32; - description - "NetConf port of device"; - } - leaf username { - type string; - description - "NetConf user name"; - } - leaf password { - type string; - description - "NetConf password. should be removed asap"; - } - leaf core-model-capability { - type string; - description - "revision of core-model capability"; - } - leaf device-type { - type NetworkElementDeviceType; - description - "categorized type of device based on implemented yang specs"; - } - leaf is-required { - type boolean; - description - "entry exists in db index required-networkelement"; - } - container node-details { - uses node-details-g; - description - "holder of available and unavailable capabilities"; - } - leaf status { - type ConnectionLogStatus; - description - "current connection status. default Disconnected"; - } - description - "An object class defining the NetConf connection towards a - NetConf server. "; - } - - container network-element-connection { - description - "builder"; - uses network-element-connection-entity; - } - - grouping status-entity { - container faults { - leaf criticals { - type uint32; - description - "The number of current faults (active alarms) with severity - 'critical'."; - } - leaf majors { - type uint32; - description - "The number of current faults (active alarms) with severity - 'major'."; - } - leaf minors { - type uint32; - description - "The number of current faults (active alarms) with severity - 'minor'."; - } - leaf warnings { - type uint32; - description - "The number of current faults (active alarms) with severity - 'warning'."; - } - description - "An object containing the number of current faults per its severity."; - } - description - "An object class defining an status entity for current faults - (also called active alarms)."; - } - - container status { - description - "builder"; - uses status-entity; - } - - grouping entity-input { - list filter { - key "property"; - leaf property { - type string; - description - "The property (parameter, column, field) identifier."; - } - leaf filtervalue { - type string; - description - "The filter information for the corresponding property."; - } - description - "List with filter criteria. Not listed means all."; - } - list sortorder { - key "property"; - leaf property { - type string; - description - "The property (parameter, column, field) identifier."; - } - leaf sortorder { - type SortOrder; - description - "The definition of the sort order for the corresponding property."; - } - description - "List with sort order. Not listed means default"; - } - container pagination { - leaf size { - type uint32 { - range "1..max"; - } - default "20"; - description - "Number of entries to be delivered"; - } - leaf page { - type uint64 { - range "1..max"; - } - default "1"; - description - "Number to be used to calculate starting entry to deliver"; - } - description - "An object defining the pagination details."; - } - description - "An object class defining a request input entity."; - } - - grouping pagination-output-g { - leaf size { - type uint32 { - range "1..max"; - } - default "20"; - description - "Number of entries to be delivered"; - } - leaf page { - type uint64 { - range "1..max"; - } - default "1"; - description - "Number to be used to calculate starting entry to deliver"; - } - leaf total { - type uint64 { - range "0..max"; - } - default "0"; - description - "Number to be used to calculate starting entry to deliver"; - } - description - "An object class defining the filter information for pagination."; - } - - container pagination-output { - description - "builder"; - uses pagination-output-g; - } - - // --- rpc - - rpc read-faultcurrent-list { - description - "Get list of current fault (active alarm) entries according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses faultcurrent-entity; - description - "The output data as list of current fault (or active alarm) - entities."; - } - } - } - - rpc read-faultlog-list { - description - "Get list of faultlog entries according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses faultlog-entity; - description - "The output data as list of fault entities."; - } - } - } - - rpc read-eventlog-list { - description - "Get list of event log entities according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses eventlog-entity; - description - "The output data as list of event log entities."; - } - } - } - - rpc read-connectionlog-list { - description - "Get list of event log entities according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses connectionlog-entity; - description - "The output data as list of connection log entities."; - } - } - } - - rpc read-maintenance-list { - description - "Get list of maintenance entries according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses maintenance-entity; - description - "The output data as list of maintenance entities."; - } - } - } - - rpc create-maintenance { - description - "insert new entry of maintenance"; - input { - uses maintenance-entity; - } - output { - uses maintenance-entity; - } - } - - rpc update-maintenance { - description - "update existing entity of maintenance"; - input { - uses maintenance-entity; - } - output { - uses maintenance-entity; - } - } - - rpc delete-maintenance { - description - "delete entity of maintenance"; - input { - uses maintenance-entity; - } - } - - rpc read-mediator-server-list { - description - "Get list of mediator-servers according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses mediator-server-entity; - description - "The list of found mediator server entities."; - } - } - } - - rpc create-mediator-server { - description - "create new entry of entity mediator-server"; - input { - uses mediator-server-entity; - } - output { - uses mediator-server-entity; - } - } - - rpc update-mediator-server { - description - "update entry of entity mediator-server"; - input { - uses mediator-server-entity; - } - output { - uses mediator-server-entity; - } - } - - rpc delete-mediator-server { - description - "delete entry of entity mediator-server"; - input { - uses mediator-server-entity; - } - } - - rpc read-network-element-connection-list { - description - "Get list of networkelement-connections according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses network-element-connection-entity; - description - "The output data as list of found network-element (or mountpoint, - or network functions) connection entities."; - } - } - } - - rpc create-network-element-connection { - description - "create entry in networkelement-connection"; - input { - uses network-element-connection-entity; - } - output { - uses network-element-connection-entity; - } - } - - rpc update-network-element-connection { - description - "Put an element to ne-entity"; - input { - uses network-element-connection-entity; - } - output { - uses network-element-connection-entity; - } - } - - rpc delete-network-element-connection { - description - "!ONLY FOR TESTING! Put an element to ne-entity"; - input { - uses network-element-connection-entity; - } - } - - rpc read-pmdata-15m-ltp-list { - description - "Get list of ltps for one mountpoint with historical pmdata"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - leaf-list data { - type string; - description - "The list of found mountpoint names."; - } - } - } - - rpc read-pmdata-24h-ltp-list { - description - "Get list of ltps for one mountpoint with historical pmdata"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - leaf-list data { - type string; - description - "The list of found logical-termination-point identifiers."; - } - } - } - - rpc read-pmdata-15m-device-list { - description - "Get list of mountpoints with historical pmdata"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - leaf-list data { - type string; - description - "The list of found mountpoint names."; - } - } - } - - rpc read-pmdata-24h-device-list { - description - "Get list of mountpoints with historical pmdata"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - leaf-list data { - type string; - description - "The list of found mountpoint names."; - } - } - } - - rpc read-pmdata-15m-list { - description - "Get list of entities according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses pmdata15m-entity; - description - "The output data as list of 15 minutes performance monitoring - entities."; - } - } - } - - rpc read-pmdata-24h-list { - description - "Get list of historical pmdata according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses pmdata24h-entity; - description - "The output data as list of 24 hours performance monitoring - entities."; - } - } - } - - rpc read-inventory-list { - description - "Get list of inventory according to filter"; - input { - uses entity-input; - } - output { - container pagination { - uses pagination-output-g; - description - "The pagination details used by the provider to filter the data."; - } - list data { - uses inventory-entity; - description - "The output data as list of inventory entities."; - } - } - } - - rpc read-status { - description - "Read status information of controller"; - output { - list data { - uses status-entity; - description - "The output data as list of status entities."; - } - } - } -} diff --git a/sdnr/wt/data-provider/model/src/main/yang/data-provider@2019-08-01.yang b/sdnr/wt/data-provider/model/src/main/yang/data-provider@2019-08-01.yang new file mode 100644 index 000000000..46505cd8f --- /dev/null +++ b/sdnr/wt/data-provider/model/src/main/yang/data-provider@2019-08-01.yang @@ -0,0 +1,1674 @@ +module data-provider { + + yang-version 1.1; + namespace "urn:opendaylight:params:xml:ns:yang:data-provider"; + prefix odluxprovider; + + import ietf-yang-types { + prefix yang; + reference + "RFC 6991: Common YANG Data Types."; + } + + organization + "highstreet technologies GmbH"; + contact + "Web: + ONAP: "; + + description + "This module defines the API for the data-provider component. + + Copyright 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."; + + revision 2019-08-01 { + description + "Initial revision"; + reference + "https://jira.onap.org/browse/SDNC-879"; + } + + // --- typedef + + typedef Entity { + type enumeration { + enum connectionlog { + description + "logs mountpoint connection state changes"; + } + enum faultcurrent { + description + "current faults"; + } + enum eventlog { + description + "logs for all notifications e.g. NetConf, ves and internal events"; + } + enum faultlog { + description + "faultlog information"; + } + enum historicalperformance15min { + description + "performance data"; + } + enum historicalperformance24h { + description + "performance data"; + } + enum mediator-server { + description + "list of mediator servers"; + } + enum networkelement-connection { + description + "list of mountpoints for NetConf devices (joint required-network-element+mdsal + state"; + } + enum inventoryequipment { + description + "list of equipment inventory"; + } + enum maintenancemode { + description + "list of maintenance setting"; + } + } + description + "Data type and alias for elasticsearch or table name for SQL database."; + } + + typedef SortOrder { + type enumeration { + enum ascending { + description + "Self explaining."; + } + enum descending { + description + "Self explaining."; + } + } + description + "Entities for odlux clients"; + } + + typedef FilterProperty { + type string; + description + "A string type describing a property (attribute, column, parameter) + filter"; + } + + typedef NotificationType { + type enumeration { + enum ProblemNotificationXml { + description + "A fault (alarm, problem) notification type in XML format."; + } + enum AttributeValueChangedNotificationXml { + description + "An attribute value change notification type in XML format."; + } + } + description + "An enumeration describing the found notification type."; + } + + typedef ConnectionLogStatus { + type enumeration { + enum Mounted { + description + "Mountpoint created"; + } + enum Unmounted { + description + "Mountpoint removed"; + } + enum Connecting { + description + "Mountpoint establishing connection"; + } + enum Connected { + description + "Mountpoint connection established"; + } + enum UnableToConnect { + description + "Mountpoint connection not possible"; + } + enum Disconnected { + description + "Required and mountpoint removed"; + } + enum Undefined { + description + "Status not available"; + } + } + description + "An enumeration describing connection states."; + } + + typedef NetworkElementDeviceType { + type enumeration { + enum Wireless { + description + "implements microwave-model.yang or air-interface.yang"; + } + enum RAN { + description + "implements sth. like o-ran*.yang"; + } + enum ORAN { + description + "implements RAN according to o-ran*.yang"; + } + enum RAN3GPP { + description + "implements RAN according to _3gpp-ran*.yang"; + } + enum Optical { + description + "implements tapi-*.yang or org-openroadm*.yang"; + } + enum Router { + description + "implements vlan-interface.yang"; + } + enum NtsManager { + description + "Manage adapter to simulate devices"; + } + enum Nonsupported { + description + "Device type known, but not support"; + } + enum Unknown { + description + "Device type at this point of time unknown"; + } + enum O-RAN-FH { + description + "implements RAN according to o-ran*.yang fro for fronthaule"; + } + enum O-ROADM { + description + "implements Open ROADM"; + } + enum O1-TR069 { + description + "implements O1 RAN interface according to TR069"; + } + } + description + "An enumeration as identification of the device."; + } + + typedef severity-type { + type enumeration { + enum NonAlarmed { + description + "problem cleared indication"; + } + enum Warning { + description + "problem level"; + } + enum Minor { + description + "problem level"; + } + enum Major { + description + "problem level"; + } + enum Critical { + description + "problem level"; + } + } + description + "According to ITU-T M.3160"; + } + + typedef source-type { + type enumeration { + enum Ves { + description + "VES Interface"; + } + enum Netconf { + description + "NetConf Interface"; + } + enum Controller { + description + "SDN Controller"; + } + enum Unknown { + description + "Unknown source"; + } + } + description + "An enumeration for the information source of an event/notification."; + } + + typedef granularity-period-type { + type enumeration { + enum unknown { + description + "none"; + } + enum period-15-min { + description + "none"; + } + enum period-24-hours { + description + "none"; + } + } + description + "The enumeration with the options for granularity period of the + performance data similar to g.874.1-model"; + } + + // --- grouping and builder-container + + grouping connectionlog-entity { + leaf id { + type string; + description + "database id"; + } + leaf node-id { + type string; + description + "the node/mountpoint which connection state has changed"; + } + leaf timestamp { + type yang:date-and-time; + description + "timestamp when event happened, preferred in UTC time format."; + } + leaf status { + type ConnectionLogStatus; + description + "new state of the connection of the device"; + } + description + "An object class describing an entry in the connection status log."; + } + + container connectionlog { + description + "builder"; + uses connectionlog-entity; + } + + grouping object-change-reference { + description + "Reference of of object (e.g. Interface pack) owned by a node"; + leaf node-id { + type string; + description + "A network wide unique identifier of the NetConf server."; + } + leaf counter { + type int32; + description + "An arbitrary counter value."; + } + leaf timestamp { + type yang:date-and-time; + description + "The time of the reported change, preferred in UTC time format. "; + } + leaf object-id { + type string; + description + "The identifier of the reporting object (resource)."; + } + } + + grouping source-reference { + description + "Identify a source"; + leaf source-type { + type source-type; + description + "The source type."; + } + } + + grouping fault { + description + "Fault event of an object"; + leaf problem { + type string; + description + "The alarm type identifier."; + } + leaf severity { + type severity-type; + description + "The reported severity of the fault (alarm)."; + } + } + + grouping attribute-change { + description + "update change of an attribute"; + leaf attribute-name { + type string; + description + "The attribute name which was changed."; + } + leaf new-value { + type string; + description + "The new value of the attribute converted to a string format."; + } + } + + grouping entity-id { + description + "Unique database id of entity"; + leaf id { + type string; + description + "The unique identifier of the entity."; + } + } + + grouping faultcurrent-entity { + description + "Current fault status"; + uses object-change-reference; + uses fault; + uses entity-id; + } + + container faultcurrent { + description + "builder"; + uses faultcurrent-entity; + } + + grouping faultlog-entity { + description + "Changed fault indication"; + uses source-reference; + uses object-change-reference; + uses fault; + uses entity-id; + } + + container faultlog { + description + "builder"; + uses faultlog-entity; + } + + grouping eventlog-entity { + description + "One change event of devices"; + uses source-reference; + uses object-change-reference; + uses attribute-change; + uses entity-id; + } + + container eventlog { + description + "builder"; + uses eventlog-entity; + } + + grouping filter { + leaf description { + type string; + description + "Filter specific description"; + } + leaf start { + type yang:date-and-time; + description + "begin of maintenance-mode"; + } + leaf end { + type yang:date-and-time; + description + "end of maintenance-mode"; + } + leaf object-id-ref { + type string; + description + "object id to filter on, or empty for all"; + } + leaf problem { + type string; + description + "name of the problem to filter or empty for all"; + } + description + "An object class describing a generic filter of an interval for + faults (alarms)."; + } + + grouping maintenance-entity { + description + "Maintenance mode for a device. "; + leaf id { + type string; + mandatory true; + description + "Key to get/set configuration entry in database. Normally Mountpoint + name is used as key id of node."; + } + leaf node-id { + type string; + mandatory true; + description + "A network wide unique identifier of the NetConf server."; + } + leaf active { + type boolean; + description + "Configuration to activate or deactivate this entry"; + } + uses filter; + } + + container maintenance { + presence "false"; + description + "builder"; + uses maintenance-entity; + } + + grouping mediator-server-entity { + leaf id { + type string; + mandatory true; + description + "A network unique identifier of the mediator server."; + } + leaf url { + type string; + description + "The ULR to reach the REST interface of the mediator server."; + } + leaf name { + type string; + description + "A human readable name of the mediator server."; + } + description + "An object class describing a mediator server entity."; + } + + grouping pmdata-base { + description + "Performance data base information"; + leaf node-name { + type string; + description + "A network unique identifier of reporting NetConf server."; + } + leaf uuid-interface { + type string; + description + "A universal unique identifier of the performance monitoring point."; + } + leaf layer-protocol-name { + type string; + description + "The name of the measured transport layer."; + } + leaf radio-signal-id { + type string; + description + "The value exists only of wireless transport devices."; + } + leaf time-stamp { + type yang:date-and-time; + description + "The time-stamp of the measurement, preferred in UTC format."; + } + leaf suspect-interval-flag { + type boolean; + description + "If false, the measurement is not completed and should not be used + for performance analysis. "; + } + leaf granularity-period { + type granularity-period-type; + description + "The expected measurement interval."; + } + leaf scanner-id { + type string; + description + "See ITU-T X.739 chapter 8.1.1.2."; + } + } + + grouping pmdata-microwave { + description + "Consolidated performance information of all microwave model interface + PACs"; + leaf es { + type int32; + units "s"; + default "-1"; + config false; + description + "Number of errored seconds."; + } + leaf ses { + type int32; + units "s"; + default "-1"; + config false; + description + "Number of severely errored seconds."; + } + leaf cses { + type int32; + units "s"; + default "-1"; + config false; + description + "Number of consecutive severely errored seconds."; + } + leaf unavailability { + type int32; + units "s"; + default "-1"; + config false; + description + "Total time of unavailability in seconds."; + } + leaf tx-level-min { + type int8; + units "dBm"; + default "99"; + config false; + description + "Minimum transmit power. Signed integers are required."; + } + leaf tx-level-max { + type int8; + units "dBm"; + default "99"; + config false; + description + "Maximum transmit power. Signed integers are required."; + } + leaf tx-level-avg { + type int8; + units "dBm"; + default "99"; + config false; + description + "Averaged transmit power. Signed integers are required."; + } + leaf rx-level-min { + type int8; + units "dBm"; + default "99"; + config false; + description + "Minimum receive level. Signed integers are required."; + } + leaf rx-level-max { + type int8; + units "dBm"; + default "99"; + config false; + description + "Maximum receive level. Signed integers are required."; + } + leaf rx-level-avg { + type int8; + units "dBm"; + default "99"; + config false; + description + "Averaged receive level. Signed integers are required."; + } + leaf time2-states { + type int32; + units "s"; + default "-1"; + config false; + description + "Sum of all seconds the transmitter operated in e.g. BPSK."; + } + leaf time4-states-s { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time4-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time8-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time16-states-s { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time16-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time32-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time64-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time128-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time256-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time512-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time512-states-l { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time1024-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time1024-states-l { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time2048-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time2048-states-l { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time4096-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time4096-states-l { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time8192-states { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf time8192-states-l { + type int32; + units "s"; + default "-1"; + config false; + description + "none"; + } + leaf snir-min { + type int8; + units "dB"; + default "-99"; + config false; + description + "Minimum signal to (noise+interference) ratio."; + } + leaf snir-max { + type int8; + units "dB"; + default "-99"; + config false; + description + "Maximum signal to (noise+interference) ratio."; + } + leaf snir-avg { + type int8; + units "dB"; + default "-99"; + config false; + description + "Averaged signal to (noise+interference) ratio."; + } + leaf xpd-min { + type int8; + units "dB"; + default "-99"; + config false; + description + "Minimum cross polarization discrimination."; + } + leaf xpd-max { + type int8; + units "dB"; + default "-99"; + config false; + description + "Maximum cross polarization discrimination."; + } + leaf xpd-avg { + type int8; + units "dB"; + default "-99"; + config false; + description + "Averaged cross polarization discrimination."; + } + leaf rf-temp-min { + type int8; + units "C"; + default "-99"; + config false; + description + "Lowest temperature (in degree Celsius) of the radio module inside the + outdoor unit."; + } + leaf rf-temp-max { + type int8; + units "C"; + default "-99"; + config false; + description + "Highest temperature (in degree Celsius) of the radio module inside the + outdoor unit."; + } + leaf rf-temp-avg { + type int8; + units "C"; + default "-99"; + config false; + description + "Averaged temperature (in degree Celsius) of the radio module inside + the outdoor unit."; + } + leaf defect-blocks-sum { + type int16; + units "blocks"; + default "-1"; + config false; + description + "Total number of blocks that were defect after receiving and could not + be corrected by the FEC."; + } + leaf time-period { + type int32; + units "s"; + default "-1"; + config false; + description + "Total length of the measurement period."; + } + } + + grouping pmdata-ethernet { + description + "Consolidated performance information for Ethernet."; + leaf tx-ethernet-bytes-max-s { + type int32; + units "Bytes/s"; + default "-1"; + config false; + description + "Counts the number of Bytes of Ethernet traffic (before header + compression) transmitted within a second and keeps the highest value + within the measurement period. Field to be left blank for all types of + TDM containers."; + } + leaf tx-ethernet-bytes-max-m { + type int64; + units "Bytes/min"; + default "-1"; + config false; + description + "Counts the number of Bytes of Ethernet traffic (before header + compression) transmitted within a minute and keeps the highest value + with in the measurement period. Field to be left blank for all types + of TDM containers."; + } + leaf tx-ethernet-bytes-sum { + type int64; + units "Bytes"; + default "-1"; + config false; + description + "Total number of Bytes of Ethernet traffic (before header compression) + transmitted (in direction out of the device) during the measurement + period. Field to be left blank for all types of TDM containers."; + } + } + + container pmdata-entity { + description + "builder"; + uses pmdata-base; + container performance-data { + uses pmdata-microwave; + uses pmdata-ethernet; + description + "An object combining different performance monitoring data."; + } + } + + grouping pmdata15m-entity { + uses pmdata-base; + container performance-data { + uses pmdata-microwave; + uses pmdata-ethernet; + description + "An object combining different performance monitoring data."; + } + description + "An object class describing a 15 minute performance monitoring entity."; + } + + grouping pmdata24h-entity { + uses pmdata-base; + container performance-data { + uses pmdata-microwave; + uses pmdata-ethernet; + description + "An object combining different performance monitoring data."; + } + description + "An object class describing a 24 hour performance monitoring entity."; + } + + grouping inventory-entity { + description + "One equipment entity in a list of a network element that could be rack, + card, backplane, module"; + leaf id { + type string; + mandatory true; + description + "Unique database id, node-id/uuid"; + } + leaf tree-level { + type uint32; + description + "Containment level, starting with 0.."; + } + leaf parent-uuid { + type string; + description + "Unique inventory id of holder"; + } + leaf node-id { + type string; + description + "Unique node id of network element"; + } + leaf uuid { + type string; + description + "Unique inventory id of this node for this equipment, provided by + network element"; + } + leaf-list contained-holder { + type string; + description + "List of uuid of contained equipment"; + } + leaf manufacturer-name { + type string; + description + "manufactured-thing/manufacturer-properties/manufacturer-name"; + } + leaf manufacturer-identifier { + type string; + description + "manufactured-thing/manufacturer-properties/manufacturer-identifier"; + } + leaf serial { + type string; + description + "manufactured-thing/equipment-instance/serial"; + } + leaf date { + type string; + description + "manufactured-thing/equipment-instance/manufacture-date: Date + information provided by manufacturer. No specific format. ()"; + } + leaf version { + type string; + description + "manufactured-thing/equipment-type/version"; + } + leaf description { + type string; + description + "manufactured-thing/equipment-type/description"; + } + leaf part-type-id { + type string; + description + "manufactured-thing/equipment-type/part-type-identifier"; + } + leaf model-identifier { + type string; + description + "manufactured-thing/equipment-type/model-identifier"; + } + leaf type-name { + type string; + description + "manufactured-thing/equipment-type/type-name"; + } + } + + container inventory { + presence "false"; + description + "builder"; + uses inventory-entity; + } + + grouping node-details-g { + leaf-list available-capabilities { + type string; + description + "The list of available yang capabilities."; + } + leaf-list unavailable-capabilities { + type string; + description + "The list of unavailable yang capabilities."; + } + description + "An object class description the available and unavailable yang + capabilities."; + } + + grouping network-element-connection-entity { + leaf id { + type string; + description + "database id/key. here is equal to node-id"; + } + leaf node-id { + type string; + description + "mountpoint name of device in controller"; + } + leaf host { + type string; + description + "NetConf server host name or IP address of device"; + } + leaf port { + type uint32; + description + "NetConf port of device"; + } + leaf username { + type string; + description + "NetConf user name"; + } + leaf password { + type string; + description + "NetConf password. should be removed asap"; + } + leaf core-model-capability { + type string; + description + "revision of core-model capability"; + } + leaf device-type { + type NetworkElementDeviceType; + description + "categorized type of device based on implemented yang specs"; + } + leaf is-required { + type boolean; + description + "entry exists in db index required-networkelement"; + } + container node-details { + uses node-details-g; + description + "holder of available and unavailable capabilities"; + } + leaf status { + type ConnectionLogStatus; + description + "current connection status. default Disconnected"; + } + description + "An object class defining the NetConf connection towards a + NetConf server. "; + } + + container network-element-connection { + description + "builder"; + uses network-element-connection-entity; + } + + grouping status-entity { + container faults { + leaf criticals { + type uint32; + description + "The number of current faults (active alarms) with severity + 'critical'."; + } + leaf majors { + type uint32; + description + "The number of current faults (active alarms) with severity + 'major'."; + } + leaf minors { + type uint32; + description + "The number of current faults (active alarms) with severity + 'minor'."; + } + leaf warnings { + type uint32; + description + "The number of current faults (active alarms) with severity + 'warning'."; + } + description + "An object containing the number of current faults per its severity."; + } + description + "An object class defining an status entity for current faults + (also called active alarms)."; + } + + container status { + description + "builder"; + uses status-entity; + } + + grouping entity-input { + list filter { + key "property"; + leaf property { + type string; + description + "The property (parameter, column, field) identifier."; + } + leaf filtervalue { + type string; + description + "The filter information for the corresponding property."; + } + description + "List with filter criteria. Not listed means all."; + } + list sortorder { + key "property"; + leaf property { + type string; + description + "The property (parameter, column, field) identifier."; + } + leaf sortorder { + type SortOrder; + description + "The definition of the sort order for the corresponding property."; + } + description + "List with sort order. Not listed means default"; + } + container pagination { + leaf size { + type uint32 { + range "1..max"; + } + default "20"; + description + "Number of entries to be delivered"; + } + leaf page { + type uint64 { + range "1..max"; + } + default "1"; + description + "Number to be used to calculate starting entry to deliver"; + } + description + "An object defining the pagination details."; + } + description + "An object class defining a request input entity."; + } + + grouping pagination-output-g { + leaf size { + type uint32 { + range "1..max"; + } + default "20"; + description + "Number of entries to be delivered"; + } + leaf page { + type uint64 { + range "1..max"; + } + default "1"; + description + "Number to be used to calculate starting entry to deliver"; + } + leaf total { + type uint64 { + range "0..max"; + } + default "0"; + description + "Number to be used to calculate starting entry to deliver"; + } + description + "An object class defining the filter information for pagination."; + } + + container pagination-output { + description + "builder"; + uses pagination-output-g; + } + + // --- rpc + + rpc read-faultcurrent-list { + description + "Get list of current fault (active alarm) entries according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses faultcurrent-entity; + description + "The output data as list of current fault (or active alarm) + entities."; + } + } + } + + rpc read-faultlog-list { + description + "Get list of faultlog entries according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses faultlog-entity; + description + "The output data as list of fault entities."; + } + } + } + + rpc read-eventlog-list { + description + "Get list of event log entities according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses eventlog-entity; + description + "The output data as list of event log entities."; + } + } + } + + rpc read-connectionlog-list { + description + "Get list of event log entities according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses connectionlog-entity; + description + "The output data as list of connection log entities."; + } + } + } + + rpc read-maintenance-list { + description + "Get list of maintenance entries according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses maintenance-entity; + description + "The output data as list of maintenance entities."; + } + } + } + + rpc create-maintenance { + description + "insert new entry of maintenance"; + input { + uses maintenance-entity; + } + output { + uses maintenance-entity; + } + } + + rpc update-maintenance { + description + "update existing entity of maintenance"; + input { + uses maintenance-entity; + } + output { + uses maintenance-entity; + } + } + + rpc delete-maintenance { + description + "delete entity of maintenance"; + input { + uses maintenance-entity; + } + } + + rpc read-mediator-server-list { + description + "Get list of mediator-servers according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses mediator-server-entity; + description + "The list of found mediator server entities."; + } + } + } + + rpc create-mediator-server { + description + "create new entry of entity mediator-server"; + input { + uses mediator-server-entity; + } + output { + uses mediator-server-entity; + } + } + + rpc update-mediator-server { + description + "update entry of entity mediator-server"; + input { + uses mediator-server-entity; + } + output { + uses mediator-server-entity; + } + } + + rpc delete-mediator-server { + description + "delete entry of entity mediator-server"; + input { + uses mediator-server-entity; + } + } + + rpc read-network-element-connection-list { + description + "Get list of networkelement-connections according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses network-element-connection-entity; + description + "The output data as list of found network-element (or mountpoint, + or network functions) connection entities."; + } + } + } + + rpc create-network-element-connection { + description + "create entry in networkelement-connection"; + input { + uses network-element-connection-entity; + } + output { + uses network-element-connection-entity; + } + } + + rpc update-network-element-connection { + description + "Put an element to ne-entity"; + input { + uses network-element-connection-entity; + } + output { + uses network-element-connection-entity; + } + } + + rpc delete-network-element-connection { + description + "!ONLY FOR TESTING! Put an element to ne-entity"; + input { + uses network-element-connection-entity; + } + } + + rpc read-pmdata-15m-ltp-list { + description + "Get list of ltps for one mountpoint with historical pmdata"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + leaf-list data { + type string; + description + "The list of found mountpoint names."; + } + } + } + + rpc read-pmdata-24h-ltp-list { + description + "Get list of ltps for one mountpoint with historical pmdata"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + leaf-list data { + type string; + description + "The list of found logical-termination-point identifiers."; + } + } + } + + rpc read-pmdata-15m-device-list { + description + "Get list of mountpoints with historical pmdata"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + leaf-list data { + type string; + description + "The list of found mountpoint names."; + } + } + } + + rpc read-pmdata-24h-device-list { + description + "Get list of mountpoints with historical pmdata"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + leaf-list data { + type string; + description + "The list of found mountpoint names."; + } + } + } + + rpc read-pmdata-15m-list { + description + "Get list of entities according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses pmdata15m-entity; + description + "The output data as list of 15 minutes performance monitoring + entities."; + } + } + } + + rpc read-pmdata-24h-list { + description + "Get list of historical pmdata according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses pmdata24h-entity; + description + "The output data as list of 24 hours performance monitoring + entities."; + } + } + } + + rpc read-inventory-list { + description + "Get list of inventory according to filter"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + list data { + uses inventory-entity; + description + "The output data as list of inventory entities."; + } + } + } + + rpc read-status { + description + "Read status information of controller"; + output { + list data { + uses status-entity; + description + "The output data as list of status entities."; + } + } + } +} diff --git a/sdnr/wt/data-provider/provider/pom.xml b/sdnr/wt/data-provider/provider/pom.xml index 0d133f8d4..9e158abf1 100644 --- a/sdnr/wt/data-provider/provider/pom.xml +++ b/sdnr/wt/data-provider/provider/pom.xml @@ -47,12 +47,11 @@ - true true yyyy-MM-dd HH:mm ${maven.build.timestamp} 49402 - 52.3b24c2d(20/04/08) + 56.139cd6d(20/07/08) @@ -91,6 +90,11 @@ org.apache.karaf.shell.core provided + + + + + org.opendaylight.netconf sal-netconf-connector @@ -146,9 +150,11 @@ java -jar - ${basedir}/../setup/target/sdnr-dmt.jar + ${basedir}/../../data-provider/setup/target/sdnr-dmt.jar -c pluginfile + -v + v3 -of ${project.build.directory}/EsInit.script @@ -165,7 +171,7 @@ testCluster 9500 ${databaseport} - 6.5.0 + 7.1.1 120 ${project.build.directory}/EsInit.script 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 index 3fe2a62af..c3c63a963 100644 --- 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 @@ -24,38 +24,35 @@ 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.EsDataObjectReaderWriter; +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 EsDataObjectReaderWriter { +public class DataObjectAcessor extends EsDataObjectReaderWriter2 { private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessor.class); - public DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class clazz) throws ClassNotFoundException { - this(dbClient, entity, clazz, true); + DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class clazz) throws ClassNotFoundException { + super(dbClient, entity, clazz); LOG.info("Create {}", this.getClass().getName()); } - public DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class clazz, boolean idSupported) - throws ClassNotFoundException { - super(dbClient, entity, clazz); - if (idSupported) { - setEsIdAttributeName("_id"); - } - } + public QueryResult getData(EntityInput input) { - QueryResult getData(EntityInput input) { - long page = QueryByFilter.getPage(input); - long pageSize = QueryByFilter.getPageSize(input); - LOG.info("Request: {}", this.getDataTypeName()); - QueryBuilder query = QueryByFilter.fromFilter(input.getFilter()).from((page - 1) * pageSize).size(pageSize); - QueryByFilter.setSortOrder(query, input.getSortorder()); - SearchResult result = doReadAll(query, query.contains("range")); - return new QueryResult<>(page, pageSize, result); + 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 index 8eb51b6aa..83017366d 100644 --- 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 @@ -26,16 +26,11 @@ 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.QueryBuilder; -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.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.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +44,7 @@ public class DataObjectAcessorPm extends DataObjectAcessor private static final String KEY = "node-name"; - enum Intervall { + public enum Intervall { PMDATA15M("historicalperformance15min", "historicalperformance15min"), PMDATA24H("historicalperformance24h", "historicalperformance24h"); @@ -75,7 +70,8 @@ public class DataObjectAcessorPm extends DataObjectAcessor public DataObjectAcessorPm(HtDatabaseClient dbClient, Intervall mode, Entity entity, Class clazz) throws ClassNotFoundException { - super(dbClient, entity, clazz, false); + super(dbClient, entity, clazz); + LOG.info("DataObjectAcessorPm"); this.dbClient = dbClient; this.mode = mode; } @@ -87,47 +83,24 @@ public class DataObjectAcessorPm extends DataObjectAcessor * @return * @throws IOException */ - QueryResult getDataLtpList(EntityInput input) throws IOException { - long page = QueryByFilter.getPage(input); - long pageSize = QueryByFilter.getPageSize(input); - Filter nodeFilter = QueryByFilter.getFilter(input.getFilter(), NODE_KEY); - if (nodeFilter != null) { - SearchRequest request = new SearchRequest(mode.getIndex(), mode.getType()); - request.setQuery( - QueryBuilders.matchQuery(NODE_KEY, nodeFilter.getFiltervalue()).aggregations(UUID_KEY).size(0)); - try { - SearchResponse response = this.dbClient.search(request); - AggregationEntries aggs = response.getAggregations(UUID_KEY); - String[] uuids = aggs.getKeysAsPagedStringList(pageSize, pageSize * (page - 1)); - long totalSize = aggs.size(); - return new QueryResult(page, pageSize, new SearchResult(uuids, totalSize)); - } catch (IOException e) { - throw new IOException("problem reading ltps for req=" + request, e); - } - } else { - String msg = "no nodename in filter found "; - LOG.debug(msg); - throw new IllegalArgumentException(msg); + 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); } } - // QueryResult getDataDeviceList(EntityInput input) throws IOException { - // - // long page = QueryByFilter.getPage(input); - // long pageSize = QueryByFilter.getPageSize(input); - // - // SearchRequest request = new SearchRequest(mode.getIndex(), mode.getType()); - // request.setQuery(QueryBuilders.matchAllQuery().aggregations(KEY).size(0)); - //// try { - // SearchResponse response = this.dbClient.search(request); - // AggregationEntries aggs = response.getAggregations(KEY); - // String[] uuids = aggs.getKeysAsPagedStringList(pageSize, pageSize * (page - 1)); - // long totalSize = aggs.size(); - // return new QueryResult(page, pageSize, new SearchResult(uuids, totalSize)); - //// } catch (IOException e) { - //// throw new IOException("problem reading nodes for req="+request, e); - //// } - // } /** * get aggregated devices list * @@ -135,31 +108,19 @@ public class DataObjectAcessorPm extends DataObjectAcessor * @return * @throws IOException */ - QueryResult getDataDeviceList(EntityInput input) throws IOException { - - long page = QueryByFilter.getPage(input); - long pageSize = QueryByFilter.getPageSize(input); - - Sortorder soNode = QueryByFilter.getSortOrder(input.getSortorder(), KEY); - SearchRequest request = new SearchRequest(mode.getIndex(), mode.getType()); - QueryBuilder query = null; - if (soNode != null) { - query = QueryBuilders.matchAllQuery() - .aggregations(KEY, - soNode.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) - .size(0); - } else { - query = QueryBuilders.matchAllQuery().aggregations(KEY).size(0); - } - request.setQuery(query); + 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(pageSize, pageSize * (page - 1)); + String[] uuids = + aggs.getKeysAsPagedStringList(queryByFilter.getPageSize(), queryByFilter.getPageStartIndex()); long totalSize = aggs.size(); - return new QueryResult(page, pageSize, new SearchResult(uuids, totalSize)); + 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 index 4dd52f43a..1fa6de37d 100644 --- 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 @@ -43,12 +43,12 @@ public class DataObjectAcessorStatus extends DataObjectAcessor { private final Entity entity; public DataObjectAcessorStatus(HtDatabaseClient dbClient, Entity entity) throws ClassNotFoundException { - super(dbClient, entity, Data.class, false); + super(dbClient, entity, Data.class); this.dbClient = dbClient; this.entity = entity; } - QueryResult getDataStatus() throws IOException { + 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); 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 new file mode 100644 index 000000000..10dd7792c --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataObjectAcessorWithId.java @@ -0,0 +1,41 @@ +/* + * ============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/DataTreeChildObject.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataTreeChildObject.java deleted file mode 100644 index a92265a84..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataTreeChildObject.java +++ /dev/null @@ -1,46 +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.Map; - -/** - * @author Michael Dürre - * - */ -public class DataTreeChildObject { - - private final String label; - private final String ownSeverity; - private final String childrenSeveritySummary; - private final boolean isMatch; - private final Map children; - - public DataTreeChildObject(String label, boolean isMatch, Map children, - String ownSeverity, String childrenSeveritySummary) { - this.label = label; - this.isMatch = isMatch; - this.children = children; - this.ownSeverity = ownSeverity; - this.childrenSeveritySummary = childrenSeveritySummary; - } -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataTreeObject.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataTreeObject.java deleted file mode 100644 index 4333dccb4..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/DataTreeObject.java +++ /dev/null @@ -1,32 +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.HashMap; - -/** - * @author Michael Dürre - * - */ -public class DataTreeObject extends HashMap { - -} 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 76d47e3e0..30e617ab6 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 @@ -77,17 +77,15 @@ public class ElasticSearchDataProvider /*extends BaseStatusProvider /* implement private static final String EXCEPTION_UNABLE_TO_UPDATE_IN_DATABASE = "unable to update data in database"; private static final String EXCEPTION_UNABLE_TO_REMOVE_FROM_DATABASE = "unable to remove data from database"; - private static final boolean DEFAULT_TRUSTALLCERTS = false; - private final HtDatabaseClient dbClient; - private final DataObjectAcessor eventRWFaultCurrent; - private final DataObjectAcessor eventRWFaultLog; - private final DataObjectAcessor mediatorserverRW; - private final DataObjectAcessor maintenanceRW; - private final DataObjectAcessor equipmentRW; - private final DataObjectAcessor connnectionlogRW; - private final DataObjectAcessor eventlogRW; - private final DataObjectAcessor networkelementConnectionRW; + private final DataObjectAcessorWithId eventRWFaultCurrent; + private final DataObjectAcessorWithId eventRWFaultLog; + private final DataObjectAcessorWithId mediatorserverRW; + private final DataObjectAcessorWithId maintenanceRW; + private final DataObjectAcessorWithId equipmentRW; + private final DataObjectAcessorWithId connnectionlogRW; + private final DataObjectAcessorWithId eventlogRW; + private final DataObjectAcessorWithId networkelementConnectionRW; private final DataObjectAcessorPm pm15mRW; private final DataObjectAcessorPm pm24hRW; @@ -100,7 +98,7 @@ public class ElasticSearchDataProvider /*extends BaseStatusProvider /* implement } public ElasticSearchDataProvider(HostInfo[] hosts) throws Exception { - this(hosts, null, null, DEFAULT_TRUSTALLCERTS); + this(hosts, null, null, HtDatabaseClient.TRUSTALL_DEFAULT); } public ElasticSearchDataProvider(HostInfo[] hosts, String authUsername, String authPassword, boolean trustAllCerts) @@ -108,31 +106,32 @@ public class ElasticSearchDataProvider /*extends BaseStatusProvider /* implement super(); LOG.info("Start {}", this.getClass().getName()); + this.dbClient = HtDatabaseClient.getClient(hosts, authUsername, authPassword, trustAllCerts); - this.mediatorserverRW = new DataObjectAcessor<>(dbClient, Entity.MediatorServer, + this.mediatorserverRW = new DataObjectAcessorWithId<>(dbClient, Entity.MediatorServer, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data.class); this.mediatorserverRW.setWriteInterface(MediatorServerEntity.class); - this.maintenanceRW = new DataObjectAcessor<>(dbClient, Entity.Maintenancemode, + this.maintenanceRW = new DataObjectAcessorWithId<>(dbClient, Entity.Maintenancemode, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.maintenance.list.output.Data.class); this.maintenanceRW.setWriteInterface(MaintenanceEntity.class); - this.equipmentRW = new DataObjectAcessor<>(dbClient, Entity.Inventoryequipment, + this.equipmentRW = new DataObjectAcessorWithId<>(dbClient, Entity.Inventoryequipment, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data.class); - this.eventRWFaultCurrent = new DataObjectAcessor<>(dbClient, Entity.Faultcurrent, + this.eventRWFaultCurrent = new DataObjectAcessorWithId<>(dbClient, Entity.Faultcurrent, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.faultcurrent.list.output.Data.class); - this.eventRWFaultLog = new DataObjectAcessor<>(dbClient, Entity.Faultlog, + this.eventRWFaultLog = new DataObjectAcessorWithId<>(dbClient, Entity.Faultlog, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.faultlog.list.output.Data.class); - this.connnectionlogRW = new DataObjectAcessor<>(dbClient, Entity.Connectionlog, + this.connnectionlogRW = new DataObjectAcessorWithId<>(dbClient, Entity.Connectionlog, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.connectionlog.list.output.Data.class); - this.eventlogRW = new DataObjectAcessor<>(dbClient, Entity.Eventlog, + this.eventlogRW = new DataObjectAcessorWithId<>(dbClient, Entity.Eventlog, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.eventlog.list.output.Data.class); - this.networkelementConnectionRW = new DataObjectAcessor<>(dbClient, Entity.NetworkelementConnection, + this.networkelementConnectionRW = new DataObjectAcessorWithId<>(dbClient, Entity.NetworkelementConnection, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.network.element.connection.list.output.Data.class); this.networkelementConnectionRW.setWriteInterface(NetworkElementConnectionEntity.class); 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 index d255cadcd..4efbf6e28 100644 --- 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 @@ -27,6 +27,7 @@ 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; @@ -113,7 +114,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid ConnectionlogEntity.class, ConnectionlogBuilder.class); networkelementConnectionDB = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection, - NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class) + NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true) .setEsIdAttributeName("_id"); pmData15mDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance15min, PmdataEntity.class, @@ -271,15 +272,64 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid // -- 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 void updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy, + public boolean updateNetworkConnectionDeviceType(NetworkElementConnectionEntity networkElementConnectionEntitiy, String nodeId) { - this.networkelementConnectionDB.update(networkElementConnectionEntitiy, nodeId); + return this.networkelementConnectionDB.update(networkElementConnectionEntitiy, nodeId) != null; + // NetworkElementConnectionEntity e = this.networkelementConnectionDB.read(nodeId); + // this.networkelementConnectionDB.write(this.joinNe(e, networkElementConnectionEntitiy), nodeId); } /** @@ -289,10 +339,14 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid * @param nodeId of device (mountpoint name) */ @Override - public void updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy, + public boolean updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy, String nodeId) { - this.networkelementConnectionDB.updateOrCreate(networkElementConnectionEntitiy, nodeId, - Arrays.asList("is-required", "username", "password")); + 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 */ 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 index a675f6876..3e9a93902 100644 --- 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 @@ -46,15 +46,15 @@ public class HtDatabaseMaintenanceService implements HtDatabaseMaintenance { private final EsDataObjectReaderWriter2 maintenanceRW; private final EsDataObjectReaderWriter2 requiredNeRW; - HtDatabaseMaintenanceService(@NonNull HtDatabaseClient client) throws ClassNotFoundException { + public HtDatabaseMaintenanceService(@NonNull HtDatabaseClient client) throws ClassNotFoundException { HtAssert.nonnull(client); // Create control structure maintenanceRW = new EsDataObjectReaderWriter2<>(client, Entity.Maintenancemode, MaintenanceEntity.class, - MaintenanceBuilder.class).setEsIdAttributeName("_id"); + MaintenanceBuilder.class, true).setEsIdAttributeName("_id"); requiredNeRW = new EsDataObjectReaderWriter2<>(client, Entity.NetworkelementConnection, - NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class) + NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true) .setEsIdAttributeName("_id"); } 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 258104db4..c229006ff 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 @@ -40,7 +40,7 @@ public class MediatorServerDataProvider implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(MediatorServerDataProvider.class); private final HtDatabaseClient dbClient; - private final DataObjectAcessor mediatorserverRW; + private final DataObjectAcessorWithId mediatorserverRW; private final int REFRESH_INTERVAL = 60; private final Map entries; private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); @@ -55,7 +55,7 @@ public class MediatorServerDataProvider implements AutoCloseable { LOG.info("Start {}", this.getClass().getName()); this.entries = new HashMap<>(); this.dbClient = HtDatabaseClient.getClient(hosts, authUsername, authPassword); - this.mediatorserverRW = new DataObjectAcessor<>(dbClient, Entity.MediatorServer, Data.class); + 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/ODLVersionLUT.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ODLVersionLUT.java deleted file mode 100644 index 8027fb2c5..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/ODLVersionLUT.java +++ /dev/null @@ -1,64 +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; - -public class ODLVersionLUT { - - public static String getONAPReleaseName(String onapCCSDKVersion, String def) { - if (onapCCSDKVersion == null) { - return def; - } - if (onapCCSDKVersion.startsWith("1.6.")) { - return "ONAP Guillin"; - } - 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"; - } - return def; - } - - public static String getOdlVersion(String onapCCSDKVersion, String def) { - - if (onapCCSDKVersion == null) { - return def; - } - if (onapCCSDKVersion.startsWith("1.6.")) { - return "sodium-SRX (0.11.X)"; - } - 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)"; - } - return def; - } -} 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 index b6a502071..4e7bee9d0 100644 --- 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 @@ -21,6 +21,8 @@ */ 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; @@ -33,11 +35,13 @@ 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; @@ -47,48 +51,130 @@ public class QueryByFilter { private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorPm.class); private static final List timestampValueNames = Arrays.asList("timestamp", "start", "end"); - private QueryByFilter() { - //Hide + 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(""); } - static long getPage(EntityInput input) { - return getPage(input, 1); + public QueryBuilder getQueryBuilderByFilter(String prefix) { + QueryBuilder queryBuilder = fromFilter(filterList, prefix).from(fromPage).size(pageSize); + setSortOrder(queryBuilder, sortOrder, prefix); + return queryBuilder; } - @SuppressWarnings("null") - private static long getPage(EntityInput input, long defaultValue) { - return input.getPagination() != null ? input.getPagination().getPage().longValue() : defaultValue; + 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); + } } - static long getPageSize(EntityInput input) { - return getPageSize(input, 1); + 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; } - @SuppressWarnings("null") - private static long getPageSize(EntityInput input, long defaultValue) { - return input.getPagination() != null ? input.getPagination().getSize().longValue() : defaultValue; + public long getPage() { + return page; } + public long getPageSize() { + return pageSize; + } + + public long getPageStartIndex() { + return fromPage; + } - public static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List sortorder) { - return setSortOrder(query, sortorder, ""); + @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((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); + 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; + }; - public static Sortorder getSortOrder(@Nullable List list, String prop) { + private static Sortorder getSortOrder(@Nullable List list, String prop) { if (list == null) { return null; } @@ -100,7 +186,7 @@ public class QueryByFilter { return null; } - public static Filter getFilter(@Nullable List list, String prop) { + private static Filter getFilter(@Nullable List list, String prop) { if (list == null) { return null; } @@ -112,10 +198,6 @@ public class QueryByFilter { 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"; @@ -176,7 +258,7 @@ public class QueryByFilter { 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*) + case 6: // switch 10 months (2000-0* or 2000-1*) tmpvalue = c.get(Calendar.MONTH); if (tmpvalue < 9) { c.set(Calendar.MONTH, 9); @@ -187,7 +269,7 @@ public class QueryByFilter { upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); break; - case 7: //switch one month (2018-01* or 2018-01-*) + case 7: // switch one month (2018-01* or 2018-01-*) case 8: c.add(Calendar.MONTH, 1); upperEnd = converter.getTimeStampAsNetconfString(c.getTime()); @@ -287,14 +369,14 @@ public class QueryByFilter { } else if (DbFilter.isComparisonValid(v)) { - RangeQueryBuilder q = DbFilter.getRangeQuery((prefix != null ? prefix : "") + p, v); + RangeQueryBuilder q = DbFilter.getRangeQuery(handlePrefix(prefix, p), v); if (q != null) { return q; } else { - return QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v); + return QueryBuilders.matchQuery(handlePrefix(prefix, p), v); } } else { - return QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v); + return QueryBuilders.matchQuery(handlePrefix(prefix, p), v); } } else { BoolQueryBuilder query = new BoolQueryBuilder(); @@ -313,22 +395,20 @@ public class QueryByFilter { if (tmpQuery != null) { query.must(tmpQuery); } else { - query.must(QueryBuilders.regex((prefix != null ? prefix : "") + p, - DbFilter.createDatabaseRegex(v))); + query.must(QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v))); } } else { - query.must(QueryBuilders.regex((prefix != null ? prefix : "") + p, - DbFilter.createDatabaseRegex(v))); + query.must(QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v))); } } else if (DbFilter.isComparisonValid(v)) { - RangeQueryBuilder q = DbFilter.getRangeQuery((prefix != null ? prefix : "") + p, v); + RangeQueryBuilder q = DbFilter.getRangeQuery(handlePrefix(prefix, p), v); if (q != null) { query.must(q); } else { - query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v)); + query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v)); } } else { - query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + p, v)); + query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v)); } } LOG.trace("Query result. {}", query.toJSON()); @@ -336,4 +416,8 @@ public class QueryByFilter { } } + 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 new file mode 100644 index 000000000..4abe65856 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/QueryByFilterStatic.java @@ -0,0 +1,336 @@ +/* + * ============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 index 61e524192..7570523cd 100644 --- 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 @@ -42,11 +42,22 @@ public class QueryResult { 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; } - PaginationOutputG getPagination() { + public PaginationOutputG getPagination() { return pagination; } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java deleted file mode 100644 index 9b8806ab8..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/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.data; - -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/database/EsDataObjectReaderWriter.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java deleted file mode 100644 index c0518c664..000000000 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java +++ /dev/null @@ -1,357 +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.database; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.onap.ccsdk.features.sdnr.wt.common.database.DatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; -import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; -import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.core.JsonProcessingException; - -/** - * Class to rw yang-tool generated objects into elasticsearch database. For "ES _id" exchange the esIdAddAtributteName - * is used. This attribute mast be of type String and contains for read and write operations the object id. The function - * can be used without id handling. If id handling is required the parameter needs to be specified by class definition - * in yang and setting the name by using setAttributeName() - * - * @param Yang tools generated class object. - */ -public class EsDataObjectReaderWriter { - - private final Logger LOG = LoggerFactory.getLogger(EsDataObjectReaderWriter.class); - - /** Typename for elastic search data schema **/ - private String dataTypeName; - - /** Elasticsearch Database client to be used **/ - private DatabaseClient db; - - /** Mapper with configuration to use opendaylight yang-tools builder pattern for object creation **/ - private YangToolsMapper yangtoolsMapper; - - /** Class of T as attribute to allow JSON to Class object mapping **/ - private Class clazz; - - /** Field is used to write id. If null no id handling **/ - private @Nullable Field field; - - /** Attribute that is used as id field for the database object **/ - private @Nullable String esIdAddAtributteName; - - /** Interface to be used for write operations. Rule for write: T extends S and **/ - private Class writeInterfaceClazz; // == "S" - - /** - * Elasticsearch database read and write for specific class, defined by opendaylight yang-tools. - * - * @param db Database access client - * @param dataTypeName typename in database schema - * @param clazz class of type to be handled - * @throws ClassNotFoundException - */ - public EsDataObjectReaderWriter(DatabaseClient db, Entity dataTypeName, Class clazz) - throws ClassNotFoundException { - this(db, dataTypeName.getName(), clazz); - } - - public EsDataObjectReaderWriter(DatabaseClient db, String dataTypeName, Class clazz) - throws ClassNotFoundException { - LOG.info("Create {} for datatype {} class {}", this.getClass().getName(), dataTypeName, clazz.getName()); - - this.esIdAddAtributteName = null; - this.field = null; - this.writeInterfaceClazz = clazz; - this.db = db; - this.dataTypeName = dataTypeName; - this.yangtoolsMapper = new YangToolsMapper(); - //this.yangtoolsMapper.assertBuilderClass(clazz); - this.clazz = clazz; - // - // if (! db.isExistsIndex(dataTypeName)) { - // throw new IllegalArgumentException("Index "+dataTypeName+" not existing."); - // } - } - - public String getDataTypeName() { - return dataTypeName; - } - - public Class getClazz() { - return clazz; - } - - /** - * Simlar to {@link #setEsIdAttributeName()}, but adapts the parameter to yangtools attribute naming schema - * - * @param esIdAttributeName is converted to UnderscoreCamelCase - * @return this for further operations. - */ - public EsDataObjectReaderWriter setEsIdAttributeNameCamelized(String esIdAttributeName) { - return setEsIdAttributeName(YangToolsMapper.toCamelCaseAttributeName(esIdAttributeName)); - } - - /** - * Attribute name of class that is containing the object id - * - * @param esIdAttributeName of the implementation class for the yangtools interface. Expected attribute name format - * is CamelCase with leading underline. @ - * @return this for further operations. - * @throws SecurityException if no access or IllegalArgumentException if wrong type or no attribute with this name. - */ - public EsDataObjectReaderWriter setEsIdAttributeName(String esIdAttributeName) { - LOG.debug("Set attribute '{}'", esIdAttributeName); - this.esIdAddAtributteName = null; // Reset status - this.field = null; - - Field attributeField; - try { - Builder builder = yangtoolsMapper.getBuilder(clazz); - T object = builder.build(); - attributeField = object.getClass().getDeclaredField(esIdAttributeName); - if (attributeField.getType().equals(String.class)) { - attributeField.setAccessible(true); - this.esIdAddAtributteName = esIdAttributeName; //Set new status if everything OK - this.field = attributeField; - } else { - String msg = "Wrong field type " + attributeField.getType().getName() + " of " + esIdAttributeName; - LOG.debug(msg); - throw new IllegalArgumentException(msg); - } - } catch (NoSuchFieldException e) { - // Convert to run-time exception - String msg = "NoSuchFieldException for '" + esIdAttributeName + "' in class " + clazz.getName(); - LOG.debug(msg); - throw new IllegalArgumentException(msg); - } catch (SecurityException e) { - LOG.debug("Access problem " + esIdAttributeName, e); - throw e; - } - return this; - } - - /** - * Specify subclass of T for write operations. - * - * @param writeInterfaceClazz - */ - public EsDataObjectReaderWriter setWriteInterface(@Nonnull Class writeInterfaceClazz) { - LOG.debug("Set write interface to {}", writeInterfaceClazz); - if (writeInterfaceClazz == null) - throw new IllegalArgumentException("Null not allowed here."); - - this.writeInterfaceClazz = writeInterfaceClazz; - return this; - } - - /** - * Write child object to database with specific id - * - * @param object - * @param @Nullable esId use the id or if null generate unique id - * @return String with id or null - */ - public @Nullable String write(S object, @Nullable String esId) { - if (writeInterfaceClazz.isInstance(object)) { - try { - String json = yangtoolsMapper.writeValueAsString(object); - return db.doWriteRaw(dataTypeName, esId, json); - } catch (JsonProcessingException e) { - LOG.error("Write problem: ", e); - } - } else { - LOG.error("Type {} does not provide interface {}", object != null ? object.getClass().getName() : "null", - writeInterfaceClazz.getName()); - } - return null; - } - - /** - * Update partial child object to database with match/term query - * - * @param object - * @param esId - * @return String with esId or null - */ - public @Nullable boolean update(S object, QueryBuilder query) { - if (writeInterfaceClazz.isInstance(object)) { - try { - String json = yangtoolsMapper.writeValueAsString(object); - return db.doUpdate(this.dataTypeName, json, query); - } catch (JsonProcessingException e) { - LOG.error("Update problem: ", e); - } - } else { - LOG.error("Type {} does not provide interface {}", object != null ? object.getClass().getName() : "null", - writeInterfaceClazz.getName()); - } - return false; - } - - /** - * Write/ update partial child object to database with specific id Write if not exists, else update - * - * @param object - * @param esId - * @return String with esId or null - */ - public @Nullable String update(S object, String esId) { - return this.update(object, esId, null); - } - - public @Nullable String update(S object, String esId, List onylForInsert) { - if (writeInterfaceClazz.isInstance(object)) { - try { - String json = yangtoolsMapper.writeValueAsString(object); - return db.doUpdateOrCreate(dataTypeName, esId, json, onylForInsert); - } catch (JsonProcessingException e) { - LOG.error("Update problem: ", e); - } - } else { - LOG.error("Type {} does not provide interface {}", object != null ? object.getClass().getName() : "null", - writeInterfaceClazz.getName()); - } - return null; - } - - /** - * Read object from database, by using the id field - * - * @param object - * @return - */ - public @Nullable T read(String esId) { - @Nullable - T res = (T) null; - if (esId != null) { - String json = db.doReadJsonData(dataTypeName, esId); - try { - res = yangtoolsMapper.readValue(json.getBytes(), clazz); - } catch (IOException e) { - LOG.error("Problem: ", e); - } - } - return res; - } - - /** - * Remove object - * - * @param esId to identify the object. - * @return success - */ - public boolean remove(String esId) { - return db.doRemove(this.dataTypeName, esId); - } - - public int remove(QueryBuilder query) { - return this.db.doRemove(this.dataTypeName, query); - } - - /** - * Get all elements of related type - * - * @return all Elements - */ - public SearchResult doReadAll() { - return doReadAll(null); - } - - public SearchResult doReadAll(QueryBuilder query) { - return this.doReadAll(query, false); - } - - /** - * Read all existing objects of a type - * - * @param query for the elements - * @return the list of all objects - */ - - public SearchResult doReadAll(QueryBuilder query, boolean ignoreException) { - - SearchResult res = new SearchResult(); - SearchResult result; - List hits; - if (query != null) { - LOG.debug("read data in {} with query {}", dataTypeName, query.toJSON()); - result = db.doReadByQueryJsonData(dataTypeName, query, ignoreException); - } else { - result = db.doReadAllJsonData(dataTypeName, ignoreException); - } - hits = result.getHits(); - LOG.debug("Read: {} elements: {} Failures: {}", dataTypeName, hits.size(), - yangtoolsMapper.getMappingFailures()); - - T object; - for (SearchHit hit : hits) { - object = getT(hit.getSourceAsString()); - LOG.debug("Mapp Object: {}\nSource: '{}'\nResult: '{}'\n Failures: {}", hit.getId(), - hit.getSourceAsString(), object, yangtoolsMapper.getMappingFailures()); - if (object != null) { - setEsId(object, hit.getId()); - res.add(object); - } else { - LOG.warn("Mapp result null Object: {}\n Source: '{}'\n : '", hit.getId(), hit.getSourceAsString()); - } - } - res.setTotal(result.getTotal()); - return res; - } - - /* --------------------------------------------- - * Private functions - */ - - private void setEsId(T object, String esId) { - if (field != null) { - try { - field.set(object, esId); - } catch (IllegalArgumentException | IllegalAccessException e) { - LOG.debug("Field set problem.", e); - } - } - } - - private @Nullable T getT(String jsonString) { - try { - return yangtoolsMapper.readValue(jsonString, clazz); - } catch (IOException e) { - LOG.info("Mapping problem", e); - return (T) null; - } - } - -} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java index e0f6e4aea..658826986 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java @@ -21,13 +21,12 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.database; +import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; import java.lang.reflect.Field; import java.util.List; - import javax.annotation.Nonnull; import javax.annotation.Nullable; - import org.eclipse.jdt.annotation.NonNull; import org.onap.ccsdk.features.sdnr.wt.common.database.DatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; @@ -41,8 +40,6 @@ import org.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.core.JsonProcessingException; - /** * Class to rw yang-tool generated objects into elasticsearch database. For "ES _id" exchange the esIdAddAtributteName * is used. This attribute mast be of type String and contains for read and write operations the object id. The function @@ -78,28 +75,23 @@ public class EsDataObjectReaderWriter2 { /** Interface to be used for write operations. Rule for write: T extends S and **/ private Class writeInterfaceClazz; // == "S" + /** Flag true to sync this attribute during write always, what is slow and false do not sync */ + private final boolean syncAfterWrite; /** * Elasticsearch database read and write for specific class, defined by opendaylight yang-tools. * + * @param + * @param * @param db Database access client * @param dataTypeName typename in database schema * @param clazz class of type to be handled + * @param builderClazz class to build related object if builder pattern should be used. + * @param syncAfterWrite * @throws ClassNotFoundException */ public > EsDataObjectReaderWriter2(DatabaseClient db, - Entity dataTypeName, @Nonnull Class clazz, @Nullable Class builderClazz) - throws ClassNotFoundException { - this(db, dataTypeName.getName(), clazz, builderClazz); - } - - public > EsDataObjectReaderWriter2(DatabaseClient db, - Entity dataTypeName, @Nonnull Class clazz) throws ClassNotFoundException { - this(db, dataTypeName.getName(), clazz, null); - } - - public > EsDataObjectReaderWriter2(DatabaseClient db, - String dataTypeName, @Nonnull Class clazz, @Nullable Class builderClazz) + String dataTypeName, @Nonnull Class clazz, @Nullable Class builderClazz, boolean syncAfterWrite) throws ClassNotFoundException { LOG.info("Create {} for datatype {} class {}", this.getClass().getName(), dataTypeName, clazz.getName()); @@ -110,11 +102,43 @@ public class EsDataObjectReaderWriter2 { this.dataTypeName = dataTypeName; this.yangtoolsMapper = new YangToolsMapper2<>(clazz, builderClazz); this.clazz = clazz; + this.syncAfterWrite = syncAfterWrite; + } + + public > EsDataObjectReaderWriter2(DatabaseClient db, + Entity dataTypeName, @Nonnull Class clazz, @Nullable Class builderClazz) + throws ClassNotFoundException { + this(db, dataTypeName.getName(), clazz, builderClazz, false); + } + + public > EsDataObjectReaderWriter2(DatabaseClient db, + Entity dataTypeName, @Nonnull Class clazz, @Nullable Class builderClazz, boolean syncAfterWrite) + throws ClassNotFoundException { + this(db, dataTypeName.getName(), clazz, builderClazz, syncAfterWrite); + } + + public EsDataObjectReaderWriter2(DatabaseClient db, Entity dataTypeName, @Nonnull Class clazz, + boolean syncAfterWrite) throws ClassNotFoundException { + this(db, dataTypeName.getName(), clazz, null, syncAfterWrite); + } + + public EsDataObjectReaderWriter2(DatabaseClient db, Entity dataTypeName, Class clazz) + throws ClassNotFoundException { + this(db, dataTypeName.getName(), clazz, null, false); + } + + /** + * Get Datatype name + * + * @return string with dataTypeName + */ + public String getDataTypeName() { + return dataTypeName; } /** * Simlar to {@link #setEsIdAttributeName()}, but adapts the parameter to yangtools attribute naming schema - * + * * @param esIdAttributeName is converted to UnderscoreCamelCase * @return this for further operations. */ @@ -124,7 +148,7 @@ public class EsDataObjectReaderWriter2 { /** * Attribute name of class that is containing the object id - * + * * @param esIdAttributeName of the implementation class for the yangtools interface. Expected attribute name format * is CamelCase with leading underline. @ * @return this for further operations. @@ -137,7 +161,7 @@ public class EsDataObjectReaderWriter2 { Field attributeField; try { - Builder builder = yangtoolsMapper.getBuilder(clazz); + Builder builder = yangtoolsMapper.getBuilder(clazz); if (builder == null) { String msg = "No builder for " + clazz; LOG.debug(msg); @@ -169,7 +193,7 @@ public class EsDataObjectReaderWriter2 { /** * Specify subclass of T for write operations. - * + * * @param writeInterfaceClazz */ public EsDataObjectReaderWriter2 setWriteInterface(@Nonnull Class writeInterfaceClazz) { @@ -194,7 +218,7 @@ public class EsDataObjectReaderWriter2 { /** * Write child object to database with specific id - * + * * @param object to be written * @param esId use the id or if null generate unique id * @return String with id or null @@ -203,7 +227,7 @@ public class EsDataObjectReaderWriter2 { if (object != null && writeInterfaceClazz.isInstance(object)) { try { String json = yangtoolsMapper.writeValueAsString(object); - return db.doWriteRaw(dataTypeName, esId, json); + return db.doWriteRaw(dataTypeName, esId, json, this.syncAfterWrite); } catch (JsonProcessingException e) { LOG.error("Write problem: ", e); } @@ -216,7 +240,7 @@ public class EsDataObjectReaderWriter2 { /** * Update partial child object to database with match/term query - * + * * @param of object * @param object to write * @param query for write of specific attributes @@ -239,7 +263,7 @@ public class EsDataObjectReaderWriter2 { /** * Write/ update partial child object to database with specific id Write if not exists, else update - * + * * @param object * @param esId * @return String with esId or null @@ -268,7 +292,7 @@ public class EsDataObjectReaderWriter2 { /** * Read object from database, by using the id field - * + * * @param object * @return */ @@ -292,7 +316,7 @@ public class EsDataObjectReaderWriter2 { /** * Remove object - * + * * @param esId to identify the object. * @return success */ @@ -306,7 +330,7 @@ public class EsDataObjectReaderWriter2 { /** * Get all elements of related type - * + * * @return all Elements */ public SearchResult doReadAll() { @@ -319,46 +343,39 @@ public class EsDataObjectReaderWriter2 { /** * Read all existing objects of a type - * + * * @param query for the elements * @return the list of all objects */ public SearchResult doReadAll(QueryBuilder query, boolean ignoreException) { - SearchResult res = new SearchResult<>(); - int idx = 0; //Idx for getAll - int iterateLength = 100; //Step width for iterate + SearchResult res = new SearchResult(); SearchResult result; List hits; - do { - if (query != null) { - LOG.debug("read data in {} with query {}", dataTypeName, query.toJSON()); - result = db.doReadByQueryJsonData(dataTypeName, query, ignoreException); + if (query != null) { + LOG.debug("read data in {} with query {}", dataTypeName, query.toJSON()); + result = db.doReadByQueryJsonData(dataTypeName, query, ignoreException); + } else { + result = db.doReadAllJsonData(dataTypeName, ignoreException); + } + hits = result.getHits(); + LOG.debug("Read: {} elements: {} Failures: {}", dataTypeName, hits.size(), + yangtoolsMapper.getMappingFailures()); + + T object; + for (SearchHit hit : hits) { + object = getT(hit.getSourceAsString()); + LOG.debug("Mapp Object: {}\nSource: '{}'\nResult: '{}'\n Failures: {}", hit.getId(), + hit.getSourceAsString(), object, yangtoolsMapper.getMappingFailures()); + if (object != null) { + setEsId(object, hit.getId()); + res.add(object); } else { - result = db.doReadAllJsonData(dataTypeName, ignoreException); - } - hits = result.getHits(); - LOG.debug("Read: {} elements: {} Failures: {}", dataTypeName, hits.size(), - yangtoolsMapper.getMappingFailures()); - - T object; - idx += result.getHits().size(); - for (SearchHit hit : hits) { - object = getT(hit.getSourceAsString()); - LOG.debug("Mapp Object: {}\nSource: '{}'\nResult: '{}'\n Failures: {}", hit.getId(), - hit.getSourceAsString(), object, yangtoolsMapper.getMappingFailures()); - if (object != null) { - setEsId(object, hit.getId()); - res.add(object); - } else { - LOG.warn("Mapp result null Object: {}\n Source: '{}'\n : '", hit.getId(), hit.getSourceAsString()); - } + LOG.warn("Mapp result null Object: {}\n Source: '{}'\n : '", hit.getId(), hit.getSourceAsString()); } - - } while (hits.size() == iterateLength); // Do it until end indicated, because less hits than iterateLength - // allows. + } res.setTotal(result.getTotal()); return res; } 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 index 120684298..fdac1c10a 100644 --- 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 @@ -23,7 +23,9 @@ 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; @@ -35,11 +37,14 @@ 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.onap.ccsdk.features.sdnr.wt.dataprovider.data.ODLVersionLUT; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.SystemInfo; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,6 +74,7 @@ public class AboutHttpServlet extends HttpServlet { 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"; @@ -76,14 +82,22 @@ public class AboutHttpServlet extends HttpServlet { 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 */ @@ -96,7 +110,7 @@ public class AboutHttpServlet extends HttpServlet { 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, "1.8.1-SNAPSHOT"); + 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)); @@ -170,6 +184,7 @@ public class AboutHttpServlet extends HttpServlet { 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); } @@ -264,6 +279,28 @@ public class AboutHttpServlet extends HttpServlet { 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 * diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java new file mode 100644 index 000000000..e34988b4b --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java @@ -0,0 +1,192 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.http; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.json.JSONObject; + +public class DataTreeChildObject { + + private final String label; + private final String ownSeverity; + private final String childrenSeveritySummary; + private final boolean isMatch; + private final Map children; + private final Map properties; + + public boolean isMatch() { + return this.isMatch; + } + + public DataTreeChildObject(String label, boolean isMatch, Map children, + String ownSeverity, String childrenSeveritySummary) { + this.label = label; + this.isMatch = isMatch; + this.children = children; + this.ownSeverity = ownSeverity; + this.childrenSeveritySummary = childrenSeveritySummary; + this.properties = new HashMap<>(); + } + + public DataTreeChildObject setProperty(String key, Object value) { + this.properties.put(key, value); + return this; + } + + public Object getProperty(String key, Object defaultValue) { + return this.properties.getOrDefault(key, defaultValue); + } + + /** + * @param string + * @param b + */ + public DataTreeChildObject(String label, boolean isMatch) { + this(label, isMatch, new HashMap<>(), null, null); + } + + /** + * @param treeLevel + * @param id + * @param data + * @param childKey + * @param parentKey + * @return + */ + public boolean putChild(long treeLevel, String id, DataTreeChildObject data, String parentKey, String childKey) { + Object itemValue; + Object itemValueToMatch = data.getProperty(parentKey, null); + if (itemValueToMatch == null) { + return false; + } + if (treeLevel > 0) { + if (this.children != null) { + for (DataTreeChildObject child : this.children.values()) { + if (child.putChild(treeLevel - 1, id, data, parentKey, childKey)) { + return true; + } + } + } + } else { + // if(this.children!=null) { + // for(DataTreeChildObject child:this.children.values()) { + // itemValue=(String) child.getProperty(childKey, null); + // if(itemValue!=null && itemValue.equals(itemValueToMatch)) { + // child.children.put(id, data); + // return true; + // } + // } + // } + itemValue = this.getProperty(childKey, null); + if (itemValue != null && itemValue.equals(itemValueToMatch)) { + this.children.put(id, data); + } + } + return false; + } + + /** + * @param treeLevel + * @param id + * @param data + * @param parentKey + * @param childKey + * @return + */ + public boolean putChildIfNotExists(long treeLevel, String id, DataTreeChildObject data, String parentKey, + String childKey) { + Object itemValue; + Object itemValueToMatch = data.getProperty(parentKey, null); + if (itemValueToMatch == null) { + return false; + } + if (treeLevel > 0) { + if (this.children != null) { + for (DataTreeChildObject child : this.children.values()) { + if (child.putChildIfNotExists(treeLevel - 1, id, data, parentKey, childKey)) { + return true; + } + } + } + } else { + itemValue = this.getProperty(childKey, null); + if (itemValue != null && itemValue.equals(itemValueToMatch)) { + if (!this.children.containsKey(id)) { + this.children.put(id, data); + } + } + } + return false; + } + + /** + * @return + */ + public JSONObject toJSONObject() { + JSONObject o = new JSONObject(); + o.put("label", this.label); + o.put("isMatch", this.isMatch); + JSONObject c = new JSONObject(); + if (this.children != null) { + for (Entry entry : this.children.entrySet()) { + c.put(entry.getKey(), entry.getValue().toJSONObject()); + } + } + o.put("children", c); + // o.put("ownSeverity", null); + // o.put("childrenSeveritySummary", null); + return o; + } + + public boolean hasChildMatching() { + boolean match = false; + for (DataTreeChildObject child : this.children.values()) { + match = match || child.hasChildMatching() || this.isMatch; + if (match) { + break; + } + } + return match; + } + + /** + * + */ + public void removeUnmatchedPaths() { + List toRemove = new ArrayList<>(); + for (Entry entry : this.children.entrySet()) { + if (!(entry.getValue().hasChildMatching() || entry.getValue().isMatch)) { + toRemove.add(entry.getKey()); + } else { + entry.getValue().removeUnmatchedPaths(); + } + } + for (String key : toRemove) { + this.children.remove(key); + } + } +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java index 490f3cac8..245ac1cf6 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java @@ -21,14 +21,29 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.http; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.json.JSONObject; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataTreeProviderImpl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Michael Dürre @@ -36,24 +51,190 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; */ public class DataTreeHttpServlet extends HttpServlet { + public enum FilterMode { + Strict, //show only filtered items and their parents + Lazy //show root items (and all their children) which have matches inside + } + /** - * @param rawClient + * */ - public void setDatabaseClient(HtDatabaseClient rawClient) { + private static final long serialVersionUID = 1L; + private final DataTreeProviderImpl dataTreeProvider; + private static final Logger LOG = LoggerFactory.getLogger(DataTreeHttpServlet.class); + public DataTreeHttpServlet() { + super(); + this.dataTreeProvider = new DataTreeProviderImpl(); + } + + /** + * @param client + */ + public void setDatabaseClient(HtDatabaseClient client) { + this.dataTreeProvider.setDatabaseClient(client); } + public static String readPayload(HttpServletRequest request) throws IOException { + + String body = null; + StringBuilder stringBuilder = new StringBuilder(); + BufferedReader bufferedReader = null; + + try { + InputStream inputStream = request.getInputStream(); + if (inputStream != null) { + bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + char[] charBuffer = new char[128]; + int bytesRead = -1; + while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { + stringBuilder.append(charBuffer, 0, bytesRead); + } + } else { + stringBuilder.append(""); + } + } catch (IOException ex) { + throw ex; + } finally { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } catch (IOException ex) { + throw ex; + } + } + } + + body = stringBuilder.toString(); + return body; + } + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String uri = req.getRequestURI(); + LOG.debug("GET request for {}", uri); + final EntityWithTree e = getEntity(uri); + if (e != null) { + LOG.info("GET request for {} to e={} with tree={}", uri, e.entity, e.tree); + switch (e.entity) { + case Inventoryequipment: + DataTreeObject o = this.dataTreeProvider.readInventoryTree(e.tree, null, FilterMode.Lazy); + this.doJsonResponse(resp, o); + break; + default: + this.notAvailble(resp); + break; + } + } else { + LOG.debug("unable to find entity for uri {}", uri); + } } - private void readInventoryTree(String filter) { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + final String uri = req.getRequestURI(); + String filter = null; + FilterMode mode = FilterMode.Lazy; + try { + final String body = readPayload(req); + JSONObject data = new JSONObject(body); + if (data.has("query")) { + filter = data.getString("query"); + } + if (data.has("mode")) { + mode = data.getString("mode").equals("lazy") ? FilterMode.Lazy : FilterMode.Strict; + } + + } catch (Exception e) { + LOG.warn("problem reading payload: {}", e); + } + LOG.debug("POST request for {}", uri); + final EntityWithTree e = getEntity(uri); + if (e != null) { + switch (e.entity) { + case Inventoryequipment: + DataTreeObject o = this.dataTreeProvider.readInventoryTree(e.tree, filter, mode); + this.doJsonResponse(resp, o); + break; + default: + this.notAvailble(resp); + break; + } + } + } + + /** + * @param resp + */ + private void notAvailble(HttpServletResponse resp) { + try { + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + } catch (IOException e) { + + } } - private void doJsonResponse(HttpServletResponse resp, Object data) { + public static EntityWithTree getEntity(String uri) { + final String regex = "^\\/tree\\/read-(.*)-tree\\/?(.*)$"; + final Pattern pattern = Pattern.compile(regex); + final Matcher matcher = pattern.matcher(uri); + Entity e = null; + if (matcher.find() && matcher.groupCount() > 0) { + try { + e = Entity.forName(matcher.group(1)).get(); + return new EntityWithTree(e, matcher.groupCount() > 1 ? matcher.group(2) : null); + } catch (Exception e2) { + LOG.warn("unable to parse {} into entity: {}", matcher.group(2), e2); + } + } + return null; + + } + + private void doJsonResponse(HttpServletResponse resp, DataTreeObject data) { + resp.setHeader("Content-Type", "application/json"); + try { + resp.getWriter().write(data.toJSON()); + } catch (IOException e) { + LOG.warn("problem sending response: {}", e); + } + } + + public static class EntityWithTree { + public final Entity entity; + public final List tree; + + @Override + public String toString() { + return "EntityWithTree [entity=" + entity + ", tree=" + tree + "]"; + } + public EntityWithTree(Entity e, String tree) { + this.entity = e; + if (tree != null) { + if (tree.startsWith("/")) { + tree = tree.substring(1); + } + if (tree.endsWith("/")) { + tree = tree.substring(0, tree.length() - 1); + } + String[] tmp = tree.split("\\/"); + this.tree = new ArrayList<>(); + for (int i = 0; i < tmp.length; i++) { + try { + String s = URLDecoder.decode(tmp[i], "utf-8"); + if (s != null && s.length() > 0) { + this.tree.add(s); + } + } catch (UnsupportedEncodingException e1) { + LOG.warn("problem urldecode {}: {}", tmp[i], e); + } + } + } else { + this.tree = null; + } + } } } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java new file mode 100644 index 000000000..d6c8bd7bb --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java @@ -0,0 +1,140 @@ +/* + * ============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.HashMap; + +import org.json.JSONObject; + +public class DataTreeObject extends HashMap { + + private static final long serialVersionUID = 1L; + private final String parentKey; + private final String childKey; + + public DataTreeObject createTreeByPath(String[] pathFilter) { + + if (pathFilter != null && pathFilter.length > 0) { + for (String key : this.keySet()) { + if (key.equals(pathFilter[0])) { + DataTreeChildObject o = this.getChildElemByPath(this.get(key), slice(pathFilter, 1)); + DataTreeObject r = new DataTreeObject(this.parentKey, this.childKey); + r.put(key, o); + return r; + } + } + } + + return null; + + } + + private DataTreeChildObject getChildElemByPath(DataTreeChildObject source, String[] pathFilter) { + + if (pathFilter != null && pathFilter.length > 0) { + // for(String key:source..keySet()) { + // if(key.equals(pathFilter[0])){ + // DataTreeChildObject o= this.getChildElemByPath(this.get(key),slice(pathFilter,1)); + // } + // } + } + + return null; + } + + public DataTreeObject(String parentKey, String childKey) { + this.parentKey = parentKey; + this.childKey = childKey; + } + + /** + * @param treeLevel + * @param id + * @param data + */ + public void put(long treeLevel, String id, DataTreeChildObject data) { + for (DataTreeChildObject entry : this.values()) { + if (entry.putChild(treeLevel, id, data, this.parentKey, this.childKey)) { + break; + } + } + + } + + /** + * + */ + public String toJSON() { + JSONObject o = new JSONObject(); + for (Entry entry : this.entrySet()) { + o.put(entry.getKey(), entry.getValue().toJSONObject()); + } + return o.toString(); + } + + /** + * + */ + public void removeUnmatchedPaths() { + for (DataTreeChildObject entry : this.values()) { + entry.removeUnmatchedPaths(); + } + + } + + /** + * @param treeLevel + * @param id + * @param setProperty + */ + public void putIfNotExists(long treeLevel, String id, DataTreeChildObject data) { + for (DataTreeChildObject entry : this.values()) { + if (entry.putChildIfNotExists(treeLevel, id, data, this.parentKey, this.childKey)) { + break; + } + } + } + + /** + * @param id + * @param data + */ + public void putIfNotExists(String id, DataTreeChildObject data) { + if (!this.containsKey(id)) { + this.put(id, data); + } + } + + /** + * @param source + * @param i + * @return + */ + public static String[] slice(String[] source, int start) { + String[] r = new String[source.length - start]; + for (int i = 0; i < r.length; i++) { + r[i] = source[i + start]; + } + return r; + + } +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MarkdownTable.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MarkdownTable.java new file mode 100644 index 000000000..52eda0cd8 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/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; + +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 new file mode 100644 index 000000000..3ea3e3d02 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/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; + +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 new file mode 100644 index 000000000..12b03ffe6 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/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; + +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 index 075f4f766..48862a6a5 100644 --- 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 @@ -28,7 +28,6 @@ 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; 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 286af7aa3..f9e0fcbc2 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 @@ -46,6 +46,7 @@ public class DataProviderImpl implements IEntityDataProvider, AutoCloseable { private MsServlet mediatorServerServlet; private DataProviderServiceImpl rpcApiService; private AboutHttpServlet aboutServlet; + private DataTreeHttpServlet treeServlet; private HtDatabaseClient dbClient; // Blueprint 1 @@ -66,12 +67,17 @@ public class DataProviderImpl implements IEntityDataProvider, AutoCloseable { this.aboutServlet = aboutServlet; } + public void setTreeServlet(DataTreeHttpServlet treeServlet) { + this.treeServlet = treeServlet; + } + public void init() throws Exception { LOG.info("Session Initiated start {}", APPLICATION_NAME); // Start RPC Service this.rpcApiService = new DataProviderServiceImpl(rpcProviderService, this.mediatorServerServlet); + this.treeServlet.setDatabaseClient(this.rpcApiService.getRawClient()); LOG.info("Session Initiated end. Initialization done"); } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java new file mode 100644 index 000000000..2af354bcc --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java @@ -0,0 +1,321 @@ +/* + * ============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.impl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.json.JSONObject; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.BoolQueryBuilder; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.Search7Request; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.AggregationEntries; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeChildObject; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.FilterMode; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; + +/** + * @author Michael Dürre + * + */ +public class DataTreeProviderImpl { + + private static final long MAXSIZE_PERSEARCH = 10; + private HtDatabaseClient dbClient; + final String INVENTORY_PROPERTY_TREELEVEL = "tree-level"; + final String INVENTORY_PROPERTY_NODEID = "node-id"; + final String INVENTORY_PROPERTY_UUID = "uuid"; + final String INVENTORY_PROPERTY_PARENTUUID = "parent-uuid"; + final String INVENTORY_PROPERTY_FOR_LABEL_CHILD = "uuid"; + final String INVENTORY_PROPERTY_FOR_LABEL = "uuid"; + + private List search(Entity e, String filter, String propTreeLevel) throws IOException { + return this.search(e, filter, null, null, null, null, null, null, propTreeLevel); + } + + private List search(Entity e, String filter, String nodeKey, String nodeId, String parentKey, + String parentValue, String childKey, String childValue, String propTreeLevel) throws IOException { + QueryBuilder query = + filter == null ? QueryBuilders.matchAllQuery() : QueryBuilders.searchAllFieldsQuery(filter); + if ((nodeId != null && nodeKey != null) || (parentKey != null && parentValue != null)) { + BoolQueryBuilder bquery = new BoolQueryBuilder(); + if (filter != null) { + bquery.must(query); + } + if (nodeId != null) { + bquery.must(QueryBuilders.matchQuery(nodeKey, nodeId)); + } + // if (parentKey != null && parentValue != null) { + // bquery.must(QueryBuilders.matchQuery(parentKey, parentValue)); + // } + // if (childKey != null && childValue != null) { + // bquery.must(QueryBuilders.matchQuery(childKey, childValue)); + // } + query = bquery; + + } + return this.search(e, query, propTreeLevel); + } + + private List search(Entity e, QueryBuilder query, String propTreeLevel) throws IOException { + List list = new ArrayList(); + query.sort(propTreeLevel, SortOrder.ASCENDING); + SearchRequest request = new Search7Request(Entity.Inventoryequipment.getName()); + query.size(MAXSIZE_PERSEARCH); + request.setQuery(query); + SearchResponse response = this.dbClient.search(request); + SearchHit[] matches = response.getHits(); + for (SearchHit hit : matches) { + list.add(hit); + } + if (response.getTotal() > MAXSIZE_PERSEARCH) { + long todo = response.getTotal(); + long from = MAXSIZE_PERSEARCH; + while (todo > from) { + request.setQuery(query.from(from)); + from += MAXSIZE_PERSEARCH; + //merge into list + response = this.dbClient.search(request); + matches = response.getHits(); + for (SearchHit hit : matches) { + list.add(hit); + } + } + } + return list; + } + + /** + * @param iNVENTORY_PROPERTY_NODEID2 + * @return + * @throws IOException + */ + private AggregationEntries searchAggregated(Entity e, String key) throws IOException { + QueryBuilder query = QueryBuilders.matchAllQuery().aggregations(key).size(MAXSIZE_PERSEARCH); + SearchRequest request = new Search7Request(e.getName()); + request.setQuery(query); + SearchResponse response = this.dbClient.search(request); + return response.getAggregations(key); + } + + /** + * + * @param tree + * @param filter + * @param + * @return + * @throws IOException + */ + public DataTreeObject readInventoryTree(List tree, String filter, FilterMode mode) throws IOException { + + //root nodes will be node-information -> below inventory + if (tree == null || tree.size() <= 0) { + return this.readInventoryTreeWithNode(filter, mode); + } + //root node will be inventory on tree-level if sliced treePath + else { + return this.readInventoryTreeForNode(tree.get(0), tree.subList(0, tree.size() - 1), filter, mode); + } + + } + + /** + * @param string + * @param slice + * @param filter + * @param mode + * @return + */ + private DataTreeObject readInventoryTreeForNode(String nodeId, List list, String filter, FilterMode mode) + throws IOException { + DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID); + final String parentUuid = list.size() > 1 ? list.get(list.size() - 2) : null; + final String uuid = list.size() > 0 ? list.get(list.size() - 1) : null; + List matches = this.search(Entity.Inventoryequipment, filter, INVENTORY_PROPERTY_NODEID, nodeId, + INVENTORY_PROPERTY_PARENTUUID, parentUuid, INVENTORY_PROPERTY_UUID, uuid, INVENTORY_PROPERTY_TREELEVEL); + + //tree.a(subtreePath); + List others = this.search(Entity.Inventoryequipment, (String) null, INVENTORY_PROPERTY_TREELEVEL); + if (matches.size() > 0) { + int treeLevelToStart = (list == null || list.size() <= 0) ? 0 : list.size() - 1; + //build tree + JSONObject hitData; + //fill root elems + for (SearchHit hit : matches) { + hitData = hit.getSource(); + if (hitData.getLong("tree-level") == treeLevelToStart) { + tree.put(hit.getId(), + new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), true) + .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, + hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); + } + } + for (SearchHit hit : others) { + hitData = hit.getSource(); + if (hitData.getLong("tree-level") == treeLevelToStart) { + tree.putIfNotExists(hit.getId(), + new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), false) + .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, + hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); + } + } + //fill child elems + for (SearchHit hit : matches) { + hitData = hit.getSource(); + if (hitData.getLong("tree-level") > treeLevelToStart) { + tree.put(hitData.getLong("tree-level") - treeLevelToStart - 1, hit.getId(), + new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), true) + .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, + hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); + } + } + for (SearchHit hit : others) { + hitData = hit.getSource(); + if (hitData.getLong("tree-level") > treeLevelToStart) { + tree.putIfNotExists(hitData.getLong("tree-level") - treeLevelToStart - 1, hit.getId(), + new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), false) + .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, + hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); + } + } + } + return tree; + } + + /** + * node will be root elements inventory information below from level-1 + * + * @param filter + * @param mode + * @return + * @throws IOException + */ + private DataTreeObject readInventoryTreeWithNode(String filter, FilterMode mode) throws IOException { + DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID); + + List matches = this.search(Entity.Inventoryequipment, filter, INVENTORY_PROPERTY_TREELEVEL); + List others = null; + if (matches.size() > 0) { + if (filter != null) { + //find all parents up to tree-level 0 + String nodeId = ""; + List alreadyInList = new ArrayList<>(); + BoolQueryBuilder query2 = QueryBuilders.boolQuery(); + for (SearchHit hit : matches) { + nodeId = hit.getSource().getString(INVENTORY_PROPERTY_NODEID); + if (alreadyInList.contains(nodeId)) { + continue; + } + query2.should(QueryBuilders.matchQuery(INVENTORY_PROPERTY_NODEID, nodeId)); + alreadyInList.add(nodeId); + tree.put(nodeId, + new DataTreeChildObject(nodeId, false).setProperty(INVENTORY_PROPERTY_UUID, nodeId)); + + } + others = this.search(Entity.Inventoryequipment, query2, INVENTORY_PROPERTY_TREELEVEL); + } else { + AggregationEntries nodes = this.searchAggregated(Entity.Inventoryequipment, INVENTORY_PROPERTY_NODEID); + for (String node : nodes.keySet()) { + tree.put(node, new DataTreeChildObject(node, false).setProperty(INVENTORY_PROPERTY_UUID, node)); + } + } + + //build tree + JSONObject hitData; + //fill root elems + for (SearchHit hit : matches) { + hitData = hit.getSource(); + if (hitData.getLong("tree-level") == 0) { + tree.put(0, hit.getId(), + new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), true) + .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, + hitData.getString(INVENTORY_PROPERTY_NODEID))); + } + } + if (others != null) { + for (SearchHit hit : others) { + hitData = hit.getSource(); + if (hitData.getLong("tree-level") == 0) { + tree.putIfNotExists(0, hit.getId(), + new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL), false) + .setProperty(INVENTORY_PROPERTY_UUID, + hitData.getString(INVENTORY_PROPERTY_UUID)) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, + hitData.getString(INVENTORY_PROPERTY_NODEID))); + } + } + } + //fill child elements + for (SearchHit hit : matches) { + hitData = hit.getSource(); + long treeLevel = hitData.getLong("tree-level"); + if (treeLevel > 0) { + tree.put(treeLevel, hit.getId(), + new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL_CHILD), true) + .setProperty(INVENTORY_PROPERTY_UUID, hitData.getString(INVENTORY_PROPERTY_UUID)) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, + hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); + } + } + if (others != null) { + for (SearchHit hit : others) { + hitData = hit.getSource(); + long treeLevel = hitData.getLong("tree-level"); + if (hitData.getLong("tree-level") > 0) { + tree.putIfNotExists(treeLevel, hit.getId(), + new DataTreeChildObject(hitData.getString(INVENTORY_PROPERTY_FOR_LABEL_CHILD), false) + .setProperty(INVENTORY_PROPERTY_UUID, + hitData.getString(INVENTORY_PROPERTY_UUID)) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, + hitData.getString(INVENTORY_PROPERTY_PARENTUUID))); + } + } + } + if (mode == FilterMode.Strict) { + tree.removeUnmatchedPaths(); + } + } + return tree; + } + + + + /** + * @param client + */ + public void setDatabaseClient(HtDatabaseClient client) { + this.dbClient = client; + + } +} diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java index 001437771..44751ffd0 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java @@ -26,7 +26,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener; @@ -52,13 +51,12 @@ public class EsConfig implements Configuration, IEsConfig { private static final String PROPERTY_KEY_AUTH_PASSWORD = "esAuthPassword"; - private static String defaultHostinfo = "${SDNRDBURL}";//printHosts(new HostInfo[] { new HostInfo("sdnrdb", 9200, Protocol.HTTP) }); + private static String defaultHostinfo = "${SDNRDBURL}"; private static final String DEFAULT_VALUE_CLUSTER = ""; /** check db data in this interval [in seconds] 0 deactivated */ private static final String DEFAULT_ARCHIVE_INTERVAL_SEC = "0"; /** keep data for this time [in seconds] 30 days */ private static final String DEFAULT_ARCHIVE_LIMIT_SEC = String.valueOf(60L * 60L * 24L * 30L); - //private static final String DEFAULT_KEY_NODE = "elasticsearchnode"; private static final String DEFAULT_VALUE_NODE = "elasticsearchnode"; private static final String DEFAULT_VALUE_DBUSERNAME = "${SDNRDBUSERNAME}"; private static final String DEFAULT_VALUE_DBPASSWORD = "${SDNRDBPASSWORD}"; diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper2.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper2.java index ce67c39dd..814bfd745 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper2.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper2.java @@ -59,16 +59,25 @@ public class YangToolsMapper2 extends ObjectMapper { private final Logger LOG = LoggerFactory.getLogger(YangToolsMapper2.class); private static final long serialVersionUID = 1L; - private static String ENTITY = "Entity"; private static String BUILDER = "Builder"; - private @Nullable Class clazz; - private @Nullable Class> builderClazz; + private @Nullable final Class clazz; + private @Nullable final Class> builderClazz; private BundleContext context; - public > YangToolsMapper2(Class clazz, Class builderClazz) - throws ClassNotFoundException { + /** + * Generic Object creation of yangtools java class builder pattern. + * + * @param Class of DataObject + * @param Builder for the class. + * @param clazz specifies class to be mapped + * @param builderClazz is the builder for class with name pattern "clazzBuilder".
+ * If null the clazz is expected to support normal jackson build pattern. + * @throws ClassNotFoundException if builderClazz not available in bundle + */ + public > YangToolsMapper2(@NonNull Class clazz, + @Nullable Class builderClazz) throws ClassNotFoundException { super(); configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE); @@ -84,11 +93,6 @@ public class YangToolsMapper2 extends ObjectMapper { context = bundle != null ? bundle.getBundleContext() : null; } - public YangToolsMapper2() throws ClassNotFoundException { - this(null, null); - } - - @Override public String writeValueAsString(Object value) throws JsonProcessingException { return super.writeValueAsString(value); @@ -101,11 +105,12 @@ public class YangToolsMapper2 extends ObjectMapper { * @param clazz class with interface. * @return builder for interface or null if not existing */ - @SuppressWarnings("unchecked") - public @Nullable Builder getBuilder(Class clazz) { + public @Nullable Builder getBuilder(Class clazz) { try { - //Class clazzBuilder = getBuilderClass(getBuilderClassName(clazz)); - return (Builder) builderClazz.newInstance(); + if (builderClazz != null) + return (Builder) builderClazz.newInstance(); + else + return null; } catch (InstantiationException | IllegalAccessException e) { LOG.debug("Problem ", e); return null; @@ -169,12 +174,6 @@ public class YangToolsMapper2 extends ObjectMapper { */ private static String getBuilderClassName(Class clazz) { return clazz.getName() + BUILDER; - // String clazzName = clazz.getName(); - // if (clazzName.endsWith(ENTITY)) { - // return clazzName.replace(ENTITY, BUILDER); - // } else { - // return clazzName + BUILDER; - // } } /** 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 81c8c6c1e..58091d5da 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 @@ -1,4 +1,4 @@ - +## Version Info | | | | --- | ----- | | ONAP release | {release-name} | @@ -12,6 +12,11 @@ | ODLUX version | {odlux-revision} | | Cluster size | {cluster-size} | +## Device manager + +{devicemanagers} + +## System Info ``` {karaf-info} ``` \ No newline at end of file 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 deleted file mode 100755 index 67d495aa0..000000000 --- a/sdnr/wt/data-provider/provider/src/main/resources/es-init.sh +++ /dev/null @@ -1,446 +0,0 @@ -#!/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/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index fcd62ff79..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 @@ -30,6 +30,8 @@ interface="org.opendaylight.mdsal.binding.api.RpcProviderService" odl:type="default"/> + + @@ -41,7 +43,8 @@ + class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet"> + @@ -58,17 +61,26 @@ + + + + + + + + + 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 f147e8724..5d9011ab0 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 @@ -25,7 +25,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.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/TestCRUDforDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java index 5cf2f0644..a22f3033d 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java @@ -41,6 +41,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.BaseRequest; import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; 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.CreateMaintenanceInput; @@ -123,12 +124,11 @@ public class TestCRUDforDatabase { private static ElasticSearchDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; - public static HostInfo[] hosts = new HostInfo[] {new HostInfo("localhost", Integer - .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200"))}; @BeforeClass public static void init() throws Exception { + HostInfo[] hosts = HostInfoForTest.get(); dbProvider = new ElasticSearchDataProvider(hosts); dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); dbRawProvider = HtDatabaseClient.getClient(hosts); @@ -337,7 +337,6 @@ public class TestCRUDforDatabase { // ==UPDATE============================ System.out.println("Trying to update..."); - final String name2 = "sim88"; final String url2 = "10.5.10.2"; final long port2 = 5960; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java index 1275b0372..9a96986c0 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java @@ -22,13 +22,15 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; import static org.junit.Assert.assertEquals; + import java.io.File; -import java.lang.reflect.Field; -import java.util.Map; + import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.EsConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +40,8 @@ public class TestConfig { private static final Logger LOG = LoggerFactory.getLogger(TestConfig.class); private static final String TESTFILENAME = "testconfig.properties"; - private static final String HOSTNAME = "localhost"; + private static String ENVSDNRDBURL = "SDNRDBURL"; + private static String SDNRDBURL = "http://sdnrdb:9200"; @After @Before @@ -52,35 +55,16 @@ public class TestConfig { @Test public void test() { - int databasePort = setSDNRDBURLEnv(); - + EnvGetter env = Section.getEnvGetter(); + Section.setEnvGetter((envname) -> { + return envname.equals(ENVSDNRDBURL) ? SDNRDBURL : env.getenv(envname); + }); ConfigurationFileRepresentation configuration = new ConfigurationFileRepresentation(TESTFILENAME); EsConfig esConfig = new EsConfig(configuration); LOG.info("Defaultconfiguration: {}", esConfig.toString()); assertEquals("http", esConfig.getHosts()[0].protocol.getValue()); - assertEquals(databasePort, esConfig.getHosts()[0].port); - assertEquals(HOSTNAME, esConfig.getHosts()[0].hostname); - - } - - public static int setSDNRDBURLEnv() { - int databasePort = Integer - .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200"); - System.out.println("DB Port: " + databasePort); - setEnv("SDNRDBURL", "http://"+HOSTNAME+":"+databasePort); - return databasePort; - } + assertEquals(9200, esConfig.getHosts()[0].port); + assertEquals("sdnrdb", esConfig.getHosts()[0].hostname); - public static void setEnv(String key, String value) { - try { - Map env = System.getenv(); - Class cl = env.getClass(); - Field field = cl.getDeclaredField("m"); - field.setAccessible(true); - Map writableEnv = (Map) field.get(env); - writableEnv.put(key, value); - } catch (Exception e) { - throw new IllegalStateException("Failed to set environment variable", e); - } } } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataTreeSerialization.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataTreeSerialization.java deleted file mode 100644 index 60a2c50e4..000000000 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataTreeSerialization.java +++ /dev/null @@ -1,33 +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.test; - -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; - -/** - * @author Michael Dürre - * - */ -public class TestDataTreeSerialization { - - //YangToolsMapper -} 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 6d54016cd..9c95a7d98 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 @@ -34,11 +34,13 @@ import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; +import org.onap.ccsdk.features.sdnr.wt.common.database.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.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; 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; @@ -78,9 +80,10 @@ public class TestEventService { @BeforeClass public static void init() throws Exception { - dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + HostInfo[] hosts = HostInfoForTest.get(); + dbProvider = new ElasticSearchDataProvider(hosts); dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); - dbRawProvider = HtDatabaseClient.getClient(TestCRUDforDatabase.hosts); + dbRawProvider = HtDatabaseClient.getClient(hosts); try { service = new HtDatabaseEventsService(dbRawProvider, dbProvider); 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 52ca2999d..5c2a66e75 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 @@ -24,54 +24,89 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.Arrays; import java.util.List; import org.junit.Test; +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.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.FilterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Sortorder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.SortorderBuilder; -public class TestFilterConversion { +public class TestFilterConversion extends Mockito { private static final String PROPERTY = "node-id"; private static final String PROPERTY2 = "_id"; private static final String PROPERTY3 = "timestamp"; @Test - public void testQuestionMark() { + public void testQuestionMark1() { + EntityInput input = mock(EntityInput.class); List filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); - QueryBuilder query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + + QueryBuilder query = new QueryByFilter(input).getQueryBuilderByFilter(); System.out.println(query.toJSON()); + assertTrue(query.toJSON().contains("{1,1}")); - assertNotNull(QueryByFilter.getFilter(filters, PROPERTY)); - assertNull(QueryByFilter.getFilter(filters, PROPERTY2)); - filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), + assertNotNull(new QueryByFilter(input).getQueryBuilderByFilter(PROPERTY)); + + } + + @Test + public void testQuestionMarkExcpetion() { + EntityInput input = mock(EntityInput.class); + List filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); + when(input.getFilter()).thenReturn(filters); + try { + new QueryByFilter(input).getSearchRequestByFilter("test1", "test2", "test3", "test4"); + fail(); + } catch (IllegalArgumentException e) { // fails if type not correct + + } + + } + + @Test + public void testQuestionMark2() { + EntityInput input = mock(EntityInput.class); + List filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), new FilterBuilder().setProperty(PROPERTY2).setFiltervalue("abc").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + QueryBuilder query = new QueryByFilter(input).getQueryBuilderByFilter(); System.out.println(query.toJSON()); - assertNotNull(QueryByFilter.getFilter(filters, PROPERTY2)); - filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), + assertNotNull(new QueryByFilter(input).getQueryBuilderByFilter(PROPERTY2)); + } + + @Test + public void testQuestionMark3() { + EntityInput input = mock(EntityInput.class); + List filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), new FilterBuilder().setProperty(PROPERTY3).setFiltervalue("<2019-06-13T15:00:12.0Z").build()); - query = QueryByFilter.fromFilter(filters); List sortorder = Arrays.asList(new SortorderBuilder().setProperty(PROPERTY).setSortorder(SortOrder.Ascending).build()); - QueryByFilter.setSortOrder(query, sortorder); - assertNotNull(QueryByFilter.getSortOrder(sortorder, PROPERTY)); + when(input.getFilter()).thenReturn(filters); + when(input.getSortorder()).thenReturn(sortorder); + + assertNotNull(new QueryByFilter(input).getQueryBuilderByFilter(PROPERTY)); } @Test public void testSortorder() { - String f = - "{\"input\":{\"filter\":[],\"sortorder\":[{\"property\":\"source-type\",\"sortorder\":\"ascending\"}],\"pagination\":{\"size\":10,\"page\":1}}}"; - - QueryBuilder query = QueryByFilter.setSortOrder(QueryByFilter.fromFilter(null), Arrays - .asList(new SortorderBuilder().setProperty("source-type").setSortorder(SortOrder.Ascending).build())); + EntityInput input = mock(EntityInput.class); + List sortorder = Arrays + .asList(new SortorderBuilder().setProperty("source-type").setSortorder(SortOrder.Ascending).build()); + when(input.getSortorder()).thenReturn(sortorder); + QueryBuilder query = new QueryByFilter(input).getQueryBuilderByFilter(); System.out.println(query.toJSON()); } } 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 cc880d1ad..2aedabee4 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 @@ -26,46 +26,53 @@ import static org.junit.Assert.fail; 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.impl.DataProviderImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey; import org.opendaylight.mdsal.binding.api.RpcProviderService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DataProviderService; import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; -import net.bytebuddy.implementation.bytecode.StackSize; - /** * @author Michael Dürre * */ public class TestImplementation { + static String XY = "http://localhost:" + + (System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200"); + @Test public void test() { - TestConfig.setSDNRDBURLEnv(); + //TestConfig.setSDNRDBURLEnv("http://localhost:"+(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200")); + EnvGetter env = Section.getEnvGetter(); + Section.setEnvGetter((xy) -> { + System.out.println("Search " + xy); + return xy.equals("SDNRDBURL") ? XY : env.getenv(xy); + }); DataProviderImpl impl = new DataProviderImpl(); impl.setRpcProviderService(new RpcProviderService() { @Override public ObjectRegistration registerRpcImplementation(Class type, T implementation, Set> paths) { - // TODO Auto-generated method stub return null; } @Override public ObjectRegistration registerRpcImplementation(Class type, T implementation) { - // TODO Auto-generated method stub return null; } }); impl.setMediatorServerServlet(new MsServlet()); impl.setAboutServlet(new AboutHttpServlet()); + impl.setTreeServlet(new DataTreeHttpServlet()); try { impl.init(); } catch (Exception e) { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java index 5839738e6..897fcc8d0 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java @@ -30,10 +30,12 @@ import java.util.concurrent.TimeUnit; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; 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.model.HtDatabaseMaintenance; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.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; @@ -53,9 +55,10 @@ public class TestMaintenanceServiceData { @BeforeClass public static void init() throws Exception { - dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + HostInfo[] hosts = HostInfoForTest.get(); + dbProvider = new ElasticSearchDataProvider(hosts); dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); - dbRawProvider = HtDatabaseClient.getClient(TestCRUDforDatabase.hosts); + dbRawProvider = HtDatabaseClient.getClient(hosts); service = dbProvider.getHtDatabaseMaintenance(); } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java index 83f8de89e..7afc5214c 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java @@ -29,20 +29,20 @@ import java.util.concurrent.TimeUnit; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; 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.MediatorServerDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; /** * @author Michael Dürre - * */ public class TestMediatorServerService { - private static final String SERVERID = null; private static ElasticSearchDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; private static MediatorServerDataProvider service = null; @@ -50,13 +50,11 @@ public class TestMediatorServerService { @BeforeClass public static void init() throws Exception { - - dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + HostInfo[] hosts = HostInfoForTest.get(); + dbProvider = new ElasticSearchDataProvider(hosts); dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); - dbRawProvider = HtDatabaseClient.getClient(TestCRUDforDatabase.hosts); - service = new MediatorServerDataProvider(TestCRUDforDatabase.hosts); - - + dbRawProvider = HtDatabaseClient.getClient(hosts); + service = new MediatorServerDataProvider(hosts); } @Test diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java index f9c8812a8..bcd2ea75d 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java @@ -21,9 +21,7 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; +import static org.junit.Assert.assertTrue; import java.io.IOException; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; @@ -34,28 +32,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro public class TestNuMappings { @Test - public void test33() { + public void testMapObjectToJson() throws IOException { + YangToolsMapper mapper = new YangToolsMapper(); + Faultcurrent c = new FaultcurrentBuilder().setSeverity(SeverityType.Critical).build(); + String json = mapper.writeValueAsString(c); + assertTrue("Critical expected", json.contains(SeverityType.Critical.getName())); + } + + @Test + public void testMapJsonToObject() throws IOException { YangToolsMapper mapper = new YangToolsMapper(); - try { - System.out.println(mapper.writeValueAsString(c) + "<=>" + SeverityType.Critical.getName()); - } catch (JsonProcessingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - try { - Faultcurrent f = mapper.readValue("{\"severity\":\"Critical\"}", Faultcurrent.class); - System.out.println(f); - System.out.println(mapper.writeValueAsString(f)); - } catch (JsonParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JsonMappingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + + Faultcurrent f = mapper.readValue("{\"severity\":\"Critical\"}", Faultcurrent.class); + assertTrue("Critical expected", f.getSeverity().equals(SeverityType.Critical)); } + } 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 39377d730..e757e24d3 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 @@ -30,134 +30,165 @@ import java.util.List; 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.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; -public class TestTimestampFilter { +public class TestTimestampFilter extends Mockito { @Test public void testTimestampRange() { final String PROPERTY_TIMESTAMP = "timestamp"; List filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2017*").build()); - QueryBuilder query = QueryByFilter.fromFilter(filters); + EntityInput input = mock(EntityInput.class); + when(input.getFilter()).thenReturn(filters); + QueryBuilder query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2017-01-01T00:00:00.0Z", "2018-01-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2000-01-01T00:00:00.0Z", "3000-01-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("20*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2000-01-01T00:00:00.0Z", "2100-01-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("205*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-01-01T00:00:00.0Z", "2060-01-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-01-01T00:00:00.0Z", "2051-01-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-01-01T00:00:00.0Z", "2051-01-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-1*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-01T00:00:00.0Z", "2051-01-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-01T00:00:00.0Z", "2050-11-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-01T00:00:00.0Z", "2050-11-01T00:00:00.0Z"); filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-0*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-01T00:00:00.0Z", "2050-10-10T00:00:00.0Z"); filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-02*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-02T00:00:00.0Z", "2050-10-03T00:00:00.0Z"); filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T00:00:00.0Z", "2050-10-15T00:00:00.0Z"); filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T00:00:00.0Z", "2050-10-15T00:00:00.0Z"); filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T1*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T10:00:00.0Z", "2050-10-14T20:00:00.0Z"); filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:00:00.0Z", "2050-10-14T13:00:00.0Z"); filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:00:00.0Z", "2050-10-14T13:00:00.0Z"); filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:4*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:40:00.0Z", "2050-10-14T12:50:00.0Z"); filters = Arrays.asList( new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:42*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:42:00.0Z", "2050-10-14T12:43:00.0Z"); filters = Arrays.asList( new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:42:*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:42:00.0Z", "2050-10-14T12:43:00.0Z"); filters = Arrays.asList( new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:42:5*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:42:50.0Z", "2050-10-14T12:43:00.0Z"); filters = Arrays.asList( new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:42:56*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:42:56.0Z", "2050-10-14T12:42:57.0Z"); } @Test public void testExtra() { final String PROPERTY_TIMESTAMP = "end"; - List filters = null; - QueryBuilder query = null; + EntityInput input = mock(EntityInput.class); + List filters; + filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020-02-19T*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + QueryBuilder query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-02-19T00:00:00.0Z", "2020-02-20T00:00:00.0Z"); + filters = Arrays .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020-02-19*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-02-19T00:00:00.0Z", "2020-02-20T00:00:00.0Z"); + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020*").build()); - query = QueryByFilter.fromFilter(filters); + when(input.getFilter()).thenReturn(filters); + query = new QueryByFilter(input).getQueryBuilderByFilter(); assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-01-01T00:00:00.0Z", "2021-01-01T00:00:00.0Z"); } + private void assertRange(JSONObject rangeQuery, String property, String lower, String upper) { System.out.println("==test for " + rangeQuery.toString()); assertTrue(rangeQuery.has("range")); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java new file mode 100644 index 000000000..f2a7ff951 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java @@ -0,0 +1,81 @@ +/* + * ============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.test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; +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.http.DataTreeHttpServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.EntityWithTree; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.FilterMode; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeObject; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataTreeProviderImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; + +/** + * @author Michael Dürre + * + */ +public class TestTree { + + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + + @BeforeClass + public static void init() throws Exception { + HostInfo[] hosts = HostInfoForTest.get(); + dbProvider = new ElasticSearchDataProvider(hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = HtDatabaseClient.getClient(hosts); + } + + @Test + public void testInventoryTree() throws IOException { + DataTreeProviderImpl provider = new DataTreeProviderImpl(); + provider.setDatabaseClient(dbRawProvider); + DeleteByQueryRequest query = new DeleteByQueryRequest(Entity.Inventoryequipment.getName(), true); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + dbRawProvider.deleteByQuery(query); + + DataTreeObject tree = provider.readInventoryTree(null, null, FilterMode.Lazy); + + tree = provider.readInventoryTree(Arrays.asList("sim1"), "CARD", FilterMode.Lazy); + System.out.println(tree.toJSON()); + + } + + @Test + public void testUriConversion() { + EntityWithTree e = DataTreeHttpServlet.getEntity("/tree/read-inventoryequipment-tree/sim1/sim1%2FODU"); + System.out.println(e); + e = DataTreeHttpServlet.getEntity("/tree/read-inventoryequipment-tree/"); + System.out.println(e); + } +} 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 585f7dee2..4221891b3 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 @@ -25,19 +25,19 @@ import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.json.JSONObject; import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.database.DatabaseClient; 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.common.database.config.HostInfo.Protocol; 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.dataprovider.database.EsDataObjectReaderWriter; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateIndexRequest; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteIndexRequest; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; @@ -58,22 +58,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.pmdata15m.entity.PerformanceDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.DataBuilder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataContainer; -import org.opendaylight.yangtools.yang.binding.DataObject; public class TestYangGenSalMapping { // Create mapper for serialization and deserialization YangToolsMapper mapper = new YangToolsMapper(); - private static HostInfo[] getHostinfo() { - int databasePort = Integer - .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200"); - System.out.println("DB Port: " + databasePort); - return new HostInfo[] {new HostInfo("localhost", databasePort, Protocol.HTTP)}; - } - @Test public void test1() throws IOException { @@ -86,9 +76,10 @@ public class TestYangGenSalMapping { loginPasswordBuilder.setPassword("myTestPassword"); netconfNodeBuilder.setCredentials(loginPasswordBuilder.build()); - OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder = new OdlHelloMessageCapabilitiesBuilder(); + OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder = + new OdlHelloMessageCapabilitiesBuilder(); List uriList = new ArrayList<>(); - uriList.add( new Uri("test.uri") ); + uriList.add(new Uri("test.uri")); odlHelloMessageCapabilitiesBuilder.setCapability(uriList); netconfNodeBuilder.setOdlHelloMessageCapabilities(odlHelloMessageCapabilitiesBuilder.build()); @@ -104,50 +95,39 @@ public class TestYangGenSalMapping { NetconfNode generatedNode = mapper.readValue(res.getBytes(), NetconfNode.class); out(generatedNode.toString()); // Print it with specified indentation // Compare result - out("Equal? "+netconfNode.equals(generatedNode)); - } - - static class TestDataObjectBuilder implements Builder { - @Override - public @NonNull TestDataObject build() throws IllegalArgumentException { - return new TestDataObject(); - } - } - - static class TestDataObject implements DataObject { - String test; - - @Override - public Class getImplementedInterface() { - return null; - } + //TODO - Guilin + //out("Equal? "+netconfNode.equals(generatedNode)); } @Test - public void test2() throws Exception { + public void test2() throws Exception { - int databasePort = Integer.valueOf(System.getProperty("databaseport")!=null?System.getProperty("databaseport"):"49200"); - System.out.println("DB Port: "+databasePort); - - HostInfo[] HOSTINFOS = new HostInfo[] { new HostInfo("localhost", databasePort ,Protocol.HTTP)}; - DatabaseClient db = HtDatabaseClient.getClient(HOSTINFOS); - - EsDataObjectReaderWriter dataRW = - new EsDataObjectReaderWriter<>(db, "inventorytest", org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data.class); + final String idx = "inventorytest"; + HostInfo[] hostInfo = HostInfoForTest.get(); + HtDatabaseClient db = HtDatabaseClient.getClient(hostInfo); + EsDataObjectReaderWriter2 dataRW = + new EsDataObjectReaderWriter2<>(db, Entity.Inventoryequipment, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data.class); + if (!db.isExistsIndex(idx)) { + db.createIndex(new CreateIndexRequest(idx)); + } org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data d1; d1 = getInventoryDataBuilder("MyDescription", 23L).build(); - String id = dataRW.write(d1,null); + String id = dataRW.write(d1, null); org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data d2; d2 = dataRW.read(id); out(d2.toString()); + if (db.isExistsIndex(idx)) { + db.deleteIndex(new DeleteIndexRequest(idx)); + } } @Test - public void test3() throws IOException { + public void test3() throws IOException { PerformanceDataBuilder performanceBuilder = new PerformanceDataBuilder(); performanceBuilder.setEs(99); @@ -168,88 +148,125 @@ public class TestYangGenSalMapping { @Test public void test4() throws IOException { - - String jsonString = "{\n" + "\"node-name\": \"Sim2230\",\n" + "\"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n" - + "\"layer-protocol-name\": \"MWPS\",\n" + "\"radio-signal-id\": \"Test8\",\n" - + "\"time-stamp\": \"2017-03-01T09:15:00.0Z\",\n" + "\"granularity-period\": \"Period15Min\",\n" - + "\"scanner-id\": \"PM_RADIO_15M_4\",\n" + "\"performance-data\": {\n" + "\"unavailability\": 0,\n" - + "\"tx-level-max\": 3,\n" + "\"tx-level-avg\": 3,\n" + "\"rx-level-min\": -44,\n" - + "\"rx-level-max\": -45,\n" + "\"rx-level-avg\": -44,\n" + "\"time2-states\": 0,\n" - + "\"time4-states-s\": 0,\n" + "\"time4-states\": 0,\n" + "\"time8-states\": -1,\n" - + "\"time16-states-s\": -1,\n" + "\"time16-states\": 0,\n" + "\"time32-states\": -1,\n" - + "\"time64-states\": 900,\n" + "\"time128-states\": -1,\n" + "\"time256-states\": -1,\n" - + "\"time512-states\": -1,\n" + "\"time512-states-l\": -1,\n" + "\"time1024-states\": -1,\n" - + "\"time1024-states-l\": -1,\n" + "\"time8192-states-l\": -1,\n" + "\"time8192-states\": -1,\n" - + "\"time2048-states\": -1,\n" + "\"snir-min\": -99,\n" + "\"snir-max\": -99,\n" - + "\"snir-avg\": -99,\n" + "\"xpd-min\": -99,\n" + "\"xpd-max\": -99,\n" + "\"xpd-avg\": -99,\n" - + "\"rf-temp-min\": -99,\n" + "\"rf-temp-max\": -99,\n" + "\"rf-temp-avg\": -99,\n" - + "\"defect-blocks-sum\": -1,\n" + "\"time-period\": 900,\n" + "\"cses\": 0,\n" - + "\"time4096-states-l\": -1,\n" + "\"tx-level-min\": 3,\n" + "\"es\": 0,\n" - + "\"time2048-states-l\": -1,\n" + "\"time4096-states\": -1,\n" + "\"ses\": 0\n" + "},\n" - + "\"suspect-interval-flag\": false\n" + "}\n" + "}"; + // @formatter:off + String jsonString = "{\n" + + "\"node-name\": \"Sim2230\",\n" + + "\"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n" + + "\"layer-protocol-name\": \"MWPS\",\n" + + "\"radio-signal-id\": \"Test8\",\n" + + "\"time-stamp\": \"2017-03-01T09:15:00.0Z\",\n" + + "\"granularity-period\": \"Period15Min\",\n" + + "\"scanner-id\": \"PM_RADIO_15M_4\",\n" + + "\"performance-data\": {\n" + + "\"unavailability\": 0,\n" + + "\"tx-level-max\": 3,\n" + + "\"tx-level-avg\": 3,\n" + + "\"rx-level-min\": -44,\n" + + "\"rx-level-max\": -45,\n" + + "\"rx-level-avg\": -44,\n" + + "\"time2-states\": 0,\n" + + "\"time4-states-s\": 0,\n" + + "\"time4-states\": 0,\n" + + "\"time8-states\": -1,\n" + + "\"time16-states-s\": -1,\n" + + "\"time16-states\": 0,\n" + + "\"time32-states\": -1,\n" + + "\"time64-states\": 900,\n" + + "\"time128-states\": -1,\n" + + "\"time256-states\": -1,\n" + + "\"time512-states\": -1,\n" + + "\"time512-states-l\": -1,\n" + + "\"time1024-states\": -1,\n" + + "\"time1024-states-l\": -1,\n" + + "\"time8192-states-l\": -1,\n" + + "\"time8192-states\": -1,\n" + + "\"time2048-states\": -1,\n" + + "\"snir-min\": -99,\n" + + "\"snir-max\": -99,\n" + + "\"snir-avg\": -99,\n" + + "\"xpd-min\": -99,\n" + + "\"xpd-max\": -99,\n" + + "\"xpd-avg\": -99,\n" + + "\"rf-temp-min\": -99,\n" + + "\"rf-temp-max\": -99,\n" + + "\"rf-temp-avg\": -99,\n" + + "\"defect-blocks-sum\": -1,\n" + + "\"time-period\": 900,\n" + + "\"cses\": 0,\n" + + "\"time4096-states-l\": -1,\n" + + "\"tx-level-min\": 3,\n" + + "\"es\": 0,\n" + + "\"time2048-states-l\": -1,\n" + + "\"time4096-states\": -1,\n" + + "\"ses\": 0\n" + + "},\n" + + "\"suspect-interval-flag\": false\n" + + "}\n" + + "}"; + // @formatter:on // 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 test5() throws IOException { - String jsonString = "{\n" + - " \"time-stamp\": \"2017-03-01T06:45:00.0Z\",\n" + - " \"node-name\": \"Sim2230\",\n" + - " \"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n" + - " \"scanner-id\": \"PM_RADIO_15M_14\",\n" + - " \"layer-protocol-name\": \"MWPS\",\n" + - " \"granularity-period\": \"Period15Min\",\n" + - " \"radio-signal-id\": \"Test8\",\n" + - " \"suspect-interval-flag\": false,\n" + - " \"performance-data\": {\n" + - " \"time4096-states-l\": -1,\n" + - " \"time16-states-s\": -1,\n" + - " \"tx-level-max\": 3,\n" + - " \"snir-max\": -99,\n" + - " \"time16-states\": 0,\n" + - " \"time64-states\": 900,\n" + - " \"unavailability\": 0,\n" + - " \"time8192-states-l\": -1,\n" + - " \"time512-states\": -1,\n" + - " \"xpd-min\": -99,\n" + - " \"xpd-avg\": -99,\n" + - " \"tx-level-avg\": 3,\n" + - " \"tx-level-min\": 3,\n" + - " \"rf-temp-min\": -99,\n" + - " \"rf-temp-avg\": -99,\n" + - " \"snir-avg\": -99,\n" + - " \"snir-min\": -99,\n" + - " \"time-period\": 900,\n" + - " \"time2-states\": 0,\n" + - " \"time4-states\": 0,\n" + - " \"time8-states\": -1,\n" + - " \"ses\": 0,\n" + - " \"time2048-states-l\": -1,\n" + - " \"time2048-states\": -1,\n" + - " \"xpd-max\": -99,\n" + - " \"rf-temp-max\": -99,\n" + - " \"time8192-states\": -1,\n" + - " \"time128-states\": -1,\n" + - " \"time256-states\": -1,\n" + - " \"rx-level-min\": -44,\n" + - " \"rx-level-avg\": -44,\n" + - " \"time1024-states-l\": -1,\n" + - " \"es\": 0,\n" + - " \"cses\": 0,\n" + - " \"time4-states-s\": 0,\n" + - " \"time1024-states\": -1,\n" + - " \"time512-states-l\": -1,\n" + - " \"time4096-states\": -1,\n" + - " \"rx-level-max\": -45,\n" + - " \"defect-blocks-sum\": -1,\n" + - " \"time32-states\": -1\n" + - " }\n" + - "}"; - + // @formatter:off + String jsonString = "{\n" + + " \"time-stamp\": \"2017-03-01T06:45:00.0Z\",\n" + + " \"node-name\": \"Sim2230\",\n" + + " \"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n" + + " \"scanner-id\": \"PM_RADIO_15M_14\",\n" + + " \"layer-protocol-name\": \"MWPS\",\n" + + " \"granularity-period\": \"Period15Min\",\n" + + " \"radio-signal-id\": \"Test8\",\n" + + " \"suspect-interval-flag\": false,\n" + + " \"performance-data\": {\n" + + " \"time4096-states-l\": -1,\n" + + " \"time16-states-s\": -1,\n" + + " \"tx-level-max\": 3,\n" + + " \"snir-max\": -99,\n" + + " \"time16-states\": 0,\n" + + " \"time64-states\": 900,\n" + + " \"unavailability\": 0,\n" + + " \"time8192-states-l\": -1,\n" + + " \"time512-states\": -1,\n" + + " \"xpd-min\": -99,\n" + + " \"xpd-avg\": -99,\n" + + " \"tx-level-avg\": 3,\n" + + " \"tx-level-min\": 3,\n" + + " \"rf-temp-min\": -99,\n" + + " \"rf-temp-avg\": -99,\n" + + " \"snir-avg\": -99,\n" + + " \"snir-min\": -99,\n" + + " \"time-period\": 900,\n" + + " \"time2-states\": 0,\n" + + " \"time4-states\": 0,\n" + + " \"time8-states\": -1,\n" + + " \"ses\": 0,\n" + + " \"time2048-states-l\": -1,\n" + + " \"time2048-states\": -1,\n" + + " \"xpd-max\": -99,\n" + + " \"rf-temp-max\": -99,\n" + + " \"time8192-states\": -1,\n" + + " \"time128-states\": -1,\n" + + " \"time256-states\": -1,\n" + + " \"rx-level-min\": -44,\n" + + " \"rx-level-avg\": -44,\n" + + " \"time1024-states-l\": -1,\n" + + " \"es\": 0,\n" + + " \"cses\": 0,\n" + + " \"time4-states-s\": 0,\n" + + " \"time1024-states\": -1,\n" + + " \"time512-states-l\": -1,\n" + + " \"time4096-states\": -1,\n" + + " \"rx-level-max\": -45,\n" + + " \"defect-blocks-sum\": -1,\n" + + " \"time32-states\": -1\n" + + " }\n" + + "}"; + // @formatter:on // Map to JSON String to Object Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class); out(generatedNode.toString()); // Print it with specified indentation @@ -260,11 +277,12 @@ public class TestYangGenSalMapping { @Test public void test6() throws Exception { out(method()); - HtDatabaseClient dbClient = HtDatabaseClient.getClient(getHostinfo()); - String PMDATA15M_TYPE = "historicalperformance15min"; + HostInfo[] hostInfo = HostInfoForTest.get(); + HtDatabaseClient dbClient = HtDatabaseClient.getClient(hostInfo); - EsDataObjectReaderWriter pm15mRW = - new EsDataObjectReaderWriter<>(dbClient, PMDATA15M_TYPE, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data.class); + EsDataObjectReaderWriter2 pm15mRW = + new EsDataObjectReaderWriter2<>(dbClient, Entity.Historicalperformance15min, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data.class); pm15mRW.setEsIdAttributeName("_nodeName"); ReadPmdata15mListInputBuilder inputBuilder = new ReadPmdata15mListInputBuilder(); @@ -283,12 +301,13 @@ public class TestYangGenSalMapping { QueryBuilder query = fromFilter(input.getFilter()).from((page - 1) * pageSize).size(pageSize); setSortOrder(query, input.getSortorder()); - SearchResult result=pm15mRW.doReadAll(query); + SearchResult result = + pm15mRW.doReadAll(query); - out("Found: "+result.getHits().size()); - int t=0; + out("Found: " + result.getHits().size()); + int t = 0; for (Data hit : result.getHits()) { - out("Hit "+t+++":"+hit); + out("Hit " + t++ + ":" + hit); } setPagination(outputBuilder, page, pageSize, result.getTotal()); outputBuilder.setData(result.getHits()); @@ -297,20 +316,21 @@ public class TestYangGenSalMapping { @Test public void test7() throws Exception { out(method()); - String ESDATATYPE_MEDIATORSERVER = Entity.MediatorServer.getName(); - HtDatabaseClient dbClient = HtDatabaseClient.getClient(getHostinfo()); - EsDataObjectReaderWriter mediatorserverRW; + HostInfo[] hostInfo = HostInfoForTest.get(); + HtDatabaseClient dbClient = HtDatabaseClient.getClient(hostInfo); - mediatorserverRW = new EsDataObjectReaderWriter<>(dbClient, ESDATATYPE_MEDIATORSERVER, + EsDataObjectReaderWriter2 mediatorserverRW; + mediatorserverRW = new EsDataObjectReaderWriter2<>(dbClient, Entity.MediatorServer, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data.class) - .setWriteInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MediatorServerEntity.class) - .setEsIdAttributeName("_id"); + .setWriteInterface( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MediatorServerEntity.class) + .setEsIdAttributeName("_id"); CreateMediatorServerInputBuilder inputBuilder = new CreateMediatorServerInputBuilder(); inputBuilder.setName("Hans"); inputBuilder.setUrl("MyGreatUrl"); - String id = mediatorserverRW.write(inputBuilder.build(),"testid"); + String id = mediatorserverRW.write(inputBuilder.build(), "testid"); System.out.println(id); } @@ -320,15 +340,15 @@ public class TestYangGenSalMapping { out(method()); String input; input = "id-dd-dd"; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); input = "idDdGg"; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); input = "_idDdGg"; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); input = "--ff--gfg"; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); input = ""; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); } /* --------------------------------- @@ -339,7 +359,8 @@ public class TestYangGenSalMapping { return nameofCurrMethod; } - private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder getInventoryDataBuilder(String description, long treeLevel) { + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder getInventoryDataBuilder( + String description, long treeLevel) { org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder dataBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder(); dataBuilder.setDescription(description); @@ -377,10 +398,9 @@ public class TestYangGenSalMapping { if (filters == null || filters.size() == 0) { return QueryBuilders.matchAllQuery(); - } else if(filters.size()==1){ + } else if (filters.size() == 1) { return QueryBuilders.matchQuery(filters.get(0).getProperty(), filters.get(0).getFiltervalue()); - } - else { + } else { BoolQueryBuilder query = new BoolQueryBuilder(); for (Filter fi : filters) { query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + fi.getProperty(), @@ -390,6 +410,7 @@ public class TestYangGenSalMapping { } } + private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List sortorder) { return setSortOrder(query, sortorder, ""); } @@ -407,9 +428,12 @@ public class TestYangGenSalMapping { } - private static void setPagination(ReadPmdata15mListOutputBuilder outputBuilder, long page, long pageSize, long totalSize) { - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Pagination value = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.PaginationBuilder() - .setPage(BigInteger.valueOf(page)).setSize(pageSize).setTotal(BigInteger.valueOf(totalSize)).build(); + private static void setPagination(ReadPmdata15mListOutputBuilder outputBuilder, long page, long pageSize, + long totalSize) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Pagination value = + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.PaginationBuilder() + .setPage(BigInteger.valueOf(page)).setSize(pageSize).setTotal(BigInteger.valueOf(totalSize)) + .build(); outputBuilder.setPagination(value); } 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 19bd76cae..244d6b053 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 @@ -48,7 +48,6 @@ 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 static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/HostInfoForTest.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/HostInfoForTest.java new file mode 100644 index 000000000..8ea4b13aa --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/HostInfoForTest.java @@ -0,0 +1,53 @@ +/* + * ============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.test.util; + +import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; +import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo.Protocol; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Using pom.xml property to setup URL to database in JUnit tests. Setup impom.xml:
+ * 49402 in cooperation with plugin + * com.github.alexcojocaru elasticsearch-maven-plugin + * In local development test environment port 49200 is used. + */ +public class HostInfoForTest { + + private static final Logger LOG = LoggerFactory.getLogger(HostInfoForTest.class); + + // static methods + public static HostInfo[] get() { + int port; + + String portAsString = System.getProperty("databaseport"); + if (portAsString == null | portAsString.isEmpty()) + port = 49200; + else + port = Integer.valueOf(portAsString); + HostInfo testHost = new HostInfo("localhost", port, Protocol.HTTP); + LOG.info("Testhost {}",testHost); + return new HostInfo[] {testHost}; + } + // end of static methods +} diff --git a/sdnr/wt/data-provider/provider/src/test/resources/simplelogger.properties b/sdnr/wt/data-provider/provider/src/test/resources/simplelogger.properties index 9943c2fc3..056e91eda 100644 --- a/sdnr/wt/data-provider/provider/src/test/resources/simplelogger.properties +++ b/sdnr/wt/data-provider/provider/src/test/resources/simplelogger.properties @@ -19,10 +19,12 @@ # # -org.slf4j.simpleLogger.defaultLogLevel=INFO +org.slf4j.simpleLogger.defaultLogLevel=DEBUG org.slf4j.simpleLogger.showDateTime=true #org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z #org.slf4j.simpleLogger.showThreadName=true org.slf4j.simpleLogger.showLogName=true org.slf4j.simpleLogger.showShortLogName=false org.slf4j.simpleLogger.org.onap.ccsdk.features.sdnr.wt.dataprovider=DEBUG +org.slf4j.simpleLogger.org.onap.ccsdk.features.sdnr.wt.common=DEBUG + diff --git a/sdnr/wt/data-provider/setup/pom.xml b/sdnr/wt/data-provider/setup/pom.xml index a43ec0c52..cf7929472 100644 --- a/sdnr/wt/data-provider/setup/pom.xml +++ b/sdnr/wt/data-provider/setup/pom.xml @@ -60,12 +60,11 @@ commons-cli commons-cli - 1.4 - org.slf4j - slf4j-log4j12 - + org.slf4j + slf4j-log4j12 +
${project.groupId} sdnr-wt-common @@ -77,7 +76,6 @@ ${project.version}
- @@ -89,7 +87,7 @@ testCluster 49504 ${databaseport} - 6.5.0 + 7.1.1 @@ -133,7 +131,7 @@ sdnr-dmt - false + false org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.Program diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java index dabe0047f..100f52371 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/DataMigrationProviderImpl.java @@ -33,7 +33,6 @@ import java.util.List; import java.util.Set; import org.json.JSONObject; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.common.database.Portstatus; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; @@ -55,6 +54,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataContainer; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataMigrationReport; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ReleaseGroup; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,19 +63,13 @@ public class DataMigrationProviderImpl implements DataMigrationProviderService { private static final Logger LOG = LoggerFactory.getLogger(DataMigrationProviderImpl.class); + private final HtDatabaseClient dbClient; public DataMigrationProviderImpl(HostInfo[] hosts, String username, String password, boolean trustAll, - long timeoutms) { + long timeoutms) throws Exception { - if (timeoutms > 0) { - Portstatus.waitSecondsTillAvailable(timeoutms / 1000, hosts); - } - try { - this.dbClient = HtDatabaseClient.getClient(hosts, username, password, trustAll); - } catch (Exception e) { - throw new IllegalArgumentException("Can not reach database with parameters.",e); - } + dbClient = HtDatabaseClient.getClient(hosts, username, password, trustAll, timeoutms); } @Override @@ -125,7 +119,7 @@ public class DataMigrationProviderImpl implements DataMigrationProviderService { for (SearchHit item : data) { if (!dryrun) { String id = this.dbClient.doWriteRaw(indexName, dataTypeName, item.getId(), - item.getSourceAsString()); + item.getSourceAsString(), true); if (!item.getId().equals(id)) { LOG.warn("entry for {} with original id {} was written with another id {}", component.getValue(), item.getId(), id); @@ -268,6 +262,7 @@ public class DataMigrationProviderImpl implements DataMigrationProviderService { return entries; } + @Override public boolean initDatabase(Release release, int numShards, int numReplicas, String dbPrefix, boolean forceRecreate, long timeoutms) { @@ -278,6 +273,16 @@ public class DataMigrationProviderImpl implements DataMigrationProviderService { if (dbVersion == null) { return false; } + LOG.info("detected database version {}", dbVersion); + if (release == null) { + release = ReleaseGroup.CURRENT_RELEASE.getLatestCompatibleRelease(dbVersion); + if (release == null) { + LOG.warn("unable to autodetect release for this database version for release {}", + ReleaseGroup.CURRENT_RELEASE.name()); + return false; + } + LOG.info("autodetect release {}", release); + } if (!release.isDbInRange(dbVersion)) { LOG.warn("db version {} maybe not compatible with release {}", dbVersion, release); return false; @@ -342,6 +347,20 @@ public class DataMigrationProviderImpl implements DataMigrationProviderService { if (entries == null) { return false; } + if (release == null) { + EsVersion dbVersion = this.readActualVersion(); + if (dbVersion == null) { + return false; + } + LOG.info("detected database version {}", dbVersion); + release = ReleaseGroup.CURRENT_RELEASE.getLatestCompatibleRelease(dbVersion); + if (release == null) { + LOG.warn("unable to autodetect release for this database version for release {}", + ReleaseGroup.CURRENT_RELEASE.name()); + return false; + } + LOG.info("autodetect release {}", release); + } ReleaseInformation ri = ReleaseInformation.getInstance(release); AcknowledgedResponse response; if (entries.size() <= 0) { diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java index c7775a96b..4b201bccc 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/Program.java @@ -53,7 +53,9 @@ public class Program { private static final String CMD_LIST_VERSION = "list"; private static final String CMD_INITDB_DESCRIPTION = "initialize databse indices and aliases"; - private static final String CMD_CLEAR_DB_DESCRIPTION = "clear database indices and aliases"; + private static final String CMD_CLEAR_DB_DESCRIPTION = "delete database indices and aliases for current release"; + private static final String CMD_CLEAR_DB_COMPLETE_DESCRIPTION = "delete all database indices and aliases"; + private static final String CMD_CREATE_PLUGIN_INIT_FILE_DESCRIPTION = "create maven plugin file"; private static final String CMD_IMPORT_DESCRIPTION = "import data into database"; private static final String CMD_EXPORT_DESCRIPTION = "export data from database"; @@ -61,31 +63,51 @@ public class Program { private static final List commands = Arrays.asList(new String[] {CMD_INITDB, CMD_INITDB_DESCRIPTION}, new String[] {CMD_CLEAR_DB, CMD_CLEAR_DB_DESCRIPTION}, + new String[] {CMD_CLEAR_DB_COMPLETE, CMD_CLEAR_DB_COMPLETE_DESCRIPTION}, new String[] {CMD_CREATE_PLUGIN_INIT_FILE, CMD_CREATE_PLUGIN_INIT_FILE_DESCRIPTION}, new String[] {CMD_IMPORT, CMD_IMPORT_DESCRIPTION}, new String[] {CMD_EXPORT, CMD_EXPORT_DESCRIPTION}, new String[] {CMD_LIST_VERSION, CMD_LIST_VERSION_DESCRIPTION}); private static final String APPLICATION_NAME = "SDNR DataMigrationTool"; + private static final int DEFAULT_SHARDS = 5; private static final int DEFAULT_REPLICAS = 1; + private static final int DEFAULT_DATABASEWAIT_SECONDS = 30; private static final String DEFAULT_DBURL = "http://sdnrdb:9200"; private static final String DEFAULT_DBPREFIX = ""; + private static final boolean DEFAULT_TRUSTINSECURESSL = false; + private static final String OPTION_FORCE_RECREATE_SHORT = "f"; + private static final String OPTION_FORCE_RECREATE_LONG = "force-recreate"; private static final String OPTION_SILENT_SHORT = "n"; private static final String OPTION_SILENT = "silent"; private static final String OPTION_VERSION_SHORT = "v"; + private static final String OPTION_VERSION_LONG = "version"; private static final String OPTION_SHARDS_SHORT = "s"; + private static final String OPTION_SHARDS_LONG = "shards"; private static final String OPTION_REPLICAS_SHORT = "r"; + private static final String OPTION_REPLICAS_LONG = "replicas"; private static final String OPTION_OUTPUTFILE_SHORT = "of"; + private static final String OPTION_OUTPUTFILE_LONG = "output-file"; private static final String OPTION_INPUTFILE_SHORT = "if"; + private static final String OPTION_INPUTFILE_LONG = "input-file"; private static final String OPTION_DEBUG_SHORT = "x"; + private static final String OPTION_DEBUG_LONG = "verbose"; private static final String OPTION_TRUSTINSECURESSL_SHORT = "k"; + private static final String OPTION_TRUSTINSECURESSL_LONG = "trust-insecure"; private static final String OPTION_DATABASE_SHORT = "db"; + private static final String OPTION_DATABASE_LONG = "dburl"; private static final String OPTION_COMMAND_SHORT = "c"; + private static final String OPTION_COMMAND_LONG = "cmd"; private static final String OPTION_DATABASEUSER_SHORT = "dbu"; + private static final String OPTION_DATABASEUSER_LONG = "db-username"; private static final String OPTION_DATABASEPASSWORD_SHORT = "dbp"; + private static final String OPTION_DATABASEPASSWORD_LONG = "db-password"; private static final String OPTION_DATABASEPREFIX_SHORT = "p"; + private static final String OPTION_DATABASEPREFIX_LONG = "prefix"; private static final String OPTION_DATABASEWAIT_SHORT = "w"; + private static final String OPTION_DATABASEWAIT_LONG = "wait"; private static final String OPTION_HELP_SHORT = "h"; + private static final String OPTION_HELP_LONG = "help"; // end of constants // variables @@ -111,6 +133,9 @@ public class Program { if (def instanceof Long) { return cmd.hasOption(option) ? (T) Long.valueOf(cmd.getOptionValue(option)) : def; } + if (def instanceof Release) { + return cmd.hasOption(option) ? (T) Release.getValueBySuffix(cmd.getOptionValue(option)) : def; + } if (cmd.hasOption(option) && cmd.getOptionValue(option) != null) { if (option.equals(OPTION_VERSION_SHORT)) { String v = cmd.getOptionValue(option); @@ -215,7 +240,8 @@ public class Program { if (of == null) { throw new Exception("please add the parameter output-file"); } - MavenDatabasePluginInitFile.create(Release.CURRENT_RELEASE, of); + MavenDatabasePluginInitFile + .create(getOptionOrDefault(cmd, OPTION_VERSION_SHORT, Release.CURRENT_RELEASE), of); } catch (Exception e) { return exit(e); } @@ -271,11 +297,11 @@ public class Program { String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null); String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null); String filename = getOptionOrDefault(cmd, OPTION_OUTPUTFILE_SHORT, null); - boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, false); + boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL); if (filename == null) { throw new Exception("please add output file parameter"); } - long timeoutms = getOptionOrDefault(cmd, OPTION_DATABASEWAIT_SHORT, 30) * 1000; + long timeoutms = getTimeoutOptionMillis(cmd); DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)}, username, password, trustAll, timeoutms); DataMigrationReport report = service.importData(filename, false); @@ -283,6 +309,7 @@ public class Program { if (!report.completed()) { throw new Exception("db import seems to be not executed completed"); } + LOG.info("database import completed successfully"); } private static void cmd_dbexport(CommandLine cmd) throws Exception { @@ -290,11 +317,11 @@ public class Program { String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null); String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null); String filename = getOptionOrDefault(cmd, OPTION_OUTPUTFILE_SHORT, null); - boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, false); + boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL); if (filename == null) { throw new Exception("please add output file parameter"); } - long timeoutms = getOptionOrDefault(cmd, OPTION_DATABASEWAIT_SHORT, 30) * 1000; + long timeoutms = getTimeoutOptionMillis(cmd); DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)}, username, password, trustAll, timeoutms); DataMigrationReport report = service.exportData(filename); @@ -302,7 +329,7 @@ public class Program { if (!report.completed()) { throw new Exception("db export seems to be not executed completed"); } - + LOG.info("database export completed successfully"); } private static int exit(Exception e) { @@ -315,85 +342,96 @@ public class Program { } private static void cmd_clear_db(CommandLine cmd) throws Exception { - Release r = getOptionOrDefault(cmd, OPTION_VERSION_SHORT, Release.CURRENT_RELEASE); + Release r = getOptionOrDefault(cmd, OPTION_VERSION_SHORT, (Release) null); String dbUrl = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL); String dbPrefix = getOptionOrDefault(cmd, OPTION_DATABASEPREFIX_SHORT, DEFAULT_DBPREFIX); String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null); String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null); - boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, false); - long timeoutms = getOptionOrDefault(cmd, OPTION_DATABASEWAIT_SHORT, 30) * 1000; + boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL); + long timeoutms = getTimeoutOptionMillis(cmd); DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)}, username, password, trustAll, timeoutms); if (!service.clearDatabase(r, dbPrefix, timeoutms)) { throw new Exception("failed to init database"); } + LOG.info("database clear completed successfully"); } private static void cmd_clear_db_complete(CommandLine cmd) throws Exception { String dbUrl = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL); String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null); String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null); - boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, false); - long timeoutms = getOptionOrDefault(cmd, OPTION_DATABASEWAIT_SHORT, 30) * 1000; + boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL); + long timeoutms = getTimeoutOptionMillis(cmd); DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)}, username, password, trustAll, timeoutms); if (!service.clearCompleteDatabase(timeoutms)) { throw new Exception("failed to init database"); } + LOG.info("database complete clear completed successfully"); } private static void cmd_init_db(CommandLine cmd) throws Exception { - Release r = getOptionOrDefault(cmd, OPTION_VERSION_SHORT, Release.CURRENT_RELEASE); + Release r = getOptionOrDefault(cmd, OPTION_VERSION_SHORT, (Release) null); int numShards = getOptionOrDefault(cmd, OPTION_SHARDS_SHORT, DEFAULT_SHARDS); int numReplicas = getOptionOrDefault(cmd, OPTION_REPLICAS_SHORT, DEFAULT_REPLICAS); String dbUrl = getOptionOrDefault(cmd, OPTION_DATABASE_SHORT, DEFAULT_DBURL); String dbPrefix = getOptionOrDefault(cmd, OPTION_DATABASEPREFIX_SHORT, DEFAULT_DBPREFIX); String username = getOptionOrDefault(cmd, OPTION_DATABASEUSER_SHORT, null); String password = getOptionOrDefault(cmd, OPTION_DATABASEPASSWORD_SHORT, null); - boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, false); - long timeoutms = getOptionOrDefault(cmd, OPTION_DATABASEWAIT_SHORT, 30) * 1000; + boolean trustAll = getOptionOrDefault(cmd, OPTION_TRUSTINSECURESSL_SHORT, DEFAULT_TRUSTINSECURESSL); + long timeoutms = getTimeoutOptionMillis(cmd); DataMigrationProviderImpl service = new DataMigrationProviderImpl(new HostInfo[] {HostInfo.parse(dbUrl)}, username, password, trustAll, timeoutms); boolean forceRecreate = cmd.hasOption(OPTION_FORCE_RECREATE_SHORT); if (!service.initDatabase(r, numShards, numReplicas, dbPrefix, forceRecreate, timeoutms)) { throw new Exception("failed to init database"); } + LOG.info("database init completed successfully"); } private static Options init() { Options result = new Options(); - result.addOption(createOption(OPTION_COMMAND_SHORT, "cmd", true, "command to execute", false)); - result.addOption(createOption(OPTION_DATABASE_SHORT, "dburl", true, "database url", false)); - result.addOption( - createOption(OPTION_DATABASEUSER_SHORT, "db-username", true, "database basic auth username", false)); - result.addOption(createOption(OPTION_DATABASEPASSWORD_SHORT, "db-password", true, + result.addOption(createOption(OPTION_COMMAND_SHORT, OPTION_COMMAND_LONG, true, "command to execute", false)); + result.addOption(createOption(OPTION_DATABASE_SHORT, OPTION_DATABASE_LONG, true, "database url", false)); + result.addOption(createOption(OPTION_DATABASEUSER_SHORT, OPTION_DATABASEUSER_LONG, true, + "database basic auth username", false)); + result.addOption(createOption(OPTION_DATABASEPASSWORD_SHORT, OPTION_DATABASEPASSWORD_LONG, true, "database basic auth password", false)); - result.addOption(createOption(OPTION_REPLICAS_SHORT, "replicas", true, "amount of replicas", false)); - result.addOption(createOption(OPTION_SHARDS_SHORT, "shards", true, "amount of shards", false)); - result.addOption(createOption(OPTION_DATABASEPREFIX_SHORT, "prefix", true, "prefix for db indices", false)); - result.addOption(createOption(OPTION_VERSION_SHORT, "version", true, "version", false)); - result.addOption(createOption(OPTION_DEBUG_SHORT, "verbose", false, "verbose mode", false)); - result.addOption(createOption(OPTION_TRUSTINSECURESSL_SHORT, "trust-insecure", false, + result.addOption(createOption(OPTION_REPLICAS_SHORT, OPTION_REPLICAS_LONG, true, "amount of replicas", false)); + result.addOption(createOption(OPTION_SHARDS_SHORT, OPTION_SHARDS_LONG, true, "amount of shards", false)); + result.addOption(createOption(OPTION_DATABASEPREFIX_SHORT, OPTION_DATABASEPREFIX_LONG, true, + "prefix for db indices", false)); + result.addOption(createOption(OPTION_VERSION_SHORT, OPTION_VERSION_LONG, true, "version", false)); + result.addOption(createOption(OPTION_DEBUG_SHORT, OPTION_DEBUG_LONG, false, "verbose mode", false)); + result.addOption(createOption(OPTION_TRUSTINSECURESSL_SHORT, OPTION_TRUSTINSECURESSL_LONG, false, "trust insecure ssl certs", false)); - result.addOption(createOption(OPTION_DATABASEWAIT_SHORT, "wait", true, + result.addOption(createOption(OPTION_DATABASEWAIT_SHORT, OPTION_DATABASEWAIT_LONG, true, "wait for yellow status with timeout in seconds", false)); - result.addOption( - createOption(OPTION_FORCE_RECREATE_SHORT, "force-recreate", false, "delete if sth exists", false)); + result.addOption(createOption(OPTION_FORCE_RECREATE_SHORT, OPTION_FORCE_RECREATE_LONG, false, + "delete if sth exists", false)); result.addOption(createOption(OPTION_SILENT_SHORT, OPTION_SILENT, false, "prevent console output", false)); - result.addOption(createOption(OPTION_OUTPUTFILE_SHORT, "output-file", true, "file to write into", false)); - result.addOption(createOption(OPTION_INPUTFILE_SHORT, "input-file", true, "file to read from", false)); - result.addOption(createOption(OPTION_HELP_SHORT, "help", false, "show help", false)); + result.addOption( + createOption(OPTION_OUTPUTFILE_SHORT, OPTION_OUTPUTFILE_LONG, true, "file to write into", false)); + result.addOption(createOption(OPTION_INPUTFILE_SHORT, OPTION_INPUTFILE_LONG, true, "file to read from", false)); + result.addOption(createOption(OPTION_HELP_SHORT, OPTION_HELP_LONG, false, "show help", false)); return result; } + private static long getTimeoutOptionMillis(CommandLine cmd) throws ParseException { + return getOptionOrDefault(cmd, OPTION_DATABASEWAIT_SHORT, DEFAULT_DATABASEWAIT_SECONDS) * 1000; + } + /** - * @param opt - * @param longOpt - * @param hasArg - * @param description - * @param required - * @return + * create option for argparse lib + * + * @param opt short option string + * @param longOpt long option string + * @param hasArg flag if has a parameter after option tag + * @param description description for help output + * @param required flag if is required for program + * @return option object for argparse lib */ private static Option createOption(String opt, String longOpt, boolean hasArg, String description, boolean required) { diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/ReleaseInformation.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/ReleaseInformation.java index cb20025ff..d772dc296 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/ReleaseInformation.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/ReleaseInformation.java @@ -33,7 +33,9 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.elalto.ElAltoReleaseInformation; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformationR2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin.GuilinReleaseInformation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin.GuilinReleaseInformationR2; public abstract class ReleaseInformation { @@ -138,8 +140,12 @@ public abstract class ReleaseInformation { return new ElAltoReleaseInformation(); case FRANKFURT_R1: return new FrankfurtReleaseInformation(); - case GUILIN: + case FRANKFURT_R2: + return new FrankfurtReleaseInformationR2(); + case GUILIN_R1: return new GuilinReleaseInformation(); + case GUILIN_R2: + return new GuilinReleaseInformationR2(); default: return null; } diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo.java index 4c38b5032..51acd0782 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo.java @@ -28,7 +28,7 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data; public class DatabaseInfo { public final String doctype; public final String alias; - private final String mapping; + protected final String mapping; private final String settingsFormat; private final String index; diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo7.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo7.java new file mode 100644 index 000000000..58b98c2aa --- /dev/null +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/DatabaseInfo7.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data; + +/** + * @author Michael Dürre + * + */ +public class DatabaseInfo7 extends DatabaseInfo { + + public DatabaseInfo7(String alias, String doctype, String mapping) { + super(alias, alias, doctype, mapping); + } + + public DatabaseInfo7(String index, String alias, String doctype, String mapping, String settingsformat) { + super(index, alias, doctype, mapping, settingsformat); + } + + @Override + public String getMapping(boolean useStrict) { + return this.mapping == null ? null + : String.format("{%s\"properties\":%s}", useStrict ? "\"dynamic\": false," : "\"dynamic\": true,", + this.mapping); + } +} diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/MavenDatabasePluginInitFile.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/MavenDatabasePluginInitFile.java index 66a5e16d0..3f6334a1e 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/MavenDatabasePluginInitFile.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/MavenDatabasePluginInitFile.java @@ -50,6 +50,7 @@ public class MavenDatabasePluginInitFile { ReleaseInformation ri = ReleaseInformation.getInstance(release); Set comps = ri.getComponents(); List lines = new ArrayList<>(); + lines.add("PUT:_cluster/settings/:{\"persistent\":{\"action.auto_create_index\":\"true\"}}"); for (ComponentName c : comps) { lines.add(String.format("PUT:%s/:{" + settings + "," + mappings + "}", ri.getIndex(c), shards, replicas, ri.getDatabaseMapping(c))); diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/Release.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/Release.java index 13c604716..b2442df6b 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/Release.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/Release.java @@ -27,11 +27,12 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.data.EsVersion; public enum Release { EL_ALTO("el alto", "_v1", new EsVersion(2, 2, 0), new EsVersion(2, 2, 0)), FRANKFURT_R1("frankfurt-R1", "-v2", - new EsVersion(6, 4, 3), new EsVersion(6, 8, 6)), FRANKFURT_R2("frankfurt-R2", "", new EsVersion(6, 4, 3), - new EsVersion(6, 8, 6)), FRANKFURT_R3("frankfurt-R3", "", new EsVersion(6, 4, 3), - new EsVersion(6, 8, 6)), + new EsVersion(6, 4, 3), new EsVersion(6, 8, 6)), FRANKFURT_R2("frankfurt-R2", "-v3", new EsVersion(7, 0, 1), + new EsVersion(7, 6, 1)), + //FRANKFURT_R3("frankfurt-R3","",new EsVersion(6,4,3),new EsVersion(6,8,6)), - GUILIN("guilin", "", new EsVersion(6, 4, 3), new EsVersion(6, 8, 6)); + GUILIN_R1("guilin-R1", "-v4", new EsVersion(6, 4, 3), new EsVersion(6, 8, 6)), GUILIN_R2("guilin-R2", "-v5", + new EsVersion(7, 0, 1), new EsVersion(7, 6, 1)); public static final Release CURRENT_RELEASE = Release.FRANKFURT_R1; @@ -67,6 +68,9 @@ public enum Release { } public static Release getValueBySuffix(String suffix) { + if (!suffix.startsWith("-")) { + suffix = "-" + suffix; + } for (Release r : Release.values()) { if (r.dbSuffix.equals(suffix)) return r; diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ReleaseGroup.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ReleaseGroup.java new file mode 100644 index 000000000..c7d26dbed --- /dev/null +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/ReleaseGroup.java @@ -0,0 +1,66 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.ccsdk.features.sdnr.wt.common.database.data.EsVersion; + +/** + * @author Michael Dürre + * + */ +public enum ReleaseGroup { + + EL_ALTO(Release.EL_ALTO), FRANKFURT(Release.FRANKFURT_R1, Release.FRANKFURT_R2), GUILIN(Release.GUILIN_R1, + Release.GUILIN_R2); + + public static final ReleaseGroup CURRENT_RELEASE = FRANKFURT; + + private final List releases; + + ReleaseGroup(Release... values) { + this.releases = new ArrayList(); + if (values != null) { + for (Release r : values) { + this.releases.add(r); + } + } + } + + /** + * @param dbVersion + * @return + */ + public Release getLatestCompatibleRelease(EsVersion dbVersion) { + Release match = null; + for (Release r : this.releases) { + if (r.isDbInRange(dbVersion)) { + match = r; + } + } + return match; + } + + +} diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/SearchHitConverter.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/SearchHitConverter.java index a95a405d6..87c4d6434 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/SearchHitConverter.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/data/SearchHitConverter.java @@ -22,9 +22,7 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.elalto.ElAltoReleaseInformation; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt.FrankfurtReleaseInformation; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin.GuilinReleaseInformation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation; public interface SearchHitConverter { @@ -46,17 +44,8 @@ public interface SearchHitConverter { public static class Factory { public static SearchHitConverter getInstance(Release src, Release dst, ComponentName component) { - switch (src) { - case EL_ALTO: - return new ElAltoReleaseInformation().getConverter(dst, component); - case FRANKFURT_R1: - return new FrankfurtReleaseInformation().getConverter(dst, component); - case GUILIN: - return new GuilinReleaseInformation().getConverter(dst, component); - default: - return null; - - } + ReleaseInformation ri = ReleaseInformation.getInstance(src); + return ri != null ? ri.getConverter(dst, component) : null; } } diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/frankfurt/FrankfurtReleaseInformation.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/frankfurt/FrankfurtReleaseInformation.java index ad0abee89..7b8c40bca 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/frankfurt/FrankfurtReleaseInformation.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/frankfurt/FrankfurtReleaseInformation.java @@ -86,7 +86,7 @@ public class FrankfurtReleaseInformation extends ReleaseInformation { ClusterSettingsResponse response = null; try { - response = dbClient.setupClusterSettings(new ClusterSettingsRequest(false)); + response = dbClient.setupClusterSettings(new ClusterSettingsRequest(false).maxCompilationsPerMinute(400)); } catch (IOException e) { LOG.warn("problem setting up cluster: {}", e); } diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/frankfurt/FrankfurtReleaseInformationR2.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/frankfurt/FrankfurtReleaseInformationR2.java new file mode 100644 index 000000000..e842b5c7b --- /dev/null +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/frankfurt/FrankfurtReleaseInformationR2.java @@ -0,0 +1,102 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.frankfurt; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo7; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterSettingsRequest; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterSettingsResponse; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation; + +public class FrankfurtReleaseInformationR2 extends ReleaseInformation { + + private final Logger LOG = LoggerFactory.getLogger(FrankfurtReleaseInformationR2.class); + private final Map> converters = new HashMap<>(); + + public FrankfurtReleaseInformationR2() { + super(Release.FRANKFURT_R2, createDBMap()); + } + + private static Map createDBMap() { + Map map = new HashMap<>(); + map.put(ComponentName.CONNECTIONLOG, new DatabaseInfo7("connectionlog", "connectionlog", + "{\"node-id\": {\"type\": \"keyword\"},\"timestamp\": {\"type\": \"date\"},\"status\": {\"type\": \"keyword\"}}")); + map.put(ComponentName.EVENTLOG, new DatabaseInfo7("eventlog", "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\"}}")); + map.put(ComponentName.FAULTCURRENT, new DatabaseInfo7("faultcurrent", "faultcurrent", + "{\"node-id\": {\"type\": \"keyword\"},\"severity\": {\"type\": \"keyword\"},\"timestamp\": {\"type\": \"date\"},\"problem\": {\"type\": \"keyword\"},\"counter\": {\"type\": \"long\"},\"object-id\":{\"type\": \"keyword\"}}")); + map.put(ComponentName.FAULTLOG, new DatabaseInfo7("faultlog", "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\"}}")); + map.put(ComponentName.INVENTORY, new DatabaseInfo7("inventoryequipment", "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\"}}")); + map.put(ComponentName.HISTORICAL_PERFORMANCE_15M, new DatabaseInfo7("historicalperformance15min", + "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\"}}")); + map.put(ComponentName.HISTORICAL_PERFORMANCE_24H, new DatabaseInfo7("historicalperformance24h", + "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\"}}")); + map.put(ComponentName.REQUIRED_NETWORKELEMENT, new DatabaseInfo7("networkelement-connection", + "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\"}}")); + map.put(ComponentName.MEDIATOR_SERVER, new DatabaseInfo7("mediator-server", "mediator-server", + "{\"url\":{\"type\": \"keyword\"},\"name\":{\"type\": \"keyword\"}}")); + map.put(ComponentName.MAINTENANCE, new DatabaseInfo7("maintenancemode", "maintenancemode", + "{\"node-id\": {\"type\": \"keyword\"},\"start\": {\"type\": \"date\"},\"end\": {\"type\": \"date\"},\"description\": {\"type\": \"keyword\"},\"active\": {\"type\": \"boolean\"}},\"date_detection\":false}}")); + return map; + } + + @Override + public SearchHitConverter getConverter(Release dst, ComponentName comp) { + SearchHitConverter c = this.converters.containsKey(dst) ? this.converters.get(dst).get(comp) : null; + if (c == null) { + c = super.getConverter(dst, comp); + } + return c; + } + + @Override + protected boolean runPreInitCommands(HtDatabaseClient dbClient) { + + ClusterSettingsResponse response = null; + try { + response = dbClient.setupClusterSettings(new ClusterSettingsRequest(false).maxCompilationsPerMinute(400)); + } catch (IOException e) { + LOG.warn("problem setting up cluster: {}", e); + } + return response == null ? false : response.isAcknowledged(); + } + + @Override + protected boolean runPostInitCommands(HtDatabaseClient dbClient) { + return true; + } + +} diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/guilin/GuilinReleaseInformation.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/guilin/GuilinReleaseInformation.java index a81a6f0fd..2c2ac25a9 100644 --- a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/guilin/GuilinReleaseInformation.java +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/guilin/GuilinReleaseInformation.java @@ -22,16 +22,15 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin; import java.util.HashMap; -import java.util.List; import java.util.Map; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter; -import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo; public class GuilinReleaseInformation extends ReleaseInformation { @@ -40,7 +39,7 @@ public class GuilinReleaseInformation extends ReleaseInformation { * @param dbMap */ public GuilinReleaseInformation() { - super(Release.GUILIN, createDBMap()); + super(Release.GUILIN_R1, createDBMap()); } @@ -63,7 +62,7 @@ public class GuilinReleaseInformation extends ReleaseInformation { @Override public SearchHitConverter getConverter(Release dst, ComponentName comp) { - if (dst == Release.GUILIN) { + if (dst == Release.GUILIN_R1) { return new KeepDataSearchHitConverter(comp); } return null; diff --git a/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/guilin/GuilinReleaseInformationR2.java b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/guilin/GuilinReleaseInformationR2.java new file mode 100644 index 000000000..29c79f3da --- /dev/null +++ b/sdnr/wt/data-provider/setup/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/guilin/GuilinReleaseInformationR2.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.guilin; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.ReleaseInformation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DatabaseInfo; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.KeepDataSearchHitConverter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.SearchHitConverter; + +public class GuilinReleaseInformationR2 extends ReleaseInformation { + + /** + * @param r + * @param dbMap + */ + public GuilinReleaseInformationR2() { + super(Release.GUILIN_R2, createDBMap()); + + } + + private static Map createDBMap() { + Map map = new HashMap<>(); + map.put(ComponentName.EVENTLOG, new DatabaseInfo("eventlog", "eventlog", "")); + map.put(ComponentName.FAULTCURRENT, new DatabaseInfo("faultcurrent", "faultcurrent", "")); + map.put(ComponentName.FAULTLOG, new DatabaseInfo("faultlog", "faultlog", "")); + map.put(ComponentName.INVENTORY, new DatabaseInfo("inventoryequipment", "inventoryequipment", "")); + map.put(ComponentName.HISTORICAL_PERFORMANCE_15M, + new DatabaseInfo("historicalperformance15min", "historicalperformance15min", "")); + map.put(ComponentName.HISTORICAL_PERFORMANCE_24H, + new DatabaseInfo("historicalperformance24h", "historicalperformance24h", "")); + map.put(ComponentName.REQUIRED_NETWORKELEMENT, + new DatabaseInfo("networkelement-connection", "networkelement-connection", "")); + map.put(ComponentName.MEDIATOR_SERVER, new DatabaseInfo("mediator-server", "mediator-server", "")); + map.put(ComponentName.MAINTENANCE, new DatabaseInfo("maintenancemode", "maintenancemode", "")); + return map; + } + + @Override + public SearchHitConverter getConverter(Release dst, ComponentName comp) { + if (dst == Release.GUILIN_R2) { + return new KeepDataSearchHitConverter(comp); + } + return null; + } + + @Override + protected boolean runPreInitCommands(HtDatabaseClient dbClient) { + return true; + } + + @Override + protected boolean runPostInitCommands(HtDatabaseClient dbClient) { + return true; + } + +} diff --git a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestData.java b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestData.java index c7864560b..ab0510c9c 100644 --- a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestData.java +++ b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestData.java @@ -48,32 +48,79 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; * */ public class TestData { - private static final JSONObject EVENTLOG_SEARCHHIT = new JSONObject("{\n" + "\"_index\": \"sdnevents_v1\",\n" - + "\"_type\": \"eventlog\",\n" + "\"_id\": \"AXB7cJHlZ_FApnwi29xq\",\n" + "\"_version\": 1,\n" - + "\"_score\": 1,\n" + "\"_source\": {\n" + "\"event\": {\n" - + "\"nodeName\": \"SDN-Controller-465e2ae306ca\",\n" + "\"counter\": \"1\",\n" - + "\"timeStamp\": \"2020-02-25T08:22:19.8Z\",\n" + "\"objectId\": \"sim2230\",\n" - + "\"attributeName\": \"ConnectionStatus\",\n" + "\"newValue\": \"connecting\",\n" - + "\"type\": \"AttributeValueChangedNotificationXml\"\n" + "}\n" + "}\n" + "}"); - private static final JSONObject EVENTLOG_SEARCHHIT2 = new JSONObject("{\n" + "\"_index\": \"sdnevents_v1\",\n" - + "\"_type\": \"eventlog\",\n" + "\"_id\": \"AXB7cJHlZ_FApnwi29xq\",\n" + "\"_version\": 1,\n" - + "\"_score\": 1,\n" + "\"_source\": {\n" + "\"event\": {\n" - + "\"nodeName\": \"SDN-Controller-465e2ae306ca\",\n" + "\"counter\": \"3\",\n" - + "\"timeStamp\": \"2020-02-22T08:22:19.8Z\",\n" + "\"objectId\": \"sim2230\",\n" - + "\"attributeName\": \"ConnectionStatus\",\n" + "\"newValue\": \"connected\",\n" - + "\"type\": \"AttributeValueChangedNotificationXml\"\n" + "}\n" + "}\n" + "}"); - private static final String CONFIG_CONTENT = "[dcae]\n" + "dcaeUserCredentials=admin:admin\n" + "dcaeUrl=off\n" - + "dcaeHeartbeatPeriodSeconds=120\n" + "dcaeTestCollector=no\n" + "\n" + "[es]\n" - + "esCluster=sendateodl5\n" + "#time limit to keep increasing data in database [in seconds]\n" - + "#60*60*24*30 (30days)\n" + "esArchiveLimit=2592000\n" + "#folder where removed data will be stored\n" - + "esArchiveFolder=./backup\n" + "#interval to archive database [in seconds]\n" + "#60*60*24 (1day)\n" - + "esArchiveInterval=86400\n" + "\n" + "[aai]\n" + "#keep comment\n" - + "aaiHeaders=[\"X-TransactionId: 9999\"]\n" + "aaiUrl=http://localhost:81\n" - + "aaiUserCredentials=AAI:AAI\n" + "aaiDeleteOnMountpointRemove=false\n" + "aaiTrustAllCerts=false\n" - + "aaiApiVersion=aai/v13\n" + "aaiPropertiesFile=aaiclient.properties\n" + "aaiApplicationId=SDNR\n" + // @formatter:off + private static final JSONObject EVENTLOG_SEARCHHIT = new JSONObject("{\n" + + "\"_index\": \"sdnevents_v1\",\n" + + "\"_type\": \"eventlog\",\n" + + "\"_id\": \"AXB7cJHlZ_FApnwi29xq\",\n" + + "\"_version\": 1,\n" + + "\"_score\": 1,\n" + + "\"_source\": {\n" + + "\"event\": {\n" + + "\"nodeName\": \"SDN-Controller-465e2ae306ca\",\n" + + "\"counter\": \"1\",\n" + + "\"timeStamp\": \"2020-02-25T08:22:19.8Z\",\n" + + "\"objectId\": \"sim2230\",\n" + + "\"attributeName\": \"ConnectionStatus\",\n" + + "\"newValue\": \"connecting\",\n" + + "\"type\": \"AttributeValueChangedNotificationXml\"\n" + + "}\n" + + "}\n" + + "}"); + private static final JSONObject EVENTLOG_SEARCHHIT2 = new JSONObject("{\n" + + "\"_index\": \"sdnevents_v1\",\n" + + "\"_type\": \"eventlog\",\n" + + "\"_id\": \"AXB7cJHlZ_FApnwi29xq\",\n" + + "\"_version\": 1,\n" + + "\"_score\": 1,\n" + + "\"_source\": {\n" + + "\"event\": {\n" + + "\"nodeName\": \"SDN-Controller-465e2ae306ca\",\n" + + "\"counter\": \"3\",\n" + + "\"timeStamp\": \"2020-02-22T08:22:19.8Z\",\n" + + "\"objectId\": \"sim2230\",\n" + + "\"attributeName\": \"ConnectionStatus\",\n" + + "\"newValue\": \"connected\",\n" + + "\"type\": \"AttributeValueChangedNotificationXml\"\n" + + "}\n" + + "}\n" + + "}"); + private static final String CONFIG_CONTENT = "[dcae]\n" + + "dcaeUserCredentials=admin:admin\n" + + "dcaeUrl=off\n" + + "dcaeHeartbeatPeriodSeconds=120\n" + + "dcaeTestCollector=no\n" + + "\n" + + "[es]\n" + + "esCluster=sendateodl5\n" + + "#time limit to keep increasing data in database [in seconds]\n" + + "#60*60*24*30 (30days)\n" + + "esArchiveLimit=2592000\n" + + "#folder where removed data will be stored\n" + + "esArchiveFolder=./backup\n" + + "#interval to archive database [in seconds]\n" + + "#60*60*24 (1day)\n" + + "esArchiveInterval=86400\n" + + "\n" + + "[aai]\n" + + "#keep comment\n" + + "aaiHeaders=[\"X-TransactionId: 9999\"]\n" + + "aaiUrl=http://localhost:81\n" + + "aaiUserCredentials=AAI:AAI\n" + + "aaiDeleteOnMountpointRemove=false\n" + + "aaiTrustAllCerts=false\n" + + "aaiApiVersion=aai/v13\n" + + "aaiPropertiesFile=aaiclient.properties\n" + + "aaiApplicationId=SDNR\n" + "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n" - + "aaiPcks12ClientCertPassphrase=adminadmin\n" + "aaiClientConnectionTimeout=30000\n" + "\n" + "[pm]\n" - + "pmCluster=sendateodl5\n" + "pmEnabled=true\n" + ""; + + "aaiPcks12ClientCertPassphrase=adminadmin\n" + + "aaiClientConnectionTimeout=30000\n" + + "\n" + + "[pm]\n" + + "pmCluster=sendateodl5\n" + + "pmEnabled=true\n" + + ""; + // @formatter:on @Test public void testComponentData() { diff --git a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestMigrationProvider.java b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestMigrationProvider.java index 02877f0c8..32438410f 100644 --- a/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestMigrationProvider.java +++ b/sdnr/wt/data-provider/setup/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/setup/TestMigrationProvider.java @@ -27,7 +27,6 @@ import static org.junit.Assert.fail; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.DataMigrationProviderImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataMigrationReport; import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release; @@ -42,16 +41,20 @@ public class TestMigrationProvider { .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200"))}; @Test - public void testCreateImport() { + public void testCreateImport() throws Exception { DataMigrationProviderImpl provider = new DataMigrationProviderImpl(hosts, null, null, true, 5000); try { + + //create el alto db infrastructure - provider.initDatabase(Release.FRANKFURT_R1, 5, 1, "", true, 10000); + if (!provider.initDatabase(null, 5, 1, "", true, 10000)) { + fail("unable to init database"); + } //import data into database - DataMigrationReport report = provider.importData(FRANKFURT_BACKUP_FILE, false, Release.FRANKFURT_R1); + DataMigrationReport report = provider.importData(FRANKFURT_BACKUP_FILE, false, Release.FRANKFURT_R2); assertTrue(report.completed()); - assertEquals(Release.FRANKFURT_R1, provider.autoDetectRelease()); + assertEquals(Release.FRANKFURT_R2, provider.autoDetectRelease()); } catch (Exception e) { fail(e.getMessage()); } diff --git a/sdnr/wt/data-provider/setup/tmp.log b/sdnr/wt/data-provider/setup/tmp.log deleted file mode 100644 index d2c5a8726..000000000 --- a/sdnr/wt/data-provider/setup/tmp.log +++ /dev/null @@ -1 +0,0 @@ -{"configs":{},"components":{},"release":"frankfurt-R1","created":"2020-02-25T05:29:35.3Z"} -- cgit 1.2.3-korg