diff options
author | 2024-02-08 16:36:52 +0000 | |
---|---|---|
committer | 2024-02-08 16:36:52 +0000 | |
commit | 590a3ee140e06a979aaf49f55bb4f8e3c7ce8e17 (patch) | |
tree | 5fdcf08771bc475ecc14364ba7dc7e2a5046577e /cps-ncmp-service/src/main | |
parent | 814b882c6bf85a88c9135edb592e90d46af31f9a (diff) | |
parent | e190adf9b0e8e0bb9e5012dd40b712c97e45c9de (diff) |
Merge "Revert "Introduce Hazelcast for alternateId-cmHandle relation pt. 2 - error collection""
Diffstat (limited to 'cps-ncmp-service/src/main')
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 e7293b2fd..b9c834c55 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 ad1c5cdfb..05b83b98e 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 0520f456a..13b3fcafb 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 40c620f50..a88adbd11 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()); |