From 485bf11a812a1f0e37667c40c85f6a7cbeec41db Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Fri, 12 Jan 2024 10:24:42 +0000 Subject: moduleSetTag and cmhandle upgrade functionalities fix - Insert only unmapped yang resources - In case of removed module call dmi plugin service to get modules. Issue-ID: CPS-2027 Change-Id: Ic1903c20169a913c835a3eee909357daec45f51e Signed-off-by: sourabh_sourabh --- .../onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java | 6 +++++- .../cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java | 9 ++++++--- .../onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java | 5 ++++- 3 files changed, 15 insertions(+), 5 deletions(-) (limited to 'cps-ncmp-service/src/main/java') 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 4fc840929..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 @@ -107,6 +107,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private final Map trustLevelPerDmiPlugin; private final TrustLevelManager trustLevelManager; private final CmHandleIdMapper cmHandleIdMapper; + private final Map> moduleSetTagCache; @Override public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule( @@ -353,13 +354,16 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService new ArrayList<>(tobeRemovedCmHandles.size()); final Collection yangModelCmHandles = inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles); - + final Set moduleSetTags = yangModelCmHandles.stream().map(YangModelCmHandle::getModuleSetTag) + .collect(Collectors.toSet()); updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING); final Set notDeletedCmHandles = new HashSet<>(); for (final List tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandles, DELETE_BATCH_SIZE)) { try { batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch); + moduleSetTags.forEach(moduleSetTagCache::remove); + log.debug("Removed module set tags: {}", moduleSetTags); tobeRemovedCmHandleBatch.forEach(cmHandleId -> cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId))); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java index 750be2dc8..22bbc7383 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleOperationsUtils.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation + * Copyright (C) 2022-2024 Nordix Foundation * Modifications Copyright (C) 2022 Bell Canada * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -68,6 +68,10 @@ public class ModuleOperationsUtils { private static final String LOCK_REASON_DETAILS_MSG_FORMAT = UPGRADE_FORMAT + " Attempt #%d failed: %s"; private static final Pattern retryAttemptPattern = Pattern.compile("Attempt #(\\d+) failed:.+"); private static final Pattern moduleSetTagPattern = Pattern.compile("Upgrade to ModuleSetTag: (\\S+)"); + private static final String CPS_PATH_CM_HANDLES_MODEL_SYNC_FAILED_OR_UPGRADE = """ + //lock-reason[@reason="MODULE_SYNC_FAILED" + or @reason="MODULE_UPGRADE" + or @reason="MODULE_UPGRADE_FAILED"]"""; /** * Query data nodes for cm handles with an "ADVISED" cm handle state. @@ -110,8 +114,7 @@ public class ModuleOperationsUtils { */ public List getCmHandlesThatFailedModelSyncOrUpgrade() { final List lockedCmHandlesAsDataNodeList - = cmHandleQueries.queryCmHandleAncestorsByCpsPath( - "//lock-reason[@reason=\"MODULE_SYNC_FAILED\" or @reason=\"MODULE_UPGRADE\"]", + = cmHandleQueries.queryCmHandleAncestorsByCpsPath(CPS_PATH_CM_HANDLES_MODEL_SYNC_FAILED_OR_UPGRADE, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); return convertCmHandlesDataNodesToYangModelCmHandles(lockedCmHandlesAsDataNodeList); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java index b21a2f1f8..72d322605 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation + * Copyright (C) 2022-2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,6 +91,9 @@ public class ModuleSyncService { existingAnchorName, inUpgrade); updateModuleSetTagCache(moduleSetTag, moduleReferencesFromExistingCmHandle); } else { + if (inUpgrade) { + deleteSchemaSetIfExists(cmHandleId); + } final Collection allModuleReferencesFromCmHandle = syncAndCreateSchemaSet(yangModelCmHandle); updateModuleSetTagCache(moduleSetTag, allModuleReferencesFromCmHandle); -- cgit 1.2.3-korg