summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2022-09-13 12:51:21 +0100
committerToineSiebelink <toine.siebelink@est.tech>2022-09-13 15:26:30 +0100
commitae5a47388dae38c51b437e448ae6a23fa9a77591 (patch)
tree2a5fce300e78717de7f9a7309ccdeea3cec51d55 /cps-ncmp-service/src/main
parent5b977b6607d696d347de08ecba638ffbf4d57d16 (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-ncmp-service/src/main')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java40
2 files changed, 29 insertions, 13 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 0eb275cf0e..3f440d65bd 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
@@ -367,7 +367,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
} catch (final AlreadyDefinedExceptionBatch alreadyDefinedExceptionBatch) {
return CmHandleRegistrationResponse.createFailureResponses(
- alreadyDefinedExceptionBatch.getAlreadyDefinedCmHandleIds(),
+ alreadyDefinedExceptionBatch.getAlreadyDefinedXpaths(),
RegistrationError.CM_HANDLE_ALREADY_EXIST);
} catch (final Exception 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 9f80218420..d5b27b61f6 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,15 +21,20 @@
package org.onap.cps.ncmp.api.models;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
@Data
@Builder
+@Slf4j
public class CmHandleRegistrationResponse {
private final String cmHandle;
@@ -37,16 +42,19 @@ public class CmHandleRegistrationResponse {
private RegistrationError registrationError;
private String errorText;
+ private static final Pattern cmHandleIdInXpathPattern = Pattern.compile("\\[@id='(.*?)']");
+
/**
* Creates a failure response based on exception.
*
- * @param cmHandle cmHandle
+ * @param cmHandleId cmHandleId
* @param exception exception
* @return CmHandleRegistrationResponse
*/
- public static CmHandleRegistrationResponse createFailureResponse(final String cmHandle, final Exception exception) {
+ public static CmHandleRegistrationResponse createFailureResponse(final String cmHandleId,
+ final Exception exception) {
return CmHandleRegistrationResponse.builder()
- .cmHandle(cmHandle)
+ .cmHandle(cmHandleId)
.status(Status.FAILURE)
.registrationError(RegistrationError.UNKNOWN_ERROR)
.errorText(exception.getMessage()).build();
@@ -55,13 +63,13 @@ public class CmHandleRegistrationResponse {
/**
* Creates a failure response based on registration error.
*
- * @param cmHandle cmHandle
+ * @param cmHandleId cmHandleId
* @param registrationError registrationError
* @return CmHandleRegistrationResponse
*/
- public static CmHandleRegistrationResponse createFailureResponse(final String cmHandle,
+ public static CmHandleRegistrationResponse createFailureResponse(final String cmHandleId,
final RegistrationError registrationError) {
- return CmHandleRegistrationResponse.builder().cmHandle(cmHandle)
+ return CmHandleRegistrationResponse.builder().cmHandle(cmHandleId)
.status(Status.FAILURE)
.registrationError(registrationError)
.errorText(registrationError.errorText)
@@ -71,15 +79,23 @@ public class CmHandleRegistrationResponse {
/**
* Creates a failure response based on registration error.
*
- * @param cmHandleIds list of failed cmHandleIds
+ * @param failedXpaths list of failed Xpaths
* @param registrationError enum describing the type of registration error
* @return CmHandleRegistrationResponse
*/
- public static List<CmHandleRegistrationResponse> createFailureResponses(final Collection<String> cmHandleIds,
+ public static List<CmHandleRegistrationResponse> createFailureResponses(final Collection<String> failedXpaths,
final RegistrationError registrationError) {
- return cmHandleIds.stream()
- .map(cmHandleId -> CmHandleRegistrationResponse.createFailureResponse(cmHandleId, registrationError))
- .collect(Collectors.toList());
+ final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses = new ArrayList<>(failedXpaths.size());
+ for (final String xpath : failedXpaths) {
+ final Matcher matcher = cmHandleIdInXpathPattern.matcher(xpath);
+ if (matcher.find()) {
+ cmHandleRegistrationResponses.add(
+ CmHandleRegistrationResponse.createFailureResponse(matcher.group(1), registrationError));
+ } else {
+ log.warn("Unexpected xpath {}", xpath);
+ }
+ }
+ return cmHandleRegistrationResponses;
}
/**
@@ -121,4 +137,4 @@ public class CmHandleRegistrationResponse {
public final String errorText;
}
-} \ No newline at end of file
+}