From 91d66108379d7cd397aedc30da4801d20643ee68 Mon Sep 17 00:00:00 2001 From: mpriyank Date: Fri, 26 Aug 2022 13:26:01 +0100 Subject: Performance Improvement:save cmhandles capability - add saveCmHandleBatch in InventoryPersistence - add saveListElementsBatch in CpsDataService - have addListElementsBatch in CpsDataPersistenceService - Test scenarios for the same Issue-ID: CPS-1229 Issue-ID: CPS-1126 Change-Id: I0a1401818da5a4e523d7d0751cac6a526d1611b2 Signed-off-by: mpriyank --- .../cps/ncmp/api/inventory/InventoryPersistence.java | 15 +++++++++++++++ .../ncmp/api/inventory/InventoryPersistenceSpec.groovy | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'cps-ncmp-service') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java index c059ece0d3..7a7ef66668 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java @@ -27,8 +27,10 @@ import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED; import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS; import java.time.OffsetDateTime; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -156,6 +158,19 @@ public class InventoryPersistence { cmHandleJsonData, NO_TIMESTAMP); } + /** + * Method to save batch of cm handles. + * + * @param yangModelCmHandles cm handle represented as Yang Models + */ + public void saveCmHandleBatch(final Collection yangModelCmHandles) { + final List cmHandlesJsonData = new ArrayList<>(); + yangModelCmHandles.forEach(yangModelCmHandle -> cmHandlesJsonData.add( + String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle)))); + cpsDataService.saveListElementsBatch(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + NCMP_DMI_REGISTRY_PARENT, cmHandlesJsonData, NO_TIMESTAMP); + } + /** * Method to delete a list or a list element. * diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy index 7ffec1ab09..76f10de831 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy @@ -202,6 +202,22 @@ class InventoryPersistenceSpec extends Specification { } } + def 'Save Multiple Cmhandles'() { + given: 'cm handles represented as Yang Model' + def yangModelCmHandle1 = new YangModelCmHandle(id: 'cmhandle1') + def yangModelCmHandle2 = new YangModelCmHandle(id: 'cmhandle2') + when: 'the cm handles are saved' + objectUnderTest.saveCmHandleBatch([yangModelCmHandle1, yangModelCmHandle2]) + then: 'CPS Data Service persists both cm handles as a batch' + 1 * mockCpsDataService.saveListElementsBatch('NCMP-Admin','ncmp-dmi-registry','/dmi-registry',_,null) >> { + args -> { + def jsonDataList = (args[3] as List) + (jsonDataList[0] as String).contains('cmhandle1') + (jsonDataList[0] as String).contains('cmhandle2') + } + } + } + def 'Delete list or list elements'() { when: 'the method to delete list or list elements is called' objectUnderTest.deleteListOrListElement('sample xPath') -- cgit 1.2.3-korg