From 105432686d7b840a0378fadcc32abb73976006bf Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Thu, 9 Feb 2023 15:52:33 +0000 Subject: Use getDataNodes (plural) in CmHandle deregistration Issue-ID: CPS-1426 Signed-off-by: danielhanrahan Change-Id: I0ad79bf36840cdecc13898e185dc618cedafd529 --- .../api/impl/NetworkCmProxyDataServiceImpl.java | 27 ++++++++++------------ ...rkCmProxyDataServiceImplRegistrationSpec.groovy | 16 ++++++------- 2 files changed, 19 insertions(+), 24 deletions(-) (limited to 'cps-ncmp-service') 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 59b960af6..e71b72ab8 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 @@ -327,36 +327,33 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final List tobeRemovedCmHandles) { final List cmHandleRegistrationResponses = new ArrayList<>(tobeRemovedCmHandles.size()); - final Map cmHandleIdToYangModelCmHandleMap = tobeRemovedCmHandles.stream() - .collect(Collectors.toMap(cmHandleId -> cmHandleId, inventoryPersistence::getYangModelCmHandle)); + final Collection yangModelCmHandles = + inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles); - final Collection yangModelCmHandles = cmHandleIdToYangModelCmHandleMap.values(); updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING); + final Set notDeletedCmHandles = new HashSet<>(); for (final List tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandles, DELETE_BATCH_SIZE)) { try { batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch); tobeRemovedCmHandleBatch.forEach(cmHandleId -> cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId))); - } catch (final Exception batchException) { + } catch (final RuntimeException batchException) { log.error("Unable to de-register cm-handle batch, retrying on each cm handle"); for (final String cmHandleId : tobeRemovedCmHandleBatch) { final CmHandleRegistrationResponse cmHandleRegistrationResponse = deleteCmHandleAndGetCmHandleRegistrationResponse(cmHandleId); cmHandleRegistrationResponses.add(cmHandleRegistrationResponse); + if (cmHandleRegistrationResponse.getStatus() != CmHandleRegistrationResponse.Status.SUCCESS) { + notDeletedCmHandles.add(cmHandleId); + } } } } - final Collection deletedYangModelCmHandles = - cmHandleRegistrationResponses.stream() - .filter(cmHandleRegistrationResponse -> - cmHandleRegistrationResponse.getStatus().equals(CmHandleRegistrationResponse.Status.SUCCESS)) - .map(CmHandleRegistrationResponse::getCmHandle) - .map(cmHandleIdToYangModelCmHandleMap::get) - .collect(Collectors.toList()); - updateCmHandleStateBatch(deletedYangModelCmHandles, CmHandleState.DELETED); + yangModelCmHandles.removeIf(yangModelCmHandle -> notDeletedCmHandles.contains(yangModelCmHandle.getId())); + updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETED); return cmHandleRegistrationResponses; } @@ -383,9 +380,9 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private void updateCmHandleStateBatch(final Collection yangModelCmHandles, final CmHandleState cmHandleState) { - final Map cmHandleIdsToBeRemoved = new HashMap<>(); - yangModelCmHandles.forEach(yangModelCmHandle -> cmHandleIdsToBeRemoved.put(yangModelCmHandle, cmHandleState)); - lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleIdsToBeRemoved); + final Map cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size()); + yangModelCmHandles.forEach(yangModelCmHandle -> cmHandleStatePerCmHandle.put(yangModelCmHandle, cmHandleState)); + lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); } private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy index e8c53738b..cf3454991 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy @@ -74,8 +74,8 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { dmiRegistration.setCreatedCmHandles([new NcmpServiceCmHandle(cmHandleId: 'cmhandle-1', publicProperties: ['publicProp1': 'value'], dmiProperties: [:])]) dmiRegistration.setUpdatedCmHandles([new NcmpServiceCmHandle(cmHandleId: 'cmhandle-2', publicProperties: ['publicProp1': 'value'], dmiProperties: [:])]) dmiRegistration.setRemovedCmHandles(['cmhandle-2']) - and: 'any cm handle is persisted' - mockInventoryPersistence.getYangModelCmHandle(_) >> new YangModelCmHandle() + and: 'cm handles are persisted' + mockInventoryPersistence.getYangModelCmHandles(['cmhandle-2']) >> [new YangModelCmHandle()] when: 'registration is processed' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiRegistration) then: 'cm-handles are removed first' @@ -245,7 +245,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def 'Remove CmHandle Successfully: #scenario'() { given: 'a registration' - mockInventoryPersistence.getYangModelCmHandle(_) >> new YangModelCmHandle() + addPersistedYangModelCmHandles(['cmhandle']) def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server', removedCmHandles: ['cmhandle']) and: '#scenario' @@ -319,7 +319,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def 'Remove CmHandle Error Handling: Schema Set Deletion failed'() { given: 'a registration' - mockInventoryPersistence.getYangModelCmHandle('cmhandle') >> new YangModelCmHandle() + addPersistedYangModelCmHandles(['cmhandle']) def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server', removedCmHandles: ['cmhandle']) and: 'schema set deletion failed with unknown error' @@ -344,7 +344,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def 'Remove CmHandle Error Handling: #scenario'() { given: 'a registration' - mockInventoryPersistence.getYangModelCmHandle('cmhandle') >> new YangModelCmHandle() + addPersistedYangModelCmHandles(['cmhandle']) def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server', removedCmHandles: ['cmhandle']) and: 'cm-handle deletion fails on batch' @@ -378,9 +378,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { } def addPersistedYangModelCmHandles(ids) { - ids.each { - def yangModelCmHandle = new YangModelCmHandle(id:it) - mockInventoryPersistence.getYangModelCmHandle(it) >> yangModelCmHandle - } + def yangModelCmHandles = ids.collect { new YangModelCmHandle(id:it) } + mockInventoryPersistence.getYangModelCmHandles(ids) >> yangModelCmHandles } } -- cgit 1.2.3-korg