diff options
4 files changed, 180 insertions, 18 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); diff --git a/postman/pap-api-collection.json b/postman/pap-api-collection.json index 34112b73..44ad24d6 100644 --- a/postman/pap-api-collection.json +++ b/postman/pap-api-collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "05831254-6fad-419f-b10e-ff21cbbd365a", + "_postman_id": "d78b72f0-00b1-44c2-88c4-98a7a51b3932", "name": "Policy Framework Administration API", "description": "This collection lists all the Administration API's supported by ONAP Policy Framework. These API's are used to perform administrative operations for managing policies, groups, statistics & health information for all registered PDP engines.", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" @@ -350,7 +350,7 @@ "response": [] }, { - "name": "Fetch Policy deployment Status", + "name": "Fetch All Policy Status", "protocolProfileBehavior": { "disableBodyPruning": true }, @@ -373,7 +373,7 @@ "raw": "" }, "url": { - "raw": "{{POLICY-PAP-URL}}/policy/pap/v1/policies/deployed/operational.modifyconfig", + "raw": "{{POLICY-PAP-URL}}/policy/pap/v1/policies/status", "host": [ "{{POLICY-PAP-URL}}" ], @@ -382,11 +382,93 @@ "pap", "v1", "policies", - "deployed", + "status" + ] + }, + "description": "This is a generic API to fetch status of all policies in the registered PDP instances." + }, + "response": [] + }, + { + "name": "Fetch All Policy Status in a Group", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "Accept", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{POLICY-PAP-URL}}/policy/pap/v1/policies/status/defaultGroup", + "host": [ + "{{POLICY-PAP-URL}}" + ], + "path": [ + "policy", + "pap", + "v1", + "policies", + "status", + "defaultGroup" + ] + }, + "description": "This is a generic API to fetch status of all policies in the registered PDP instances in a PDP Group." + }, + "response": [] + }, + { + "name": "Fetch Policy Status in a Group", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "Accept", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{POLICY-PAP-URL}}/policy/pap/v1/policies/status/defaultGroup/operational.modifyconfig", + "host": [ + "{{POLICY-PAP-URL}}" + ], + "path": [ + "policy", + "pap", + "v1", + "policies", + "status", + "defaultGroup", "operational.modifyconfig" ] }, - "description": "This is an API to fetch status of a specific deployed policy in the registered PDP instances." + "description": "This is a generic API to fetch status of all versions of a policy in the registered PDP instances in a PDP Group." }, "response": [] }, @@ -431,6 +513,47 @@ "response": [] }, { + "name": "Fetch Policy deployment Status", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "type": "text", + "value": "application/json" + }, + { + "key": "Accept", + "type": "text", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{POLICY-PAP-URL}}/policy/pap/v1/policies/deployed/operational.modifyconfig", + "host": [ + "{{POLICY-PAP-URL}}" + ], + "path": [ + "policy", + "pap", + "v1", + "policies", + "deployed", + "operational.modifyconfig" + ] + }, + "description": "This is an API to fetch status of a specific deployed policy in the registered PDP instances." + }, + "response": [] + }, + { "name": "Fetch All PDPs Statistics", "protocolProfileBehavior": { "disableBodyPruning": true @@ -650,7 +773,6 @@ { "listen": "prerequest", "script": { - "id": "d6987a6d-a224-4288-a7bd-4c1c209a2637", "type": "text/javascript", "exec": [ "" @@ -660,7 +782,6 @@ { "listen": "test", "script": { - "id": "731a9aab-e8f2-4dc6-941c-ac7e142c5177", "type": "text/javascript", "exec": [ "" @@ -670,17 +791,14 @@ ], "variable": [ { - "id": "bc82ca5c-f667-4118-9da1-e78a9b532b91", "key": "USER", "value": "healthcheck", "type": "string" }, { - "id": "1c2733ff-2507-49e8-ba07-b0f85ea97914", "key": "PASSWORD", "value": "zb!XztG34", "type": "string" } - ], - "protocolProfileBehavior": {} + ] }
\ No newline at end of file |