aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java15
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java19
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/parameters/PdpParameters.java13
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java4
4 files changed, 44 insertions, 7 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java
index fc61c1ab..512609a4 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpHeartbeatListener.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -23,6 +24,7 @@ package org.onap.policy.pap.main.comm;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.listeners.TypedMessageListener;
import org.onap.policy.models.pdp.concepts.PdpStatus;
+import org.onap.policy.pap.main.parameters.PdpParameters;
/**
* Listener for PDP Status messages which either represent registration or heart beat.
@@ -31,10 +33,21 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
*/
public class PdpHeartbeatListener implements TypedMessageListener<PdpStatus> {
+ private final PdpParameters params;
+
+ /**
+ * Constructs the object.
+ *
+ * @param params PDP parameters
+ */
+ public PdpHeartbeatListener(PdpParameters params) {
+ this.params = params;
+ }
+
@Override
public void onTopicEvent(final CommInfrastructure infra, final String topic, final PdpStatus message) {
- final PdpStatusMessageHandler handler = new PdpStatusMessageHandler();
+ final PdpStatusMessageHandler handler = new PdpStatusMessageHandler(params);
handler.handlePdpStatus(message);
}
}
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) {
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PdpParameters.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PdpParameters.java
index 1776772a..72b11d76 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/PdpParameters.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PdpParameters.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.
@@ -20,6 +20,7 @@
package org.onap.policy.pap.main.parameters;
+import java.util.concurrent.TimeUnit;
import lombok.Getter;
import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.annotations.Min;
@@ -34,9 +35,19 @@ import org.onap.policy.common.parameters.annotations.NotNull;
@Getter
public class PdpParameters extends ParameterGroupImpl {
+ /**
+ * Default maximum message age, in milliseconds, that should be examined. Any message
+ * older than this is discarded.
+ */
+ public static final long DEFAULT_MAX_AGE_MS = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);
+
+
@Min(1)
private long heartBeatMs;
+ @Min(1)
+ private long maxMessageAgeMs = DEFAULT_MAX_AGE_MS;
+
private PdpUpdateParameters updateParameters;
private PdpStateChangeParameters stateChangeParameters;
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 83b9151c..fd13c232 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 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.
@@ -109,7 +109,7 @@ public class PapActivator extends ServiceManagerContainer {
this.papParameterGroup = papParameterGroup;
this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
this.reqIdDispatcher = new RequestIdDispatcher<>(PdpStatus.class, REQ_ID_NAMES);
- this.pdpHeartbeatListener = new PdpHeartbeatListener();
+ this.pdpHeartbeatListener = new PdpHeartbeatListener(papParameterGroup.getPdpParameters());
} catch (final RuntimeException e) {
throw new PolicyPapRuntimeException(e);