diff options
author | halil.cakal <halil.cakal@est.tech> | 2024-11-04 17:47:55 +0000 |
---|---|---|
committer | halil.cakal <halil.cakal@est.tech> | 2024-11-04 17:53:20 +0000 |
commit | c475188530572efedbcb606239da0cdcee48c05b (patch) | |
tree | d2d566553e0f02b0f80df4c42a5444ed5c6462b8 | |
parent | a5e97f16b513ceab58e9b221e492fc9d272d5145 (diff) |
Refactor module synch task
- improve readablity of ModuleSyncTasks
Issue-ID: CPS-2474
Change-Id: Ib0342e8fad00b431a293c5095fe54f4917f7a51b
Signed-off-by: halil.cakal <halil.cakal@est.tech>
-rw-r--r-- | cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncTasks.java | 55 |
1 files changed, 29 insertions, 26 deletions
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 f00ac608b9..31fcbad08b 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 @@ -59,32 +59,12 @@ public class ModuleSyncTasks { public CompletableFuture<Void> performModuleSync(final Collection<DataNode> cmHandlesAsDataNodes, final AtomicInteger batchCounter) { final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = - new HashMap<>(cmHandlesAsDataNodes.size()); + new HashMap<>(cmHandlesAsDataNodes.size()); try { - for (final DataNode cmHandleAsDataNode : cmHandlesAsDataNodes) { - final String cmHandleId = String.valueOf(cmHandleAsDataNode.getLeaves().get("id")); + cmHandlesAsDataNodes.forEach(cmHandleAsDataNode -> { final YangModelCmHandle yangModelCmHandle = YangDataConverter.toYangModelCmHandle(cmHandleAsDataNode); - final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId); - final boolean inUpgrade = ModuleOperationsUtils.inUpgradeOrUpgradeFailed(compositeState); - try { - if (inUpgrade) { - moduleSyncService.syncAndUpgradeSchemaSet(yangModelCmHandle); - } else { - moduleSyncService.deleteSchemaSetIfExists(cmHandleId); - moduleSyncService.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle); - } - yangModelCmHandle.getCompositeState().setLockReason(null); - 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 - : LockReasonCategory.MODULE_SYNC_FAILED; - moduleOperationsUtils.updateLockReasonWithAttempts(compositeState, - lockReasonCategory, e.getMessage()); - setCmHandleStateLocked(yangModelCmHandle, compositeState.getLockReason()); - cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED); - } - } + cmHandleStatePerCmHandle.put(yangModelCmHandle, processCmHandle(yangModelCmHandle)); + }); } finally { batchCounter.getAndDecrement(); lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); @@ -107,13 +87,36 @@ public class ModuleSyncTasks { final CompositeState compositeState = yangModelCmHandle.getCompositeState(); final String resetCmHandleId = yangModelCmHandle.getId(); log.debug("Resetting CM handle {} state to ADVISED for retry by the module-sync watchdog. Lock reason: {}", - yangModelCmHandle.getId(), compositeState.getLockReason().getLockReasonCategory().name()); + yangModelCmHandle.getId(), compositeState.getLockReason().getLockReasonCategory().name()); cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.ADVISED); removeResetCmHandleFromModuleSyncMap(resetCmHandleId); } lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); } + private CmHandleState processCmHandle(final YangModelCmHandle yangModelCmHandle) { + final CompositeState compositeState = inventoryPersistence.getCmHandleState(yangModelCmHandle.getId()); + final boolean inUpgrade = ModuleOperationsUtils.inUpgradeOrUpgradeFailed(compositeState); + try { + if (inUpgrade) { + moduleSyncService.syncAndUpgradeSchemaSet(yangModelCmHandle); + } else { + moduleSyncService.deleteSchemaSetIfExists(yangModelCmHandle.getId()); + moduleSyncService.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle); + } + yangModelCmHandle.getCompositeState().setLockReason(null); + return CmHandleState.READY; + } catch (final Exception e) { + log.warn("Processing of {} module failed due to reason {}.", yangModelCmHandle.getId(), e.getMessage()); + final LockReasonCategory lockReasonCategory = inUpgrade ? LockReasonCategory.MODULE_UPGRADE_FAILED + : LockReasonCategory.MODULE_SYNC_FAILED; + moduleOperationsUtils.updateLockReasonWithAttempts(compositeState, + lockReasonCategory, e.getMessage()); + setCmHandleStateLocked(yangModelCmHandle, compositeState.getLockReason()); + return CmHandleState.LOCKED; + } + } + private void setCmHandleStateLocked(final YangModelCmHandle advisedCmHandle, final CompositeState.LockReason lockReason) { advisedCmHandle.getCompositeState().setLockReason(lockReason); @@ -124,4 +127,4 @@ public class ModuleSyncTasks { log.info("{} removed from in progress map", resetCmHandleId); } } -} +}
\ No newline at end of file |