summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2021-02-18 14:13:29 +0000
committera.sreekumar <ajith.sreekumar@bell.ca>2021-02-19 15:21:56 +0000
commitde818b6638b3fe537017fd103c0b9997b707dce0 (patch)
tree3bd3da682c03c6bcac15104ab10a39738f29ad1b /main
parentcd8c7690c302973da1811be81a5453aef7469c10 (diff)
Update Pdp policy status during registration or State change
The Pdp Policy Status is not updated during the pdp heartbeat handling/registration flow, or during State change. When a PDP goes down the pdppolicystatus gets cleared. But when the PDP comes back online, PAP deploys the right policies into it, but the deployment status was not getting updated. Similarly, when the State is changed to PASSIVE, the status should be undeployed, and when the state is changed back to ACTIVE, then the status should be deployed for any active policies in any PDP. These issues are fixed here. Updating postman collection. Also updating the csit test to check for 202 instead of 200 for the deployment api response. Change-Id: I1e05f22df23daaa8da8be1376413e995be2376f3 Issue-ID: POLICY-2526 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java38
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java8
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java12
3 files changed, 51 insertions, 7 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
index 79a5e990..fb47e929 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -26,6 +27,7 @@ import java.util.List;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.pap.concepts.PolicyNotification;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
@@ -35,6 +37,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
+import org.onap.policy.pap.main.notification.DeploymentStatus;
+import org.onap.policy.pap.main.notification.PolicyNotifier;
import org.onap.policy.pap.main.parameters.PapParameterGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -90,7 +94,8 @@ public class PdpMessageGenerator {
}
protected PdpUpdate createPdpUpdateMessage(final String pdpGroupName, final PdpSubGroup subGroup,
- final String pdpInstanceId, final PolicyModelsProvider databaseProvider) throws PfModelException {
+ final String pdpInstanceId, final PolicyModelsProvider databaseProvider)
+ throws PfModelException {
final PdpUpdate update = new PdpUpdate();
update.setName(pdpInstanceId);
@@ -127,4 +132,35 @@ public class PdpMessageGenerator {
LOGGER.debug("Created PdpStateChange message - {}", stateChange);
return stateChange;
}
+
+ /**
+ * If group state=ACTIVE AND updateMsg has policiesToDeploy, then make sure deployment status is updated
+ * If group state=PASSIVE, then delete any deployment information for a PDP.
+ *
+ * @param pdpGroupName the group name
+ * @param pdpType the pdp type
+ * @param pdpInstanceId the pdp instance
+ * @param pdpState the new state as per the PDP_STATE_CHANGE change message
+ * @param databaseProvider the database provider
+ * @param policies list of policies as per the PDP_UPDATE message
+ * @throws PfModelException the exception
+ */
+ protected void updateDeploymentStatus(final String pdpGroupName, final String pdpType, final String pdpInstanceId,
+ PdpState pdpState, final PolicyModelsProvider databaseProvider, List<ToscaPolicy> policies)
+ throws PfModelException {
+ DeploymentStatus deploymentStatus = new DeploymentStatus(databaseProvider);
+ deploymentStatus.loadByGroup(pdpGroupName);
+ if (pdpState.equals(PdpState.PASSIVE)) {
+ deploymentStatus.deleteDeployment(pdpInstanceId);
+ } else if (pdpState.equals(PdpState.ACTIVE)) {
+ for (ToscaPolicy toscaPolicy : policies) {
+ deploymentStatus.deploy(pdpInstanceId, toscaPolicy.getIdentifier(), toscaPolicy.getTypeIdentifier(),
+ pdpGroupName, pdpType, true);
+ }
+ }
+ PolicyNotification notification = new PolicyNotification();
+ deploymentStatus.flush(notification);
+ PolicyNotifier notifier = Registry.get(PapConstants.REG_POLICY_NOTIFIER);
+ notifier.publish(notification);
+ }
}
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 d7ee15bd..2e9adda4 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -281,9 +282,12 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
private void sendPdpMessage(final String pdpGroupName, final PdpSubGroup subGroup, final String pdpInstanceId,
final PdpState pdpState, final PolicyModelsProvider databaseProvider) throws PfModelException {
final PdpUpdate pdpUpdatemessage =
- createPdpUpdateMessage(pdpGroupName, subGroup, pdpInstanceId, databaseProvider);
+ createPdpUpdateMessage(pdpGroupName, subGroup, pdpInstanceId, databaseProvider);
final PdpStateChange pdpStateChangeMessage =
- createPdpStateChangeMessage(pdpGroupName, subGroup, pdpInstanceId, pdpState);
+ createPdpStateChangeMessage(pdpGroupName, subGroup, pdpInstanceId, pdpState);
+ updateDeploymentStatus(pdpGroupName, subGroup.getPdpType(), pdpInstanceId, pdpStateChangeMessage.getState(),
+ databaseProvider, pdpUpdatemessage.getPolicies());
+
requestMap.addRequest(pdpUpdatemessage, pdpStateChangeMessage);
LOGGER.debug("Sent PdpUpdate message - {}", pdpUpdatemessage);
LOGGER.debug("Sent PdpStateChange message - {}", pdpStateChangeMessage);
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java
index 0c90ae47..374b5282 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -113,14 +114,17 @@ public class PdpGroupStateChangeProvider extends PdpMessageGenerator {
}
private void sendPdpMessage(final PdpGroup pdpGroup, final PdpState pdpState,
- final PolicyModelsProvider databaseProvider) throws PfModelException {
-
+ final PolicyModelsProvider databaseProvider) throws PfModelException {
+ String pdpGroupName = pdpGroup.getName();
for (final PdpSubGroup subGroup : pdpGroup.getPdpSubgroups()) {
for (final Pdp pdp : subGroup.getPdpInstances()) {
+ String pdpInstanceId = pdp.getInstanceId();
final PdpUpdate pdpUpdatemessage =
- createPdpUpdateMessage(pdpGroup.getName(), subGroup, pdp.getInstanceId(), databaseProvider);
+ createPdpUpdateMessage(pdpGroupName, subGroup, pdpInstanceId, databaseProvider);
final PdpStateChange pdpStateChangeMessage =
- createPdpStateChangeMessage(pdpGroup.getName(), subGroup, pdp.getInstanceId(), pdpState);
+ createPdpStateChangeMessage(pdpGroupName, subGroup, pdpInstanceId, pdpState);
+ updateDeploymentStatus(pdpGroupName, subGroup.getPdpType(), pdpInstanceId,
+ pdpStateChangeMessage.getState(), databaseProvider, pdpUpdatemessage.getPolicies());
requestMap.addRequest(pdpUpdatemessage, pdpStateChangeMessage);
LOGGER.debug("Sent PdpUpdate message - {}", pdpUpdatemessage);
LOGGER.debug("Sent PdpStateChange message - {}", pdpStateChangeMessage);