diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2022-09-13 12:51:21 +0100 |
---|---|---|
committer | ToineSiebelink <toine.siebelink@est.tech> | 2022-09-13 15:26:30 +0100 |
commit | ae5a47388dae38c51b437e448ae6a23fa9a77591 (patch) | |
tree | 2a5fce300e78717de7f9a7309ccdeea3cec51d55 /cps-ri/src/main/java/org/onap | |
parent | 5b977b6607d696d347de08ecba638ffbf4d57d16 (diff) |
Handle partial failure (improvements)
- catching of failures on retry of individual nodes
- extract cm handle id from xpaths (can only report xpaths in cps core)
- add test for same
Issue-ID: CPS-1232
Issue-ID: CPS-1126
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Change-Id: Ice2032c8b15fea97ae0aaa4d1ed642b3499228fa
Diffstat (limited to 'cps-ri/src/main/java/org/onap')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java | 24 |
1 files changed, 17 insertions, 7 deletions
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 e02fb7355b..d62421c5af 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 @@ -103,17 +103,17 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService @Override public void addMultipleLists(final String dataspaceName, final String anchorName, final String parentNodeXpath, final Collection<Collection<DataNode>> newLists) { - final Collection<String> failedCmHandleIds = new HashSet<>(); + final Collection<String> failedXpaths = new HashSet<>(); newLists.forEach(newList -> { try { addChildrenDataNodes(dataspaceName, anchorName, parentNodeXpath, newList); - } catch (final AlreadyDefinedException e) { - newList.forEach(listElement -> failedCmHandleIds.add((String) listElement.getLeaves().get("id"))); + } catch (final AlreadyDefinedExceptionBatch e) { + failedXpaths.addAll(e.getAlreadyDefinedXpaths()); } }); - if (!failedCmHandleIds.isEmpty()) { - throw new AlreadyDefinedExceptionBatch(failedCmHandleIds); + if (!failedXpaths.isEmpty()) { + throw new AlreadyDefinedExceptionBatch(failedXpaths); } } @@ -147,7 +147,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService }); fragmentRepository.saveAll(fragmentEntities); } catch (final DataIntegrityViolationException e) { - log.warn("Exception occurred : {} , Batch with size : {} will be retried using individual save operations", + log.warn("Exception occurred : {} , While saving : {} children, retrying using individual save operations", e, fragmentEntities.size()); retrySavingEachChildIndividually(dataspaceName, anchorName, parentNodeXpath, newChildren); } @@ -155,7 +155,17 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService private void retrySavingEachChildIndividually(final String dataspaceName, final String anchorName, final String parentNodeXpath, final Collection<DataNode> newChildren) { - newChildren.forEach(newChild -> addNewChildDataNode(dataspaceName, anchorName, parentNodeXpath, newChild)); + final Collection<String> failedXpaths = new HashSet<>(); + for (final DataNode newChild : newChildren) { + try { + addNewChildDataNode(dataspaceName, anchorName, parentNodeXpath, newChild); + } catch (final AlreadyDefinedException e) { + failedXpaths.add(newChild.getXpath()); + } + } + if (!failedXpaths.isEmpty()) { + throw new AlreadyDefinedExceptionBatch(failedXpaths); + } } @Override |