From ae5a47388dae38c51b437e448ae6a23fa9a77591 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Tue, 13 Sep 2022 12:51:21 +0100 Subject: 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 Change-Id: Ice2032c8b15fea97ae0aaa4d1ed642b3499228fa --- .../spi/impl/CpsDataPersistenceServiceImpl.java | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'cps-ri/src/main') 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 e02fb7355..d62421c5a 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> newLists) { - final Collection failedCmHandleIds = new HashSet<>(); + final Collection 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 newChildren) { - newChildren.forEach(newChild -> addNewChildDataNode(dataspaceName, anchorName, parentNodeXpath, newChild)); + final Collection 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 -- cgit 1.2.3-korg