Add exception handling to delete schema set when a registration is removed 10/126210/4
authorniamhcore <niamh.core@est.tech>
Mon, 13 Dec 2021 10:34:52 +0000 (10:34 +0000)
committerniamhcore <niamh.core@est.tech>
Tue, 14 Dec 2021 14:24:04 +0000 (14:24 +0000)
Issue-ID: CPS-783
Signed-off-by: niamhcore <niamh.core@est.tech>
Change-Id: Ief4c6727e788822bc29379a757d25dff14f68c94

cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy

index faa2efe..62a0922 100755 (executable)
@@ -297,8 +297,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     private void parseAndRemoveCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
         for (final String cmHandle : dmiPluginRegistration.getRemovedCmHandles()) {
             try {
-                cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle,
-                    CASCADE_DELETE_ALLOWED);
+                attemptToDeleteSchemaSetWithCascade(cmHandle);
                 cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
                     "/dmi-registry/cm-handles[@id='" + cmHandle + "']", NO_TIMESTAMP);
             } catch (final DataNodeNotFoundException e) {
@@ -307,6 +306,15 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
         }
     }
 
+    private void attemptToDeleteSchemaSetWithCascade(final String schemaSetName) {
+        try {
+            cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName,
+                CASCADE_DELETE_ALLOWED);
+        } catch (final Exception e) {
+            log.warn("Schema set {} delete failed, reason {}", schemaSetName, e.getMessage());
+        }
+    }
+
     private void syncAndCreateSchemaSet(final PersistenceCmHandle persistenceCmHandle) {
 
         final List<ModuleReference> moduleReferencesFromCmHandle =
index 4108454..8c3e593 100644 (file)
@@ -126,6 +126,19 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
             noExceptionThrown()
     }
 
+    def 'Register a DMI Plugin for the given cm-handle(s) with no schema set found during delete process.'() {
+        given: 'a registration'
+            def objectUnderTest = getObjectUnderTestWithModelSyncDisabled()
+            def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'my-server')
+            dmiPluginRegistration.removedCmHandles = cmHandlesArray
+        and: 'an exception occurs during delete schema set process'
+            mockCpsModuleService.deleteSchemaSet(_,_,_) >>  { throw (new Exception('')) }
+        when: 'registration is updated and modules are synced'
+            objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+        then: 'delete list or list element is still called'
+            1 * mockCpsDataService.deleteListOrListElement(_,_,_,_)
+    }
+
     def 'Dmi plugin registration with #scenario'() {
         given: 'a registration '
             def objectUnderTest = getObjectUnderTestWithModelSyncDisabled()