From 884a5a0e8bf08cc47e0e0dbd7e20558212ca82b1 Mon Sep 17 00:00:00 2001 From: lukegleeson Date: Mon, 27 Jun 2022 16:26:21 +0100 Subject: Allow Module Re-Sync Allows the Resync of an already synced CmHandle Currently: Advised -(create schemaset)-> Ready -(manual write)-> Advised -> Locked as schemaset for cmhandle already exists With this: Advised -(create schemaset)-> Ready -(manual write)-> Advised -(delete schemaset, create schemaset)-> Ready Included some logging Renamed ModuleSyncSpec -> ModuleSyncWatchdogSpec to match class Issue-ID: CPS-1045 Signed-off-by: lukegleeson Change-Id: I408fbea698b7926dbf5d0cddc74acf1b00235b1f --- .../ncmp/api/inventory/sync/ModuleSyncService.java | 19 +++++++++++++++++++ .../ncmp/api/inventory/sync/ModuleSyncWatchdog.java | 1 + 2 files changed, 20 insertions(+) (limited to 'cps-ncmp-service/src/main/java/org') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java index 58e2bf345..c574aa61d 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java @@ -32,6 +32,8 @@ import org.onap.cps.api.CpsAdminService; import org.onap.cps.api.CpsModuleService; import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; +import org.onap.cps.spi.CascadeDeleteAllowed; +import org.onap.cps.spi.exceptions.SchemaSetNotFoundException; import org.onap.cps.spi.model.ModuleReference; import org.springframework.stereotype.Service; @@ -83,4 +85,21 @@ public class ModuleSyncService { schemaSetAndAnchorName); } + /** + * Deletes the SchemaSet for provided cmHandle if the SchemaSet Exists. + * + * @param yangModelCmHandle the yang model of cm handle. + */ + public void deleteSchemaSetIfExists(final YangModelCmHandle yangModelCmHandle) { + final String schemaSetAndAnchorName = yangModelCmHandle.getId(); + try { + cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetAndAnchorName, + CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED); + log.debug("SchemaSet for {} has been deleted. Ready to be recreated.", schemaSetAndAnchorName); + } catch (final SchemaSetNotFoundException e) { + log.debug("No SchemaSet for {}. Assuming CmHandle has not been previously Module Synced.", + schemaSetAndAnchorName); + } + } + } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java index 402f9f6b4..9383ac1ef 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java @@ -53,6 +53,7 @@ public class ModuleSyncWatchdog { final String cmHandleId = advisedCmHandle.getId(); final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId); try { + moduleSyncService.deleteSchemaSetIfExists(advisedCmHandle); moduleSyncService.syncAndCreateSchemaSetAndAnchor(advisedCmHandle); compositeState.setCmHandleState(CmHandleState.READY); } catch (final Exception e) { -- cgit 1.2.3-korg