aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org/onap
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2022-09-06 18:29:34 +0100
committermpriyank <priyank.maheshwari@est.tech>2022-09-12 18:09:43 +0100
commit7b6ab50231f5ab39d1476531031437f81328115e (patch)
tree3939da0046a69ab31d391e14bd2b5af699202baf /cps-ncmp-service/src/main/java/org/onap
parent440dc8aab179f6c8451683f53b019ccd8bd60bdf (diff)
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>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java12
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java29
2 files changed, 35 insertions, 6 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index 209ade9559..0eb275cf0e 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -59,7 +59,7 @@ import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.exceptions.AlreadyDefinedException;
+import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
@@ -365,12 +365,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
try {
lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
- } catch (final AlreadyDefinedException alreadyDefinedException) {
- return List.of(CmHandleRegistrationResponse.createFailureResponse(
- String.join(",", cmHandleIds), RegistrationError.CM_HANDLE_ALREADY_EXIST));
+ } catch (final AlreadyDefinedExceptionBatch alreadyDefinedExceptionBatch) {
+ return CmHandleRegistrationResponse.createFailureResponses(
+ alreadyDefinedExceptionBatch.getAlreadyDefinedCmHandleIds(),
+ RegistrationError.CM_HANDLE_ALREADY_EXIST);
} catch (final Exception exception) {
- return List.of(CmHandleRegistrationResponse.createFailureResponse(String.join(",", cmHandleIds),
- exception));
+ return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
}
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
index b7faf09a9e..9f80218420 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
@@ -21,6 +21,7 @@
package org.onap.cps.ncmp.api.models;
+import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Builder;
@@ -67,6 +68,34 @@ public class CmHandleRegistrationResponse {
.build();
}
+ /**
+ * Creates a failure response based on registration error.
+ *
+ * @param cmHandleIds list of failed cmHandleIds
+ * @param registrationError enum describing the type of registration error
+ * @return CmHandleRegistrationResponse
+ */
+ public static List<CmHandleRegistrationResponse> createFailureResponses(final Collection<String> cmHandleIds,
+ final RegistrationError registrationError) {
+ return cmHandleIds.stream()
+ .map(cmHandleId -> CmHandleRegistrationResponse.createFailureResponse(cmHandleId, registrationError))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Creates a failure response based on other exception.
+ *
+ * @param cmHandleIds list of failed cmHandleIds
+ * @param exception exception caught during the registration
+ * @return CmHandleRegistrationResponse
+ */
+ public static List<CmHandleRegistrationResponse> createFailureResponses(final Collection<String> cmHandleIds,
+ final Exception exception) {
+ return cmHandleIds.stream()
+ .map(cmHandleId -> CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception))
+ .collect(Collectors.toList());
+ }
+
public static CmHandleRegistrationResponse createSuccessResponse(final String cmHandle) {
return CmHandleRegistrationResponse.builder().cmHandle(cmHandle)
.status(Status.SUCCESS).build();