diff options
author | 2025-03-19 12:09:12 +0100 | |
---|---|---|
committer | 2025-03-19 18:12:47 +0100 | |
commit | 7b63610d1d2e020b51a5baaeaeb9bbc1ac30b355 (patch) | |
tree | 0d24ea372f5b57125dc3c100bbc3042bf7cc4677 /cps-ncmp-service/src | |
parent | 7a67aa410fbdaaed0cf5b5110512c442bfb400ff (diff) |
Enhance batch operation performance with AlternateIdMatcher
- used more efficient methos in AlternateIdMatcher to get cmHandleIds
- removed getYangModelCmHandlesFromCmHandleReferences from InventoryPersistence class (unused + bad performance)
Issue-ID: CPS-2607
Change-Id: Ia1970435aec57cd12713958a910a9ced4511440b
Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
Diffstat (limited to 'cps-ncmp-service/src')
6 files changed, 12 insertions, 41 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java index 7cb1c44526..2a0d2f563c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java @@ -50,6 +50,7 @@ import org.onap.cps.ncmp.impl.dmi.DmiRestClient; import org.onap.cps.ncmp.impl.inventory.InventoryPersistence; import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; import org.onap.cps.ncmp.impl.models.DmiRequestBody; +import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher; import org.onap.cps.ncmp.impl.utils.http.RestServiceUrlTemplateBuilder; import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters; import org.onap.cps.utils.JsonObjectMapper; @@ -69,6 +70,7 @@ import reactor.core.publisher.Mono; public class DmiDataOperations { private final InventoryPersistence inventoryPersistence; + private final AlternateIdMatcher alternateIdMatcher; private final JsonObjectMapper jsonObjectMapper; private final DmiProperties dmiProperties; private final DmiRestClient dmiRestClient; @@ -140,10 +142,10 @@ public class DmiDataOperations { final String requestId, final String authorization) { - final Set<String> cmHandlesReferences = getDistinctCmHandleReferences(dataOperationRequest); + final Set<String> cmHandleIds = getDistinctCmHandleIds(dataOperationRequest); final Collection<YangModelCmHandle> yangModelCmHandles - = inventoryPersistence.getYangModelCmHandlesFromCmHandleReferences(cmHandlesReferences); + = inventoryPersistence.getYangModelCmHandles(cmHandleIds); final Map<String, List<DmiDataOperation>> operationsOutPerDmiServiceName = DmiDataOperationsHelper.processPerDefinitionInDataOperationsRequest(topicParamInQuery, @@ -248,10 +250,11 @@ public class DmiDataOperations { } } - private static Set<String> getDistinctCmHandleReferences(final DataOperationRequest dataOperationRequest) { + private Set<String> getDistinctCmHandleIds(final DataOperationRequest dataOperationRequest) { return dataOperationRequest.getDataOperationDefinitions().stream() - .flatMap(dataOperationDefinition -> - dataOperationDefinition.getCmHandleReferences().stream()).collect(Collectors.toSet()); + .flatMap(it -> it.getCmHandleReferences().stream()) + .map(alternateIdMatcher::getCmHandleId) + .collect(Collectors.toSet()); } private void asyncSendMultipleRequest(final String requestId, final String topicParamInQuery, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java index fb7ad6b116..6bb1bfc86c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java @@ -73,14 +73,6 @@ public interface InventoryPersistence extends NcmpPersistence { Collection<YangModelCmHandle> getYangModelCmHandles(Collection<String> cmHandleIds); /** - * This method retrieves DMI service name, DMI properties and the state for a given list of cm handle references. - * - * @param cmHandleReferences a list of the ids of the cm handles - * @return collection of yang model cm handles - */ - Collection<YangModelCmHandle> getYangModelCmHandlesFromCmHandleReferences(Collection<String> cmHandleReferences); - - /** * Method to return module definitions by cmHandleId. * * @param cmHandleId cm handle ID diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java index cf98b31614..02e711287e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java @@ -138,19 +138,6 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv } @Override - public Collection<YangModelCmHandle> getYangModelCmHandlesFromCmHandleReferences( - final Collection<String> cmHandleReferences) { - - final String cpsPathForCmHandlesByReferences = getCpsPathForCmHandlesByReferences(cmHandleReferences); - - final Collection<DataNode> cmHandlesAsDataNodes = - cmHandleQueryService.queryNcmpRegistryByCpsPath( - cpsPathForCmHandlesByReferences, INCLUDE_ALL_DESCENDANTS, cmHandleReferences.size()); - - return YangDataConverter.toYangModelCmHandles(cmHandlesAsDataNodes); - } - - @Override public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) { return cpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId); } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy index 3dd2eabe21..37a9097f33 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy @@ -109,7 +109,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { def 'Execute (async) data operation from DMI service.'() { given: 'collection of yang model cm Handles and data operation request' - mockYangModelCmHandleCollectionRetrieval([yangModelCmHandleProperty]) + mockYangModelCmHandleRetrievalByCmHandleId([yangModelCmHandleProperty]) def dataOperationBatchRequestJsonData = TestUtils.getResourceFileContent('dataOperationRequest.json') def dataOperationRequest = spiedJsonObjectMapper.convertJsonString(dataOperationBatchRequestJsonData, DataOperationRequest.class) dataOperationRequest.dataOperationDefinitions[0].cmHandleReferences = [cmHandleId] @@ -126,7 +126,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { def 'Execute (async) data operation from DMI service with Exception.'() { given: 'collection of yang model cm Handles and data operation request' - mockYangModelCmHandleCollectionRetrieval([yangModelCmHandleProperty]) + mockYangModelCmHandleRetrievalByCmHandleId([yangModelCmHandleProperty]) def dataOperationBatchRequestJsonData = TestUtils.getResourceFileContent('dataOperationRequest.json') def dataOperationRequest = spiedJsonObjectMapper.convertJsonString(dataOperationBatchRequestJsonData, DataOperationRequest.class) dataOperationRequest.dataOperationDefinitions[0].cmHandleReferences = [cmHandleId] diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy index 1edee4e355..c5c1397048 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy @@ -59,9 +59,9 @@ abstract class DmiOperationsBaseSpec extends Specification { mockInventoryPersistence.getYangModelCmHandle(cmHandleId) >> yangModelCmHandle } - def mockYangModelCmHandleCollectionRetrieval(dmiProperties) { + def mockYangModelCmHandleRetrievalByCmHandleId(dmiProperties) { populateYangModelCmHandle(dmiProperties, '') - mockInventoryPersistence.getYangModelCmHandlesFromCmHandleReferences(_) >> [yangModelCmHandle] + mockInventoryPersistence.getYangModelCmHandles(_) >> [yangModelCmHandle] } def populateYangModelCmHandle(dmiProperties, moduleSetTag) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy index 5619c5ac57..2b0997b523 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy @@ -161,17 +161,6 @@ class InventoryPersistenceImplSpec extends Specification { assert results.size() == 0 } - def "Retrieve multiple YangModelCmHandles using cm handle references"() { - given: 'the cps data service returns 2 data nodes from the DMI registry' - def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId, 'alternate-id':alternateId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2,'alternate-id':alternateId2])] - mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, INCLUDE_ALL_DESCENDANTS, _) >> dataNodes - when: 'retrieving the yang modelled cm handle' - def results = objectUnderTest.getYangModelCmHandlesFromCmHandleReferences([cmHandleId, cmHandleId2]) - then: 'verify both have returned and cmhandleIds are correct' - assert results.size() == 2 - assert results.id.containsAll([cmHandleId, cmHandleId2]) - } - def 'Get a Cm Handle Composite State'() { given: 'a valid cm handle id' def cmHandleId = 'Some-Cm-Handle' |