aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-06-16 17:52:17 -0400
committerJim Hahn <jrh3@att.com>2020-06-17 14:41:01 -0400
commit5cfff2b468a13e7b5ce068e58e899fcfe36537b3 (patch)
tree95a3f9f64443cb7028afa90632bd412048ed05a0 /main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
parent169dd4b89bb02a4a644b748a07a0294a324715cb (diff)
PAP should discard old PDP messages
Modified PAP to discard any messages old than 10 minutes so that if PAP is unable to communicate with DMaaP and then suddently gets flooded, it will discard old messages. Updates per review comments - made the "max message age" configurable, with a default of 10 minutes Issue-ID: POLICY-2170 Change-Id: I541c03aabf29482af12a07f51eeb5888bbafbf31 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
index cf73a138..674a07fd 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ package org.onap.policy.pap.main.comm;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
-
+import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.base.PfModelException;
@@ -40,6 +40,7 @@ import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.PolicyPapException;
+import org.onap.policy.pap.main.parameters.PdpParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,11 +53,16 @@ import org.slf4j.LoggerFactory;
public class PdpStatusMessageHandler extends PdpMessageGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(PdpStatusMessageHandler.class);
+ private final PdpParameters params;
+
/**
* Constructs the object.
+ *
+ * @param params PDP parameters
*/
- public PdpStatusMessageHandler() {
+ public PdpStatusMessageHandler(PdpParameters params) {
super(true);
+ this.params = params;
}
/**
@@ -65,6 +71,13 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
* @param message the PdpStatus message
*/
public void handlePdpStatus(final PdpStatus message) {
+ long diffms = System.currentTimeMillis() - message.getTimestampMs();
+ if (diffms > params.getMaxMessageAgeMs()) {
+ long diffsec = TimeUnit.SECONDS.convert(diffms, TimeUnit.MILLISECONDS);
+ LOGGER.info("discarding status message from {} age {}s", message.getName(), diffsec);
+ return;
+ }
+
synchronized (updateLock) {
try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
if (message.getPdpSubgroup() == null) {