diff options
author | 2019-06-11 10:56:25 -0400 | |
---|---|---|
committer | 2019-06-11 17:23:35 -0400 | |
commit | a240d7a4020d0346040fe4d86682a6ab8fcd757a (patch) | |
tree | 31b2fa3a76c38f00a0ab5a45fca5a4d17508e45f /main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java | |
parent | fde702471743115e7492951873dd48ba3dbc66bb (diff) |
Add PDP heart beat expiration timer
Added heart beat interval to the PDP-UPDATE message sent in response
to a heart beat message received from a PDP.
Added timers to detect missing heart beats and remove the PDP from
the DB - PdpTracker.
Modified current heart beat listener to update PdpTracker when a
heart beat is received.
Allow 3 missed heart beats instead of 2.
Change-Id: I81621fefbe494e0c4d6f0b9767b00b2a9dd398d8
Issue-ID: POLICY-1795
Signed-off-by: jrh3 <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.java | 46 |
1 files changed, 34 insertions, 12 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 1b7281ca..e1ad80e2 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 @@ -24,7 +24,6 @@ package org.onap.policy.pap.main.startstop; import java.util.Arrays; import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; - import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher; @@ -39,6 +38,7 @@ 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.parameters.PapParameterGroup; @@ -57,12 +57,12 @@ public class PapActivator extends ServiceManagerContainer { private static final String[] MSG_TYPE_NAMES = { "messageName" }; private static final String[] REQ_ID_NAMES = { "response", "responseTo" }; - private final PapParameterGroup papParameterGroup; - /** - * The PAP REST API server. + * Max number of heat beats that can be missed before PAP removes a PDP. */ - private PapRestServer restServer; + private static final int MAX_MISSED_HEARTBEATS = 3; + + private final PapParameterGroup papParameterGroup; /** * Listens for messages on the topic, decodes them into a {@link PdpStatus} message, and then dispatches them to @@ -110,7 +110,10 @@ public class PapActivator extends ServiceManagerContainer { final AtomicReference<Publisher> pdpPub = new AtomicReference<>(); final AtomicReference<TimerManager> pdpUpdTimers = new AtomicReference<>(); final AtomicReference<TimerManager> pdpStChgTimers = new AtomicReference<>(); + final AtomicReference<TimerManager> heartBeatTimers = new AtomicReference<>(); final AtomicReference<PolicyModelsProviderFactoryWrapper> daoFactory = new AtomicReference<>(); + final AtomicReference<PdpModifyRequestMap> requestMap = new AtomicReference<>(); + final AtomicReference<PapRestServer> restServer = new AtomicReference<>(); // @formatter:off addAction("PAP parameters", @@ -153,6 +156,14 @@ public class PapActivator extends ServiceManagerContainer { }, () -> pdpPub.get().stop()); + 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())); @@ -172,7 +183,8 @@ public class PapActivator extends ServiceManagerContainer { () -> Registry.unregister(PapConstants.REG_PDP_MODIFY_LOCK)); addAction("PDP modification requests", - () -> Registry.register(PapConstants.REG_PDP_MODIFY_MAP, new PdpModifyRequestMap( + () -> { + requestMap.set(new PdpModifyRequestMap( new PdpModifyRequestMapParams() .setDaoFactory(daoFactory.get()) .setModifyLock(pdpUpdateLock) @@ -180,16 +192,26 @@ public class PapActivator extends ServiceManagerContainer { .setPublisher(pdpPub.get()) .setResponseDispatcher(reqIdDispatcher) .setStateChangeTimers(pdpStChgTimers.get()) - .setUpdateTimers(pdpUpdTimers.get()))), + .setUpdateTimers(pdpUpdTimers.get()))); + Registry.register(PapConstants.REG_PDP_MODIFY_MAP, requestMap.get()); + }, () -> Registry.unregister(PapConstants.REG_PDP_MODIFY_MAP)); - addAction("Create REST server", - () -> restServer = new PapRestServer(papParameterGroup.getRestServerParameters()), - () -> restServer = null); + 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("REST server", - () -> restServer.start(), - () -> restServer.stop()); + () -> { + restServer.set(new PapRestServer(papParameterGroup.getRestServerParameters())); + restServer.get().start(); + }, + () -> restServer.get().stop()); // @formatter:on } |