diff options
author | Sourabh Sourabh <sourabh.sourabh@est.tech> | 2022-08-25 14:35:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-08-25 14:35:18 +0000 |
commit | e2a699f90d9b755230ea960df21abef55bc305ce (patch) | |
tree | e1d02d7c6ed0ccd240d4df324375bb111c3dd596 /cps-service/src/main | |
parent | 10317d3502c18c8013ae11d3c18e29b40db151d1 (diff) | |
parent | ed6c05157f60328b0215bde544f7a4e9894fd15f (diff) |
Merge "Performance Improvement: Batch Update DataNodes"
Diffstat (limited to 'cps-service/src/main')
3 files changed, 52 insertions, 8 deletions
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 cde25a9f98..decf67d24e 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 @@ -24,6 +24,7 @@ package org.onap.cps.api; import java.time.OffsetDateTime; import java.util.Collection; +import java.util.Map; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; @@ -93,7 +94,7 @@ public interface CpsDataService { OffsetDateTime observedTimestamp); /** - * Replaces existing data node content including descendants. + * Replaces an existing data node's content including descendants. * * @param dataspaceName dataspace name * @param anchorName anchor name @@ -101,8 +102,19 @@ public interface CpsDataService { * @param jsonData json data * @param observedTimestamp observedTimestamp */ - void replaceNodeTree(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, - OffsetDateTime observedTimestamp); + void updateDataNodeAndDescendants(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, + OffsetDateTime observedTimestamp); + + /** + * Replaces multiple existing data nodes' content including descendants in a batch operation. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param nodesJsonData map of xpath and node JSON data + * @param observedTimestamp observedTimestamp + */ + void updateDataNodesAndDescendants(String dataspaceName, String anchorName, Map<String, String> nodesJsonData, + OffsetDateTime observedTimestamp); /** * Replaces list content by removing all existing elements and inserting the given new elements as json 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 7bdc2c166a..092fd31fcf 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 @@ -28,6 +28,9 @@ import static org.onap.cps.notification.Operation.UPDATE; import java.time.OffsetDateTime; import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsAdminService; @@ -142,15 +145,28 @@ public class CpsDataServiceImpl implements CpsDataService { } @Override - public void replaceNodeTree(final String dataspaceName, final String anchorName, final String parentNodeXpath, - final String jsonData, final OffsetDateTime observedTimestamp) { + public void updateDataNodeAndDescendants(final String dataspaceName, final String anchorName, + final String parentNodeXpath, final String jsonData, + final OffsetDateTime observedTimestamp) { CpsValidator.validateNameCharacters(dataspaceName, anchorName); final DataNode dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData); - cpsDataPersistenceService.replaceDataNodeTree(dataspaceName, anchorName, dataNode); + cpsDataPersistenceService.updateDataNodeAndDescendants(dataspaceName, anchorName, dataNode); processDataUpdatedEventAsync(dataspaceName, anchorName, parentNodeXpath, UPDATE, observedTimestamp); } @Override + public void updateDataNodesAndDescendants(final String dataspaceName, final String anchorName, + final Map<String, String> nodesJsonData, + final OffsetDateTime observedTimestamp) { + CpsValidator.validateNameCharacters(dataspaceName, anchorName); + final List<DataNode> dataNodes = buildDataNodes(dataspaceName, anchorName, nodesJsonData); + cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, dataNodes); + nodesJsonData.keySet().forEach(nodeXpath -> + processDataUpdatedEventAsync(dataspaceName, anchorName, nodeXpath, + UPDATE, observedTimestamp)); + } + + @Override public void replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { CpsValidator.validateNameCharacters(dataspaceName, anchorName); @@ -209,6 +225,13 @@ public class CpsDataServiceImpl implements CpsDataService { .build(); } + private List<DataNode> buildDataNodes(final String dataspaceName, final String anchorName, + final Map<String, String> nodesJsonData) { + return nodesJsonData.entrySet().stream().map(nodeJsonData -> + buildDataNode(dataspaceName, anchorName, nodeJsonData.getKey(), + nodeJsonData.getValue())).collect(Collectors.toList()); + } + private Collection<DataNode> buildDataNodes(final String dataspaceName, final String anchorName, final String parentNodeXpath, 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 b27a2976d0..686f0f3fee 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 @@ -90,13 +90,22 @@ public interface CpsDataPersistenceService { void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves); /** - * Replaces existing data node content including descendants. + * Replaces an existing data node's content including descendants. * * @param dataspaceName dataspace name * @param anchorName anchor name * @param dataNode data node */ - void replaceDataNodeTree(String dataspaceName, String anchorName, DataNode dataNode); + void updateDataNodeAndDescendants(String dataspaceName, String anchorName, DataNode dataNode); + + /** + * Replaces multiple existing data nodes' content including descendants in a batch operation. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param dataNodes data nodes + */ + void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final List<DataNode> dataNodes); /** * Replaces list content by removing all existing elements and inserting the given new elements |