aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org
diff options
context:
space:
mode:
authorLevente Csanyi <levente.csanyi@est.tech>2024-02-08 16:12:06 +0000
committerLevente Csanyi <levente.csanyi@est.tech>2024-02-08 16:12:06 +0000
commite190adf9b0e8e0bb9e5012dd40b712c97e45c9de (patch)
treeee069a78c5419a7001b6dd98399372a4066181a5 /cps-ncmp-service/src/main/java/org
parent67681820f2a7fea88cbc6cbe5b3d483dae506d55 (diff)
Revert "Introduce Hazelcast for alternateId-cmHandle relation pt. 2 - error collection"
This reverts commit 67681820f2a7fea88cbc6cbe5b3d483dae506d55. Reason for revert: does not work Change-Id: I92c063b59261d25774ee34664d834399c269f0c2 Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java3
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java31
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java17
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleIdMapper.java33
4 files changed, 20 insertions, 64 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java
index e7293b2fd9..b9c834c559 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java
@@ -36,8 +36,7 @@ public enum NcmpResponseStatus {
SUBSCRIPTION_PENDING("106", "subscription pending for all cm handles"),
UNKNOWN_ERROR("108", "Unknown error"),
CM_HANDLE_ALREADY_EXIST("109", "cm-handle already exists"),
- CM_HANDLE_INVALID_ID("110", "cm-handle has an invalid character(s) in id"),
- ALTERNATE_ID_ALREADY_ASSOCIATED("111", "cannot re-assign alternate id");
+ CM_HANDLE_INVALID_ID("110", "cm-handle has an invalid character(s) in id");
private final String code;
private final String message;
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 ad1c5cdfb9..05b83b98e4 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
@@ -24,7 +24,6 @@
package org.onap.cps.ncmp.api.impl;
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.ALTERNATE_ID_ALREADY_ASSOCIATED;
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND;
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_READY;
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST;
@@ -501,35 +500,16 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private List<CmHandleRegistrationResponse> registerNewCmHandles(final List<YangModelCmHandle> yangModelCmHandles,
final Map<String, TrustLevel>
initialTrustLevelPerCmHandleId) {
- final List<CmHandleRegistrationResponse> failureResponses = new ArrayList<>();
- final List<YangModelCmHandle> acceptedYangModelCmHandles = new ArrayList<>(yangModelCmHandles.size());
- final Set<String> acceptedCmHandleIds = new HashSet<>(yangModelCmHandles.size());
- for (final YangModelCmHandle yangModelCmHandle : yangModelCmHandles) {
- if (cmHandleIdMapper.isDuplicateId(yangModelCmHandle.getId(), yangModelCmHandle.getAlternateId())) {
- initialTrustLevelPerCmHandleId.remove(yangModelCmHandle.getId());
- failureResponses.add(CmHandleRegistrationResponse.createFailureResponse(
- yangModelCmHandle.getId(), ALTERNATE_ID_ALREADY_ASSOCIATED));
- } else {
- acceptedCmHandleIds.add(yangModelCmHandle.getId());
- acceptedYangModelCmHandles.add(yangModelCmHandle);
- }
- }
+ final Set<String> cmHandleIds = initialTrustLevelPerCmHandleId.keySet();
try {
- lcmEventsCmHandleStateHandler.initiateStateAdvised(acceptedYangModelCmHandles);
+ lcmEventsCmHandleStateHandler.initiateStateAdvised(yangModelCmHandles);
trustLevelManager.handleInitialRegistrationOfTrustLevels(initialTrustLevelPerCmHandleId);
- final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses = CmHandleRegistrationResponse
- .createSuccessResponses(acceptedCmHandleIds);
- cmHandleRegistrationResponses.addAll(failureResponses);
- return cmHandleRegistrationResponses;
+ return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
} catch (final AlreadyDefinedException alreadyDefinedException) {
- final List<CmHandleRegistrationResponse> alreadyDefinedResponses = CmHandleRegistrationResponse
- .createFailureResponses(
+ return CmHandleRegistrationResponse.createFailureResponses(
alreadyDefinedException.getAlreadyDefinedObjectNames(), CM_HANDLE_ALREADY_EXIST);
- failureResponses.addAll(alreadyDefinedResponses);
- return failureResponses;
} catch (final Exception exception) {
- return CmHandleRegistrationResponse
- .createFailureResponses(initialTrustLevelPerCmHandleId.keySet(), exception);
+ return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
}
}
@@ -576,4 +556,5 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
}
}
+
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java
index 0520f456a5..13b3fcafb1 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java
@@ -22,7 +22,6 @@
package org.onap.cps.ncmp.api.impl;
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.ALTERNATE_ID_ALREADY_ASSOCIATED;
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND;
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID;
import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.DMI_PROPERTY;
@@ -82,17 +81,11 @@ public class NetworkCmProxyDataServicePropertyHandler {
for (final NcmpServiceCmHandle ncmpServiceCmHandle : ncmpServiceCmHandles) {
final String cmHandleId = ncmpServiceCmHandle.getCmHandleId();
try {
- if (cmHandleIdMapper.isDuplicateId(ncmpServiceCmHandle.getCmHandleId(),
- ncmpServiceCmHandle.getAlternateId())) {
- cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createFailureResponse(cmHandleId,
- ALTERNATE_ID_ALREADY_ASSOCIATED));
- } else {
- final DataNode existingCmHandleDataNode = inventoryPersistence.getCmHandleDataNode(cmHandleId)
- .iterator().next();
- updateAlternateId(existingCmHandleDataNode, ncmpServiceCmHandle);
- processUpdates(existingCmHandleDataNode, ncmpServiceCmHandle);
- cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
- }
+ final DataNode existingCmHandleDataNode = inventoryPersistence.getCmHandleDataNode(cmHandleId)
+ .iterator().next();
+ updateAlternateId(existingCmHandleDataNode, ncmpServiceCmHandle);
+ processUpdates(existingCmHandleDataNode, ncmpServiceCmHandle);
+ cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
} catch (final DataNodeNotFoundException e) {
log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandleId, e.getMessage());
cmHandleRegistrationResponses.add(
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleIdMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleIdMapper.java
index 40c620f508..a88adbd110 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleIdMapper.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleIdMapper.java
@@ -55,10 +55,15 @@ public class CmHandleIdMapper {
private boolean addMappingWithValidation(final String cmHandleId, final String alternateId) {
- if (StringUtils.isBlank(alternateId)) {
+ if (alternateIdPerCmHandleId.containsKey(cmHandleId)) {
+ final String originalAlternateId = alternateIdPerCmHandleId.get(cmHandleId);
+ if (!originalAlternateId.equals(alternateId)) {
+ log.warn("Alternate id update ignored, cannot update cm handle {}, already has an alternate id of {}",
+ cmHandleId, originalAlternateId);
+ }
return false;
}
- if (isDuplicateId(cmHandleId, alternateId)) {
+ if (StringUtils.isBlank(alternateId)) {
return false;
}
alternateIdPerCmHandleId.put(cmHandleId, alternateId);
@@ -77,32 +82,10 @@ public class CmHandleIdMapper {
}
}
- /**
- * Check if alternate id is already used.
- *
- * @param cmHandleId the cmHandle id.
- * @param alternateId the alternate id.
- * @return boolean true if the alternate id is already used.
- */
- public boolean isDuplicateId(final String cmHandleId, final String alternateId) {
- if (StringUtils.isBlank(alternateId)) {
- return false;
- }
- if (cmHandleIdPerAlternateId.get(alternateId) != null) {
- log.warn("The given alternate id was added to the cache already: {}", alternateId);
- return true;
- }
- if (alternateIdPerCmHandleId.get(cmHandleId) != null) {
- log.warn("The given cmhandle id was added to the cache already: {}", cmHandleId);
- return true;
- }
- return false;
- }
-
private void initializeCache() {
if (!cacheIsInitialized) {
networkCmProxyCmHandleQueryService.getAllCmHandles().forEach(cmHandle ->
- addMappingWithValidation(cmHandle.getCmHandleId(), cmHandle.getAlternateId())
+ addMappingWithValidation(cmHandle.getCmHandleId(), cmHandle.getAlternateId())
);
log.info("Alternate ID cache initialized from DB with {} cm handle/alternate id pairs ",
alternateIdPerCmHandleId.size());