summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-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);