From 7b6ab50231f5ab39d1476531031437f81328115e Mon Sep 17 00:00:00 2001
From: mpriyank <priyank.maheshwari@est.tech>
Date: Tue, 6 Sep 2022 18:29:34 +0100
Subject: Handle partial failure

- Removing the transaction boundaries as it was getting rollbacked on
  partial failures
- Handled adding the elements in batch and if it fails try them
  individually
- Refactored code a bit and when there is partial failure we try one
  more time in sequence and even if there are failures we collect the
  failures

Issue-ID: CPS-1232
Issue-ID: CPS-1126
Change-Id: I7824c9f37f80cbaeedd5dc06d598ca0e3a69c59b
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
---
 .../org/onap/cps/api/impl/CpsDataServiceImpl.java  |  2 +-
 .../onap/cps/spi/CpsDataPersistenceService.java    |  8 ++---
 .../exceptions/AlreadyDefinedExceptionBatch.java   | 34 ++++++++++++++++++++++
 3 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/AlreadyDefinedExceptionBatch.java

(limited to 'cps-service/src/main/java/org/onap')

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 6bf493556e..b6aa04be76 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
@@ -97,7 +97,7 @@ public class CpsDataServiceImpl implements CpsDataService {
         CpsValidator.validateNameCharacters(dataspaceName, anchorName);
         final Collection<Collection<DataNode>> listElementDataNodeCollections =
                 buildDataNodes(dataspaceName, anchorName, parentNodeXpath, jsonDataList);
-        cpsDataPersistenceService.addListElementsBatch(dataspaceName, anchorName, parentNodeXpath,
+        cpsDataPersistenceService.addMultipleLists(dataspaceName, anchorName, parentNodeXpath,
                 listElementDataNodeCollections);
         processDataUpdatedEventAsync(dataspaceName, anchorName, parentNodeXpath, UPDATE, observedTimestamp);
     }
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 8b45ae78d9..cd0cefcbf3 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
@@ -66,15 +66,15 @@ public interface CpsDataPersistenceService {
         Collection<DataNode> listElementsCollection);
 
     /**
-     * Adds list child elements to a Fragment.
+     * Add multiple lists of data nodes to a parent node at the same time.
      *
      * @param dataspaceName           dataspace name
      * @param anchorName              anchor name
      * @param parentNodeXpath         parent node xpath
-     * @param listElementsCollections collections of data nodes representing list elements
+     * @param newLists collections of lists of data nodes representing list elements
      */
-    void addListElementsBatch(String dataspaceName, String anchorName, String parentNodeXpath,
-            Collection<Collection<DataNode>> listElementsCollections);
+    void addMultipleLists(String dataspaceName, String anchorName, String parentNodeXpath,
+            Collection<Collection<DataNode>> newLists);
 
     /**
      * Retrieves datanode by XPath for given dataspace and anchor.
diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/AlreadyDefinedExceptionBatch.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AlreadyDefinedExceptionBatch.java
new file mode 100644
index 0000000000..a5ce6fde21
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AlreadyDefinedExceptionBatch.java
@@ -0,0 +1,34 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.exceptions;
+
+import java.util.Collection;
+import lombok.Getter;
+
+public class AlreadyDefinedExceptionBatch extends RuntimeException {
+
+    @Getter
+    private final Collection<String> alreadyDefinedCmHandleIds;
+
+    public AlreadyDefinedExceptionBatch(final Collection<String> alreadyDefinedCmHandleIds) {
+        this.alreadyDefinedCmHandleIds = alreadyDefinedCmHandleIds;
+    }
+}
-- 
cgit 1.2.3-korg