summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-05-04 20:13:11 -0400
committerJim Hahn <jrh3@att.com>2020-05-04 20:19:11 -0400
commit26df07d10d9b0a7e6e9e9ab2d9cc14ed735c0d1d (patch)
treead4887722c794b6e8b5b8b87ac894aaf60107803 /main
parented81ba9cc8e54c3c2d8c70972a6307a1b5bbe86a (diff)
Eliminate spurious notifications from PAP
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
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java10
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java14
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/notification/PolicyCommonTrackerTest.java24
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java17
4 files changed, 14 insertions, 51 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java
index 67d9b988..5f702daf 100644
--- a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java
+++ b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java
@@ -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);
});
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java
index c24cafca..430a09b9 100644
--- a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java
+++ b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java
@@ -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);
}
/**
diff --git a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyCommonTrackerTest.java b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyCommonTrackerTest.java
index e8c03d1d..fc43c7a9 100644
--- a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyCommonTrackerTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyCommonTrackerTest.java
@@ -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));
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java
index 478c63c9..1305f27e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyNotifierTest.java
@@ -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