Updating CmHandleStates using batch operation 98/132898/3
authorJosephKeenan <joseph.keenan@est.tech>
Wed, 11 Jan 2023 09:18:07 +0000 (09:18 +0000)
committerJosephKeenan <joseph.keenan@est.tech>
Thu, 12 Jan 2023 16:13:05 +0000 (16:13 +0000)
Issue-ID: CPS-1424
Signed-off-by: JosephKeenan <joseph.keenan@est.tech>
Change-Id: Ia67db468ece4a7ab694d95cb63a954f24dd8cb55

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 d00d211..5aad404 100755 (executable)
@@ -93,8 +93,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
             final DmiPluginRegistration dmiPluginRegistration) {
         dmiPluginRegistration.validateDmiPluginRegistration();
         final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse();
-        dmiPluginRegistrationResponse.setRemovedCmHandles(
-                parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration.getRemovedCmHandles()));
+
+        if (!dmiPluginRegistration.getRemovedCmHandles().isEmpty()) {
+            dmiPluginRegistrationResponse.setRemovedCmHandles(
+                    parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration.getRemovedCmHandles()));
+        }
+
         if (!dmiPluginRegistration.getCreatedCmHandles().isEmpty()) {
             dmiPluginRegistrationResponse.setCreatedCmHandles(
                     parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(dmiPluginRegistration));
@@ -321,15 +325,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
             final List<String> tobeRemovedCmHandles) {
         final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
                 new ArrayList<>(tobeRemovedCmHandles.size());
+
+        setState(tobeRemovedCmHandles, CmHandleState.DELETING);
+
         for (final String cmHandleId : tobeRemovedCmHandles) {
             try {
-                final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
-                lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle,
-                        CmHandleState.DELETING);
                 deleteCmHandleFromDbAndModuleSyncMap(cmHandleId);
                 cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
-                lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle,
-                        CmHandleState.DELETED);
             } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
                 log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
                         cmHandleId, dataNodeNotFoundException.getMessage());
@@ -347,9 +349,22 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
                         CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception));
             }
         }
+
+        setState(tobeRemovedCmHandles, CmHandleState.DELETED);
+
         return cmHandleRegistrationResponses;
     }
 
+    private void setState(final List<String> tobeRemovedCmHandles, final CmHandleState cmHandleState) {
+        final Map<YangModelCmHandle, CmHandleState> cmHandleIdsToBeRemoved = new HashMap<>();
+        for (final String cmHandleId : tobeRemovedCmHandles) {
+            cmHandleIdsToBeRemoved.put(
+                    inventoryPersistence.getYangModelCmHandle(cmHandleId),
+                    cmHandleState);
+        }
+        lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleIdsToBeRemoved);
+    }
+
     private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) {
         inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId);
         inventoryPersistence.deleteListOrListElement("/dmi-registry/cm-handles[@id='" + cmHandleId + "']");
index e6c79f8..1ebd69e 100644 (file)
@@ -252,7 +252,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
         when: 'registration is updated to delete cmhandle'
             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
         then: 'the cmHandle state is updated to "DELETING"'
-            1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.DELETING)
+        1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_)
         and: 'method to delete relevant schema set is called once'
             1 * mockInventoryPersistence.deleteSchemaSetWithCascade(_)
         and: 'method to delete relevant list/list element is called once'
@@ -264,7 +264,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
                 assert it.cmHandle == 'cmhandle'
             }
         and: 'the cmHandle state is updated to "DELETED"'
-            1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.DELETED)
+            1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_)
         where:
             scenario                                            | schemaSetExist
             'schema-set exists and can be deleted successfully' | true