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 --- .../src/main/java/org/onap/cps/api/CpsDataService.java | 13 +++++++++++++ .../java/org/onap/cps/api/impl/CpsDataServiceImpl.java | 18 ++++++++++++++++++ .../org/onap/cps/spi/CpsDataPersistenceService.java | 11 +++++++++++ 3 files changed, 42 insertions(+) (limited to 'cps-service/src/main/java') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java index decf67d24e..b2e8c5ba42 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java @@ -68,6 +68,19 @@ public interface CpsDataService { void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, OffsetDateTime observedTimestamp); + /** + * Persists child data fragment representing one or more list elements under existing data node for the + * given anchor and dataspace. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param parentNodeXpath parent node xpath + * @param jsonDataList collection of json data representing list element(s) + * @param observedTimestamp observedTimestamp + */ + void saveListElementsBatch(String dataspaceName, String anchorName, String parentNodeXpath, + Collection jsonDataList, OffsetDateTime observedTimestamp); + /** * Retrieves datanode by XPath for given dataspace and anchor. * diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java index 092fd31fcf..6bf493556e 100755 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java @@ -91,6 +91,17 @@ public class CpsDataServiceImpl implements CpsDataService { processDataUpdatedEventAsync(dataspaceName, anchorName, parentNodeXpath, UPDATE, observedTimestamp); } + @Override + public void saveListElementsBatch(final String dataspaceName, final String anchorName, final String parentNodeXpath, + final Collection jsonDataList, final OffsetDateTime observedTimestamp) { + CpsValidator.validateNameCharacters(dataspaceName, anchorName); + final Collection> listElementDataNodeCollections = + buildDataNodes(dataspaceName, anchorName, parentNodeXpath, jsonDataList); + cpsDataPersistenceService.addListElementsBatch(dataspaceName, anchorName, parentNodeXpath, + listElementDataNodeCollections); + processDataUpdatedEventAsync(dataspaceName, anchorName, parentNodeXpath, UPDATE, observedTimestamp); + } + @Override public DataNode getDataNode(final String dataspaceName, final String anchorName, final String xpath, final FetchDescendantsOption fetchDescendantsOption) { @@ -252,6 +263,13 @@ public class CpsDataServiceImpl implements CpsDataService { } + private Collection> buildDataNodes(final String dataspaceName, final String anchorName, + final String parentNodeXpath, final Collection jsonDataList) { + return jsonDataList.stream() + .map(jsonData -> buildDataNodes(dataspaceName, anchorName, parentNodeXpath, jsonData)) + .collect(Collectors.toList()); + } + private void processDataUpdatedEventAsync(final String dataspaceName, final String anchorName, final String xpath, final Operation operation, final OffsetDateTime observedTimestamp) { try { diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java index 686f0f3fee..8b45ae78d9 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java @@ -65,6 +65,17 @@ public interface CpsDataPersistenceService { void addListElements(String dataspaceName, String anchorName, String parentNodeXpath, Collection listElementsCollection); + /** + * Adds list child elements to a Fragment. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param parentNodeXpath parent node xpath + * @param listElementsCollections collections of data nodes representing list elements + */ + void addListElementsBatch(String dataspaceName, String anchorName, String parentNodeXpath, + Collection> listElementsCollections); + /** * Retrieves datanode by XPath for given dataspace and anchor. * -- cgit 1.2.3-korg