From 0cb3dec31d5a42ef00e89038aef1625179c8ac00 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Thu, 23 Jan 2025 12:34:40 +0000 Subject: Fix for cm handles stuck in LOCKED during registration - Additional Error logging when cm handles fail module sync - Swallow already defined exception upon schema and/or anchor creation - Updated integration test to try to reproduce the problem (but couldn't) - Ignored integration tests that depend/affected by race conditions (they are useful for troubleshooting but not for pipeline checks) - Removed last remnants of springboot retry annotation option (incl dependencies) Issue-ID: CPS-2576 Change-Id: I910e802268332f955134c043bd1b46a7ec57233b Signed-off-by: ToineSiebelink --- .../impl/inventory/sync/ModuleSyncService.java | 30 ++++++++++++++++---- .../ncmp/impl/inventory/sync/ModuleSyncTasks.java | 2 +- .../inventory/sync/ModuleSyncServiceSpec.groovy | 32 +++++++++++++++++++--- 3 files changed, 54 insertions(+), 10 deletions(-) (limited to 'cps-ncmp-service') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java index 041daa0927..6c1dc731c6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java @@ -35,6 +35,8 @@ import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsAnchorService; import org.onap.cps.api.CpsDataService; import org.onap.cps.api.CpsModuleService; +import org.onap.cps.api.exceptions.AlreadyDefinedException; +import org.onap.cps.api.exceptions.DuplicatedYangResourceException; import org.onap.cps.api.model.ModuleReference; import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; import org.onap.cps.utils.ContentType; @@ -68,7 +70,12 @@ public class ModuleSyncService { final String moduleSetTag = yangModelCmHandle.getModuleSetTag(); final String schemaSetName = getSchemaSetName(cmHandleId, moduleSetTag); syncAndCreateSchemaSet(yangModelCmHandle, schemaSetName); - cpsAnchorService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName, cmHandleId); + try { + cpsAnchorService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName, cmHandleId); + } catch (final AlreadyDefinedException alreadyDefinedException) { + log.warn("Ignoring (anchor) already exist exception for {}. Exception details: ", + yangModelCmHandle.getId(), alreadyDefinedException); + } } /** @@ -99,14 +106,27 @@ public class ModuleSyncService { private void syncAndCreateSchemaSet(final YangModelCmHandle yangModelCmHandle, final String schemaSetName) { if (isNewSchemaSet(schemaSetName)) { final ModuleDelta moduleDelta = getModuleDelta(yangModelCmHandle); - log.info("Creating Schema Set {} for CM Handle {}", schemaSetName, yangModelCmHandle.getId()); - cpsModuleService.createSchemaSetFromModules( + try { + log.info("Creating Schema Set {} for CM Handle {}", schemaSetName, yangModelCmHandle.getId()); + cpsModuleService.createSchemaSetFromModules( NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName, moduleDelta.newModuleNameToContentMap, moduleDelta.allModuleReferences - ); - log.info("Successfully created Schema Set {} for CM Handle {}", schemaSetName, yangModelCmHandle.getId()); + ); + log.info("Successfully created Schema Set {} for CM Handle {}", schemaSetName, + yangModelCmHandle.getId()); + } catch (final AlreadyDefinedException alreadyDefinedException) { + log.warn("Ignoring already exist (schema set) exception for {}. Exception details: ", + yangModelCmHandle.getId(), alreadyDefinedException); + } catch (final DuplicatedYangResourceException duplicatedYangResourceException) { + log.warn("Duplicate Yang Resource {} creation for {}. " + + "CM Handle will be LOCKED (for retry). Exception details: ", + duplicatedYangResourceException.getName(), + yangModelCmHandle.getId(), + duplicatedYangResourceException); + throw duplicatedYangResourceException; + } } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java index 40404b719a..b63496753e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java @@ -114,7 +114,7 @@ public class ModuleSyncTasks { compositeState.setLockReason(null); return CmHandleState.READY; } catch (final Exception e) { - log.warn("Processing of {} failed,reason : {}.", yangModelCmHandle.getId(), e.getMessage()); + log.warn("Processing of {} failed,reason : ", yangModelCmHandle.getId(), e); final LockReasonCategory lockReasonCategory = inUpgrade ? LockReasonCategory.MODULE_UPGRADE_FAILED : LockReasonCategory.MODULE_SYNC_FAILED; diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy index 7881375762..868609e282 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy @@ -90,21 +90,45 @@ class ModuleSyncServiceSpec extends Specification { 'without' | '' } - def 'Attempt Sync models for a cm handle with existing schema set (#originalException).'() { + def 'Sync models for a cm handle with already defined exception upon schema set creation.'() { given: 'a cm handle to be synced' def yangModelCmHandle = createAdvisedCmHandle('existing tag') and: 'dmi returns no new yang resources' mockDmiModelOperations.getNewYangResourcesFromDmi(*_) >> [:] and: 'already defined exception occurs when creating schema (existing)' + mockCpsModuleService.createSchemaSetFromModules(*_) >> { throw AlreadyDefinedException.forSchemaSet('', '', null) } + when: 'module sync is triggered' + objectUnderTest.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle) + then: 'the exception is ignored' + noExceptionThrown() + } + + def 'Sync models for a cm handle with already defined exception upon anchor set creation.'() { + given: 'a cm handle to be synced' + def yangModelCmHandle = createAdvisedCmHandle('existing tag') + and: 'dmi returns no new yang resources' + mockDmiModelOperations.getNewYangResourcesFromDmi(*_) >> [:] + and: 'already defined exception occurs when creating schema (existing)' + mockCpsAnchorService.createAnchor(*_) >> { throw AlreadyDefinedException.forAnchor('', '', null) } + when: 'module sync is triggered' + objectUnderTest.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle) + then: 'the exception is ignored' + noExceptionThrown() + } + + def 'Attempt Sync models for a cm handle with duplicate yang resources exception).'() { + given: 'a cm handle to be synced' + def yangModelCmHandle = createAdvisedCmHandle('existing tag') + and: 'dmi returns no new yang resources' + mockDmiModelOperations.getNewYangResourcesFromDmi(*_) >> [:] + and: 'duplicate yang resource exception occurs when creating schema' + def originalException = new DuplicatedYangResourceException('', '', null) mockCpsModuleService.createSchemaSetFromModules(*_) >> { throw originalException } when: 'module sync is triggered' objectUnderTest.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle) then: 'same exception is thrown up' def thrownException = thrown(Exception) assert thrownException == originalException - where: 'following exceptions occur' - originalException << [AlreadyDefinedException.forSchemaSet('', '', null), - new DuplicatedYangResourceException('', '', null) ] } def 'Model upgrade without using Module Set Tags (legacy) where the modules are in database.'() { -- cgit 1.2.3-korg