summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
author--global <as00745003@techmahindra.com>2023-04-05 17:08:08 +0530
committer--global <as00745003@techmahindra.com>2023-05-09 16:04:03 +0530
commitc7e5a80d6f11b76d35341bf7d934c6a06b783e01 (patch)
tree8e8459ad7c9d7abeed049a06c493247035bd7f1b /cps-ri/src/main/java
parent492b6660fb153dd3dbf52c693a0b86bed3bee4f5 (diff)
Support for Patch across multiple data nodes
- Added new method updateMultipleDataLeaves to perform Update on multiple data nodes - Deprecated singular method of update data node(updateDataLeaves) - Refactored code where singular version was used - Updated release notes Issue-ID: CPS-1006 Signed-off-by: <as00745003@techmahindra.com> Change-Id: If67280e2dd3ad566de9a8217489f168415e624bc
Diffstat (limited to 'cps-ri/src/main/java')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java9
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java35
2 files changed, 31 insertions, 13 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java
index 49e2dd2530..b7ce98e1ac 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntityArranger.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Nordix Foundation
+ * Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,9 +41,11 @@ public class FragmentEntityArranger {
public static Collection<FragmentEntity> toFragmentEntityTrees(final AnchorEntity anchorEntity,
final Collection<FragmentExtract> fragmentExtracts) {
final Map<Long, FragmentEntity> fragmentEntityPerId = new HashMap<>();
- for (final FragmentExtract fragmentExtract : fragmentExtracts) {
- final FragmentEntity fragmentEntity = toFragmentEntity(anchorEntity, fragmentExtract);
- fragmentEntityPerId.put(fragmentEntity.getId(), fragmentEntity);
+ if (fragmentExtracts != null) {
+ for (final FragmentExtract fragmentExtract : fragmentExtracts) {
+ final FragmentEntity fragmentEntity = toFragmentEntity(anchorEntity, fragmentExtract);
+ fragmentEntityPerId.put(fragmentEntity.getId(), fragmentEntity);
+ }
}
return reuniteChildrenWithTheirParents(fragmentEntityPerId);
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index c26cd2fea8..3d2b87d7de 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -450,14 +450,25 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
}
@Override
- public void updateDataLeaves(final String dataspaceName, final String anchorName, final String xpath,
- final Map<String, Serializable> updateLeaves) {
+ public void batchUpdateDataLeaves(final String dataspaceName, final String anchorName,
+ final Map<String, Map<String, Serializable>> updatedLeavesPerXPath) {
final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName);
- final FragmentEntity fragmentEntity = getFragmentEntity(anchorEntity, xpath);
- final String currentLeavesAsString = fragmentEntity.getAttributes();
- final String mergedLeaves = mergeLeaves(updateLeaves, currentLeavesAsString);
- fragmentEntity.setAttributes(mergedLeaves);
- fragmentRepository.save(fragmentEntity);
+
+ final Collection<String> xpathsOfUpdatedLeaves = updatedLeavesPerXPath.keySet();
+ final Collection<FragmentEntity> fragmentEntities = getFragmentEntities(anchorEntity, xpathsOfUpdatedLeaves,
+ FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
+
+ for (final FragmentEntity fragmentEntity : fragmentEntities) {
+ final Map<String, Serializable> updatedLeaves = updatedLeavesPerXPath.get(fragmentEntity.getXpath());
+ final String mergedLeaves = mergeLeaves(updatedLeaves, fragmentEntity.getAttributes());
+ fragmentEntity.setAttributes(mergedLeaves);
+ }
+
+ try {
+ fragmentRepository.saveAll(fragmentEntities);
+ } catch (final StaleStateException staleStateException) {
+ retryUpdateDataNodesIndividually(anchorEntity, fragmentEntities);
+ }
}
@Override
@@ -687,9 +698,13 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
}
private String mergeLeaves(final Map<String, Serializable> updateLeaves, final String currentLeavesAsString) {
- final Map<String, Serializable> currentLeavesAsMap = currentLeavesAsString.isEmpty()
- ? new HashMap<>() : jsonObjectMapper.convertJsonString(currentLeavesAsString, Map.class);
- currentLeavesAsMap.putAll(updateLeaves);
+ Map<String, Serializable> currentLeavesAsMap = new HashMap<>();
+ if (currentLeavesAsString != null) {
+ currentLeavesAsMap = currentLeavesAsString.isEmpty()
+ ? new HashMap<>() : jsonObjectMapper.convertJsonString(currentLeavesAsString, Map.class);
+ currentLeavesAsMap.putAll(updateLeaves);
+ }
+
if (currentLeavesAsMap.isEmpty()) {
return "";
}