2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
4 * Modifications Copyright (C) 2024 TechMahindra Ltd.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the 'License');
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an 'AS IS' BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.integration.performance.base
24 import org.onap.cps.integration.ResourceMeter
25 import org.onap.cps.api.parameters.FetchDescendantsOption
26 import org.onap.cps.utils.ContentType
28 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DATASPACE_NAME
29 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
30 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT
32 class NcmpPerfTestBase extends PerfTestBase {
34 def static NCMP_PERFORMANCE_TEST_DATASPACE = 'ncmpPerformance'
35 def static REGISTRY_ANCHOR = NCMP_DMI_REGISTRY_ANCHOR
36 def static REGISTRY_PARENT = NCMP_DMI_REGISTRY_PARENT
37 def static REGISTRY_SCHEMA_SET = 'registrySchemaSet'
38 def static TOTAL_CM_HANDLES = 20_000
39 def static CM_DATA_SUBSCRIPTIONS_ANCHOR = 'cm-data-subscriptions'
40 def static CM_DATA_SUBSCRIPTIONS_SCHEMA_SET = 'cmDataSubscriptionsSchemaSet'
42 def datastore1cmHandlePlaceHolder = '{"datastores":{"datastore":[{"name":"ds-1","cm-handles":{"cm-handle":[]}}]}}'
43 def xPathForDataStore1CmHandles = '/datastores/datastore[@name="ds-1"]/cm-handles'
44 def numberOfCmDataSubscribers = 200
45 def numberOfFiltersPerCmHandle = 10
46 def numberOfCmHandlesPerCmDataSubscription = 200
48 ResourceMeter resourceMeter = new ResourceMeter()
50 def subscriberIdPrefix = 'some really long subscriber id to see if this makes any difference to the performance'
51 def xpathPrefix = 'some really long xpath/with/loads/of/children/grandchildren/and/whatever/else/I/can/think/of to see if this makes any difference to the performance'
52 def cmHandlePrefix = 'some really long cm handle id to see if this makes any difference to the performance'
55 println('## N C M P P E R F O R M A N C E T E S T R E S U L T S ##')
59 return dataspaceExists(NCMP_PERFORMANCE_TEST_DATASPACE)
62 def setupPerformanceInfraStructure() {
63 cpsDataspaceService.createDataspace(NCMP_PERFORMANCE_TEST_DATASPACE)
64 createRegistrySchemaSet()
65 createCmDataSubscriptionsSchemaSet()
68 def createInitialData() {
70 addRegistryDataWithAlternateIdAsPath()
71 addCmSubscriptionData()
74 def createRegistrySchemaSet() {
75 def modelAsString = readResourceDataFile('inventory/dmi-registry@2024-02-23.yang')
76 cpsModuleService.createSchemaSet(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, [registry: modelAsString])
79 def addRegistryData() {
80 cpsAnchorService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, REGISTRY_ANCHOR)
81 cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '{"dmi-registry": []}', now)
82 def cmHandleJsonTemplate = readResourceDataFile('inventory/cmHandleTemplate.json')
84 for (def i = 0; i < TOTAL_CM_HANDLES; i += batchSize) {
85 def data = '{ "cm-handles": [' + (1..batchSize).collect { cmHandleJsonTemplate.replace('CM_HANDLE_ID_POSTFIX', (it + i).toString()) }.join(',') + ']}'
86 cpsDataService.saveListElements(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, REGISTRY_PARENT, data, now, ContentType.JSON)
90 def addRegistryDataWithAlternateIdAsPath() {
91 def cmHandleWithAlternateIdTemplate = readResourceDataFile('inventory/cmHandleWithAlternateIdTemplate.json')
93 for (def i = 0; i < TOTAL_CM_HANDLES; i += batchSize) {
94 def data = '{ "cm-handles": [' + (1..batchSize).collect {
95 cmHandleWithAlternateIdTemplate.replace('CM_HANDLE_ID_POSTFIX', (it + i).toString())
96 .replace('ALTERNATE_ID_POSTFIX', (it + i).toString())
98 cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, REGISTRY_PARENT, data, now, ContentType.JSON)
102 def createCmDataSubscriptionsSchemaSet() {
103 def modelAsString = readResourceDataFile('cm-data-subscriptions/cm-data-subscriptions@2023-09-21.yang')
104 cpsModuleService.createSchemaSet(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, [registry: modelAsString])
107 def addCmSubscriptionData() {
108 cpsAnchorService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, CM_DATA_SUBSCRIPTIONS_ANCHOR)
109 cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, datastore1cmHandlePlaceHolder, now)
110 def subscribers = createLeafList('subscribers',numberOfCmDataSubscribers, subscriberIdPrefix)
111 def filters = '"filters":' + createJsonArray('filter',numberOfFiltersPerCmHandle,'xpath',xpathPrefix,subscribers)
112 def cmHandles = createJsonArray('cm-handle',numberOfCmHandlesPerCmDataSubscription,'id',cmHandlePrefix, filters)
113 cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, xPathForDataStore1CmHandles, cmHandles, now)
116 def 'NCMP pre-load test data'() {
117 when: 'dummy get data nodes runs so that populating the DB does not get included in other test timings'
118 resourceMeter.start()
119 def result = cpsDataService.getDataNodes(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, '/', FetchDescendantsOption.OMIT_DESCENDANTS)
121 then: 'expected data exists'
122 assert result.xpath == [REGISTRY_PARENT]