aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-06-23 10:11:14 -0400
committerJim Hahn <jrh3@att.com>2021-06-23 18:01:24 -0400
commitbcb522a96d60e6b50383645f870100a72ee11db7 (patch)
treecdf2ee03fb5f784d9640f9fb1b2bcf5213906ac4 /main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
parent00e9e19f5ac50cb5ce4cd09a9c403797a6e8f2b3 (diff)
Remove expired PDPs
Added code to remove PDPs for which no message has been received for a while. Added a max-age field to the request-map parameters, changing the parameters class to use a Builder, in the process. Deleted the PdpTracker class, as its functionality was replaced by the expiration checker. Changed port numbers in some tests, due to collisions in junit tests. Issue-ID: POLICY-3407 Change-Id: Ifbfbc03b833a4f11ee5e910e256ee42e21a0afab Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java53
1 files changed, 26 insertions, 27 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
index 5c942341..78a301f6 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
@@ -22,6 +22,9 @@
package org.onap.policy.pap.main.startstop;
import java.util.Arrays;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
@@ -41,7 +44,6 @@ import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
import org.onap.policy.pap.main.PolicyPapRuntimeException;
import org.onap.policy.pap.main.comm.PdpHeartbeatListener;
import org.onap.policy.pap.main.comm.PdpModifyRequestMap;
-import org.onap.policy.pap.main.comm.PdpTracker;
import org.onap.policy.pap.main.comm.Publisher;
import org.onap.policy.pap.main.comm.TimerManager;
import org.onap.policy.pap.main.notification.PolicyNotifier;
@@ -124,7 +126,7 @@ public class PapActivator extends ServiceManagerContainer {
final AtomicReference<Publisher<PolicyNotification>> notifyPub = new AtomicReference<>();
final AtomicReference<TimerManager> pdpUpdTimers = new AtomicReference<>();
final AtomicReference<TimerManager> pdpStChgTimers = new AtomicReference<>();
- final AtomicReference<TimerManager> heartBeatTimers = new AtomicReference<>();
+ final AtomicReference<ScheduledExecutorService> pdpExpirationTimer = new AtomicReference<>();
final AtomicReference<PolicyModelsProviderFactoryWrapper> daoFactory = new AtomicReference<>();
final AtomicReference<PdpModifyRequestMap> requestMap = new AtomicReference<>();
final AtomicReference<RestServer> restServer = new AtomicReference<>();
@@ -183,14 +185,6 @@ public class PapActivator extends ServiceManagerContainer {
() -> Registry.register(PapConstants.REG_POLICY_NOTIFIER, notifier.get()),
() -> Registry.unregister(PapConstants.REG_POLICY_NOTIFIER));
- addAction("PDP heart beat timers",
- () -> {
- long maxWaitHeartBeatMs = MAX_MISSED_HEARTBEATS * pdpParams.getHeartBeatMs();
- heartBeatTimers.set(new TimerManager("heart beat", maxWaitHeartBeatMs));
- startThread(heartBeatTimers.get());
- },
- () -> heartBeatTimers.get().stop());
-
addAction("PDP update timers",
() -> {
pdpUpdTimers.set(new TimerManager("update", pdpParams.getUpdateParameters().getMaxWaitMs()));
@@ -212,15 +206,17 @@ public class PapActivator extends ServiceManagerContainer {
addAction("PDP modification requests",
() -> {
requestMap.set(new PdpModifyRequestMap(
- new PdpModifyRequestMapParams()
- .setDaoFactory(daoFactory.get())
- .setModifyLock(pdpUpdateLock)
- .setParams(pdpParams)
- .setPolicyNotifier(notifier.get())
- .setPdpPublisher(pdpPub.get())
- .setResponseDispatcher(reqIdDispatcher)
- .setStateChangeTimers(pdpStChgTimers.get())
- .setUpdateTimers(pdpUpdTimers.get())));
+ PdpModifyRequestMapParams.builder()
+ .maxPdpAgeMs(MAX_MISSED_HEARTBEATS * pdpParams.getHeartBeatMs())
+ .daoFactory(daoFactory.get())
+ .modifyLock(pdpUpdateLock)
+ .params(pdpParams)
+ .policyNotifier(notifier.get())
+ .pdpPublisher(pdpPub.get())
+ .responseDispatcher(reqIdDispatcher)
+ .stateChangeTimers(pdpStChgTimers.get())
+ .updateTimers(pdpUpdTimers.get())
+ .build()));
Registry.register(PapConstants.REG_PDP_MODIFY_MAP, requestMap.get());
// now that it's registered, we can attach a "policy undeploy" provider
@@ -228,14 +224,17 @@ public class PapActivator extends ServiceManagerContainer {
},
() -> Registry.unregister(PapConstants.REG_PDP_MODIFY_MAP));
- addAction("PDP heart beat tracker",
- () -> Registry.register(PapConstants.REG_PDP_TRACKER, PdpTracker.builder()
- .daoFactory(daoFactory.get())
- .timers(heartBeatTimers.get())
- .modifyLock(pdpUpdateLock)
- .requestMap(requestMap.get())
- .build()),
- () -> Registry.unregister(PapConstants.REG_PDP_TRACKER));
+ addAction("PDP expiration timer",
+ () -> {
+ long frequencyMs = pdpParams.getHeartBeatMs();
+ pdpExpirationTimer.set(Executors.newScheduledThreadPool(1));
+ pdpExpirationTimer.get().scheduleWithFixedDelay(
+ requestMap.get()::removeExpiredPdps,
+ frequencyMs,
+ frequencyMs,
+ TimeUnit.MILLISECONDS);
+ },
+ () -> pdpExpirationTimer.get().shutdownNow());
addAction("PAP client executor",
() ->