Eliminate spurious notifications from PAP 78/107078/3
authorJim Hahn <jrh3@att.com>
Tue, 5 May 2020 00:13:11 +0000 (20:13 -0400)
committerJim Hahn <jrh3@att.com>
Tue, 5 May 2020 00:19:11 +0000 (20:19 -0400)
Tracked it down to the following sequence:
- policies were deployed to the pdp
- received a request to undeploy a policy
- generated a notification for the formerly deployed policy
  - this should not have been generated
- undeployed the policy
- received a response from the pdp indicating the policy had
  been undeployed
- generated a notification indicating the policy was undeployed

Removed the code that generated a notification when a policy is
initially moved from deployed to undeployed (or vice versa).

Issue-ID: POLICY-2539
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: If175974b5fa5ccda6a1e1ab8fa1326b263bb8005

main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java
main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java
main/src/test/java/org/onap/policy/pap/main/notification/PolicyCommonTrackerTest.java
main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java

index 67d9b98..5f702da 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -104,10 +104,8 @@ public abstract class PolicyCommonTracker {
      * Removes a set of PDPs from all policies within the tracker.
      *
      * @param notifyData data identifying the policy and the PDPs to be removed from it
-     * @param statusList status messages are added here if policies become complete as a
-     *        result of this operation
      */
-    public void removeData(PolicyPdpNotificationData notifyData, List<PolicyStatus> statusList) {
+    public void removeData(PolicyPdpNotificationData notifyData) {
 
         policy2data.computeIfPresent(notifyData.getPolicyId(), (policyId, data) -> {
 
@@ -116,9 +114,7 @@ public abstract class PolicyCommonTracker {
                 return data;
             }
 
-            // this policy is complete - notify
-            statusList.add(makeStatus(policyId, data));
-
+            // this policy is complete
             return (shouldRemove(data) ? null : data);
         });
     }
index c24cafc..430a09b 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -181,12 +181,8 @@ public class PolicyNotifier {
      * @param data data to be added
      */
     public synchronized void addDeploymentData(PolicyPdpNotificationData data) {
-        PolicyNotification notification = new PolicyNotification();
-
-        undeployTracker.removeData(data, notification.getDeleted());
+        undeployTracker.removeData(data);
         deployTracker.addData(data);
-
-        publish(notification);
     }
 
     /**
@@ -196,12 +192,8 @@ public class PolicyNotifier {
      * @param data data to be added
      */
     public synchronized void addUndeploymentData(PolicyPdpNotificationData data) {
-        PolicyNotification notification = new PolicyNotification();
-
-        deployTracker.removeData(data, notification.getAdded());
+        deployTracker.removeData(data);
         undeployTracker.addData(data);
-
-        publish(notification);
     }
 
     /**
index e8c03d1..fc43c7a 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -141,9 +141,7 @@ public class PolicyCommonTrackerTest extends PolicyCommonSupport {
         tracker.addData(makeData(policy2, PDP1, PDP3));
 
         // remove a policy that isn't in the map
-        List<PolicyStatus> statusList = new ArrayList<>();
-        tracker.removeData(makeData(policy3, PDP1), statusList);
-        assertTrue(statusList.isEmpty());
+        tracker.removeData(makeData(policy3, PDP1));
         assertEquals(2, map.size());
     }
 
@@ -155,10 +153,8 @@ public class PolicyCommonTrackerTest extends PolicyCommonSupport {
         tracker.addData(makeData(policy1, PDP1, PDP2));
         tracker.addData(makeData(policy2, PDP1, PDP3));
 
-        // remove some PDPs from a policy - no notifications and no changes to the map
-        List<PolicyStatus> statusList = new ArrayList<>();
-        tracker.removeData(makeData(policy2, PDP1), statusList);
-        assertTrue(statusList.isEmpty());
+        // remove some PDPs from a policy - no changes to the map
+        tracker.removeData(makeData(policy2, PDP1));
         assertTrue(map.containsKey(policy1));
         assertTrue(map.containsKey(policy2));
     }
@@ -180,11 +176,7 @@ public class PolicyCommonTrackerTest extends PolicyCommonSupport {
         tracker.addData(makeData(policy2, PDP1, PDP3));
 
         // remove all the PDPs from one policy, but do NOT remove the policy
-        List<PolicyStatus> statusList = new ArrayList<>();
-        tracker.removeData(makeData(policy2, PDP1, PDP3), statusList);
-        assertEquals(1, statusList.size());
-        assertEquals(policy2, statusList.get(0).getPolicy());
-        assertEquals(type, statusList.get(0).getPolicyType());
+        tracker.removeData(makeData(policy2, PDP1, PDP3));
         assertTrue(map.containsKey(policy1));
         assertTrue(map.containsKey(policy2));
     }
@@ -198,11 +190,7 @@ public class PolicyCommonTrackerTest extends PolicyCommonSupport {
         tracker.addData(makeData(policy2, PDP1, PDP3));
 
         // remove all the PDPs from one policy, and remove the policy
-        List<PolicyStatus> statusList = new ArrayList<>();
-        tracker.removeData(makeData(policy1, PDP1, PDP2, PDP3), statusList);
-        assertEquals(1, statusList.size());
-        assertEquals(policy1, statusList.get(0).getPolicy());
-        assertEquals(type, statusList.get(0).getPolicyType());
+        tracker.removeData(makeData(policy1, PDP1, PDP2, PDP3));
         assertFalse(map.containsKey(policy1));
         assertTrue(map.containsKey(policy2));
     }
index 478c63c..1305f27 100644 (file)
@@ -22,7 +22,6 @@ package org.onap.policy.pap.main.notification;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doAnswer;
@@ -223,32 +222,20 @@ public class PolicyNotifierTest extends PolicyCommonSupport {
 
     @Test
     public void testAddDeploymentData() {
-        doAnswer(addStatus(1, status1, status2)).when(undeploy).removeData(any(), any());
-
         PolicyPdpNotificationData data = makeData(policy1, PDP1, PDP2);
         notifier.addDeploymentData(data);
 
         verify(deploy).addData(data);
-        verify(undeploy).removeData(eq(data), any());
-
-        PolicyNotification notification = getNotification();
-        assertEquals(Arrays.asList(status1, status2), notification.getDeleted());
-        assertTrue(notification.getAdded().isEmpty());
+        verify(undeploy).removeData(eq(data));
     }
 
     @Test
     public void testAddUndeploymentData() {
-        doAnswer(addStatus(1, status1, status2)).when(deploy).removeData(any(), any());
-
         PolicyPdpNotificationData data = makeData(policy1, PDP1, PDP2);
         notifier.addUndeploymentData(data);
 
         verify(undeploy).addData(data);
-        verify(deploy).removeData(eq(data), any());
-
-        PolicyNotification notification = getNotification();
-        assertEquals(Arrays.asList(status1, status2), notification.getAdded());
-        assertTrue(notification.getDeleted().isEmpty());
+        verify(deploy).removeData(eq(data));
     }
 
     @Test