[Module Sync] Always update states at end of batch 19/139319/1
authordanielhanrahan <daniel.hanrahan@est.tech>
Fri, 1 Nov 2024 17:35:21 +0000 (17:35 +0000)
committerdanielhanrahan <daniel.hanrahan@est.tech>
Mon, 4 Nov 2024 13:26:23 +0000 (13:26 +0000)
This commit moves the state update code into the 'finally'
block, so that state updates are always sent for the handles
that finished syncing, even if an exception occurred.
This commit also fixes a typo in cmHandleStatePerCmHandle.

Issue-ID: CPS-2474
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Ic25608a5772c0873fe0d0f8aca8d70bcda51d94a

cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java

index 80cdea8..f00ac60 100644 (file)
@@ -58,9 +58,9 @@ public class ModuleSyncTasks {
      */
     public CompletableFuture<Void> performModuleSync(final Collection<DataNode> cmHandlesAsDataNodes,
                                                      final AtomicInteger batchCounter) {
+        final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle =
+                new HashMap<>(cmHandlesAsDataNodes.size());
         try {
-            final Map<YangModelCmHandle, CmHandleState> cmHandelStatePerCmHandle
-                    = new HashMap<>(cmHandlesAsDataNodes.size());
             for (final DataNode cmHandleAsDataNode : cmHandlesAsDataNodes) {
                 final String cmHandleId = String.valueOf(cmHandleAsDataNode.getLeaves().get("id"));
                 final YangModelCmHandle yangModelCmHandle = YangDataConverter.toYangModelCmHandle(cmHandleAsDataNode);
@@ -74,7 +74,7 @@ public class ModuleSyncTasks {
                         moduleSyncService.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle);
                     }
                     yangModelCmHandle.getCompositeState().setLockReason(null);
-                    cmHandelStatePerCmHandle.put(yangModelCmHandle, CmHandleState.READY);
+                    cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.READY);
                 } catch (final Exception e) {
                     log.warn("Processing of {} module failed due to reason {}.", cmHandleId, e.getMessage());
                     final LockReasonCategory lockReasonCategory = inUpgrade ? LockReasonCategory.MODULE_UPGRADE_FAILED
@@ -82,12 +82,12 @@ public class ModuleSyncTasks {
                     moduleOperationsUtils.updateLockReasonWithAttempts(compositeState,
                             lockReasonCategory, e.getMessage());
                     setCmHandleStateLocked(yangModelCmHandle, compositeState.getLockReason());
-                    cmHandelStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED);
+                    cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED);
                 }
             }
-            lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandelStatePerCmHandle);
         } finally {
             batchCounter.getAndDecrement();
+            lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
             log.info("Processing module sync batch finished. {} batch(es) active.", batchCounter.get());
         }
         return CompletableFuture.completedFuture(null);