CmSubscription overlapping case 75/138075/4
authormpriyank <priyank.maheshwari@est.tech>
Fri, 24 May 2024 10:38:06 +0000 (11:38 +0100)
committermpriyank <priyank.maheshwari@est.tech>
Mon, 27 May 2024 09:46:34 +0000 (10:46 +0100)
- Directly ACCEPT the CmSubscription request in case of overlapping
  scenario
- The confirmation will be sent out when the DMI timeout has happened
- No request sent out to DMI plugin in this scenario

Issue-ID: CPS-2237
Change-Id: Ic799801058e9c8e1c2db8780a42ab85ea306f45e
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmNotificationSubscriptionDelta.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionHandlerServiceImpl.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmNotificationSubscriptionDeltaSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionHandlerServiceImplSpec.groovy

index 8a4beb9..4e2062f 100644 (file)
@@ -64,12 +64,19 @@ public class CmNotificationSubscriptionDelta {
                 }
             }
 
-            final DmiCmNotificationSubscriptionPredicate predicateDelta =
-                new DmiCmNotificationSubscriptionPredicate(targetCmHandleIds, datastoreType, xpaths);
+            populateValidDmiCmNotificationSubscriptionPredicateDelta(targetCmHandleIds, xpaths, datastoreType, delta);
+        }
+        return delta;
+    }
 
+    private void populateValidDmiCmNotificationSubscriptionPredicateDelta(final Set<String> targetCmHandleIds,
+            final Set<String> xpaths, final DatastoreType datastoreType,
+            final List<DmiCmNotificationSubscriptionPredicate> delta) {
+        if (!(targetCmHandleIds.isEmpty() || xpaths.isEmpty())) {
+            final DmiCmNotificationSubscriptionPredicate predicateDelta =
+                    new DmiCmNotificationSubscriptionPredicate(targetCmHandleIds, datastoreType, xpaths);
             delta.add(predicateDelta);
         }
-        return delta;
     }
 
 }
index 7872ba0..128c675 100644 (file)
@@ -30,6 +30,7 @@ import org.onap.cps.ncmp.api.impl.events.cmsubscription.CmNotificationSubscripti
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.CmNotificationSubscriptionEventsHandler;
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.CmNotificationSubscriptionMappersHandler;
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.DmiCmNotificationSubscriptionCacheHandler;
+import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.CmNotificationSubscriptionStatus;
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionDetails;
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionPredicate;
 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.client_to_ncmp.CmNotificationSubscriptionNcmpInEvent;
@@ -56,11 +57,10 @@ public class CmNotificationSubscriptionHandlerServiceImpl implements CmNotificat
 
         if (cmNotificationSubscriptionPersistenceService.isUniqueSubscriptionId(subscriptionId)) {
             dmiCmNotificationSubscriptionCacheHandler.add(subscriptionId, predicates);
-            sendSubscriptionCreateRequestToDmi(subscriptionId);
+            handleCmNotificationSubscriptionDelta(subscriptionId);
             scheduleCmNotificationSubscriptionNcmpOutEventResponse(subscriptionId);
         } else {
-            rejectAndPublishCmNotificationSubscriptionCreateRequest(subscriptionId,
-                    predicates);
+            rejectAndPublishCmNotificationSubscriptionCreateRequest(subscriptionId, predicates);
         }
     }
 
@@ -81,18 +81,37 @@ public class CmNotificationSubscriptionHandlerServiceImpl implements CmNotificat
                 "subscriptionCreateResponse", cmNotificationSubscriptionNcmpOutEvent, false);
     }
 
-    private void sendSubscriptionCreateRequestToDmi(final String subscriptionId) {
+    private void handleCmNotificationSubscriptionDelta(final String subscriptionId) {
         final Map<String, DmiCmNotificationSubscriptionDetails> dmiCmNotificationSubscriptionDetailsMap =
                 dmiCmNotificationSubscriptionCacheHandler.get(subscriptionId);
         dmiCmNotificationSubscriptionDetailsMap.forEach((dmiPluginName, dmiCmNotificationSubscriptionDetails) -> {
             final List<DmiCmNotificationSubscriptionPredicate> dmiCmNotificationSubscriptionPredicates =
                     cmNotificationSubscriptionDelta.getDelta(
                             dmiCmNotificationSubscriptionDetails.getDmiCmNotificationSubscriptionPredicates());
-            final CmNotificationSubscriptionDmiInEvent cmNotificationSubscriptionDmiInEvent =
-                    cmNotificationSubscriptionMappersHandler.toCmNotificationSubscriptionDmiInEvent(
-                            dmiCmNotificationSubscriptionPredicates);
-            cmNotificationSubscriptionEventsHandler.publishCmNotificationSubscriptionDmiInEvent(subscriptionId,
-                    dmiPluginName, "subscriptionCreateRequest", cmNotificationSubscriptionDmiInEvent);
+
+            if (dmiCmNotificationSubscriptionPredicates.isEmpty()) {
+                acceptAndPublishCmNotificationSubscriptionNcmpOutEventPerDmi(subscriptionId, dmiPluginName);
+            } else {
+                publishCmNotificationSubscriptionDmiInEventPerDmi(subscriptionId, dmiPluginName,
+                        dmiCmNotificationSubscriptionPredicates);
+            }
         });
     }
-}
\ No newline at end of file
+
+    private void publishCmNotificationSubscriptionDmiInEventPerDmi(final String subscriptionId,
+            final String dmiPluginName,
+            final List<DmiCmNotificationSubscriptionPredicate> dmiCmNotificationSubscriptionPredicates) {
+        final CmNotificationSubscriptionDmiInEvent cmNotificationSubscriptionDmiInEvent =
+                cmNotificationSubscriptionMappersHandler.toCmNotificationSubscriptionDmiInEvent(
+                        dmiCmNotificationSubscriptionPredicates);
+        cmNotificationSubscriptionEventsHandler.publishCmNotificationSubscriptionDmiInEvent(subscriptionId,
+                dmiPluginName, "subscriptionCreateRequest", cmNotificationSubscriptionDmiInEvent);
+    }
+
+    private void acceptAndPublishCmNotificationSubscriptionNcmpOutEventPerDmi(final String subscriptionId,
+            final String dmiPluginName) {
+        dmiCmNotificationSubscriptionCacheHandler.updateDmiCmNotificationSubscriptionStatusPerDmi(subscriptionId,
+                dmiPluginName, CmNotificationSubscriptionStatus.ACCEPTED);
+        dmiCmNotificationSubscriptionCacheHandler.persistIntoDatabasePerDmi(subscriptionId, dmiPluginName);
+    }
+}
index e506526..75db0bf 100644 (file)
@@ -46,4 +46,15 @@ class CmNotificationSubscriptionDeltaSpec extends Specification {
 
     }
 
+    def 'Find Delta of given list of predicates when it is an ongoing Cm Subscription'() {
+        given: 'A list of predicates'
+            def predicateList = [new DmiCmNotificationSubscriptionPredicate(['ch-1'].toSet(), DatastoreType.PASSTHROUGH_OPERATIONAL, ['a/1/'].toSet())]
+        and: 'its already present'
+            mockCmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(DatastoreType.PASSTHROUGH_OPERATIONAL, 'ch-1', 'a/1/') >>> true
+        when: 'getDelta is called'
+            def result = objectUnderTest.getDelta(predicateList)
+        then: 'verify correct delta is returned'
+            assert result.size() == 0
+    }
+
 }
index 98b4ee2..9156ae9 100644 (file)
@@ -25,10 +25,10 @@ import org.onap.cps.ncmp.api.impl.events.cmsubscription.CmNotificationSubscripti
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.CmNotificationSubscriptionEventsHandler
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.CmNotificationSubscriptionMappersHandler
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.DmiCmNotificationSubscriptionCacheHandler
-import org.onap.cps.ncmp.api.impl.events.cmsubscription.mapper.CmNotificationSubscriptionDmiInEventMapper
-import org.onap.cps.ncmp.api.impl.events.cmsubscription.mapper.CmNotificationSubscriptionNcmpOutEventMapper
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.CmNotificationSubscriptionStatus
 import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionDetails
+import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionPredicate
+import org.onap.cps.ncmp.api.impl.operations.DatastoreType
 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.client_to_ncmp.CmNotificationSubscriptionNcmpInEvent
 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.ncmp_to_dmi.CmNotificationSubscriptionDmiInEvent
 import org.onap.cps.ncmp.events.cmsubscription_merge1_0_0.ncmp_to_client.CmNotificationSubscriptionNcmpOutEvent
@@ -50,12 +50,12 @@ class CmNotificationSubscriptionHandlerServiceImplSpec extends Specification{
         mockCmNotificationSubscriptionEventsHandler, mockDmiCmNotificationSubscriptionCacheHandler)
 
     def testSubscriptionDetailsMap = ["dmi-1":new DmiCmNotificationSubscriptionDetails([], CmNotificationSubscriptionStatus.PENDING)]
-    def testListOfDeltaPredicates = []
 
     def 'Consume valid and unique CmNotificationSubscriptionNcmpInEvent create message'() {
         given: 'a cmNotificationSubscriptionNcmp in event with unique subscription id'
             def jsonData = TestUtils.getResourceFileContent('cmSubscription/cmNotificationSubscriptionNcmpInEvent.json')
             def testEventConsumed = jsonObjectMapper.convertJsonString(jsonData, CmNotificationSubscriptionNcmpInEvent.class)
+            def testListOfDeltaPredicates = [new DmiCmNotificationSubscriptionPredicate(['ch1'].toSet(), DatastoreType.PASSTHROUGH_OPERATIONAL, ['/a/b'].toSet())]
             mockCmNotificationSubscriptionPersistenceService.isUniqueSubscriptionId("test-id") >> true
         and: 'the cache handler returns for relevant subscription id'
             1 * mockDmiCmNotificationSubscriptionCacheHandler.get("test-id") >> testSubscriptionDetailsMap
@@ -77,6 +77,27 @@ class CmNotificationSubscriptionHandlerServiceImplSpec extends Specification{
                 "test-id", "subscriptionCreateResponse", null, true)
     }
 
+    def 'Consume valid and Overlapping Cm Notification Subscription NcmpIn Event'() {
+        given: 'a cmNotificationSubscriptionNcmp in event with unique subscription id'
+            def jsonData = TestUtils.getResourceFileContent('cmSubscription/cmNotificationSubscriptionNcmpInEvent.json')
+            def testEventConsumed = jsonObjectMapper.convertJsonString(jsonData, CmNotificationSubscriptionNcmpInEvent.class)
+            def noDeltaPredicates = []
+            mockCmNotificationSubscriptionPersistenceService.isUniqueSubscriptionId("test-id") >> true
+        and: 'the cache handler returns for relevant subscription id'
+            1 * mockDmiCmNotificationSubscriptionCacheHandler.get("test-id") >> testSubscriptionDetailsMap
+        and: 'the delta predicates is returned'
+            1 * mockCmNotificationSubscriptionDelta.getDelta(_) >> noDeltaPredicates
+        when: 'the valid and unique event is consumed'
+            objectUnderTest.processSubscriptionCreateRequest(testEventConsumed)
+        then: 'the subscription cache handler is called once'
+            1 * mockDmiCmNotificationSubscriptionCacheHandler.add('test-id', _)
+        and: 'the subscription details are updated in the cache'
+            1 * mockDmiCmNotificationSubscriptionCacheHandler.updateDmiCmNotificationSubscriptionStatusPerDmi('test-id', _, CmNotificationSubscriptionStatus.ACCEPTED)
+        and: 'we schedule to send the response after configured time from the cache'
+            1 * mockCmNotificationSubscriptionEventsHandler.publishCmNotificationSubscriptionNcmpOutEvent(
+                "test-id", "subscriptionCreateResponse", null, true)
+    }
+
     def 'Consume valid and but non-unique CmNotificationSubscription create message'() {
         given: 'a cmNotificationSubscriptionNcmp in event'
             def jsonData = TestUtils.getResourceFileContent('cmSubscription/cmNotificationSubscriptionNcmpInEvent.json')