diff options
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/comm')
4 files changed, 125 insertions, 115 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 15242a92..4e4709e9 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2022 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. @@ -23,10 +23,12 @@ package org.onap.policy.pap.main.comm; import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; 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; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; /** * Listener for PDP Status messages which either represent registration or heart beat. @@ -34,16 +36,16 @@ import org.onap.policy.pap.main.parameters.PdpParameters; * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @AllArgsConstructor +@NoArgsConstructor +@Component public class PdpHeartbeatListener implements TypedMessageListener<PdpStatus> { - private final PdpParameters params; + @Autowired + private PdpStatusMessageHandler pdpStatusMessageHandler; - private final boolean savePdpStatistics; @Override public void onTopicEvent(final CommInfrastructure infra, final String topic, final PdpStatus message) { - - final var handler = new PdpStatusMessageHandler(params, savePdpStatistics); - handler.handlePdpStatus(message); + pdpStatusMessageHandler.handlePdpStatus(message); } } 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 02609535..255b93e0 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,7 +4,7 @@ * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2022 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. @@ -32,16 +32,17 @@ import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.concepts.PdpUpdate; import org.onap.policy.models.pdp.enums.PdpState; -import org.onap.policy.models.provider.PolicyModelsProvider; 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.onap.policy.pap.main.service.PolicyStatusService; +import org.onap.policy.pap.main.service.ToscaServiceTemplateService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.event.EventListener; @@ -66,15 +67,19 @@ public class PdpMessageGenerator { protected PdpModifyRequestMap requestMap; /** - * Factory for PAP DAO. - */ - protected PolicyModelsProviderFactoryWrapper modelProviderWrapper; - - /** * Heart beat interval, in milliseconds, to pass to PDPs, or {@code null}. */ private Long heartBeatMs; + @Autowired + private ToscaServiceTemplateService toscaService; + + @Autowired + private PolicyStatusService policyStatusService; + + @Autowired + private PolicyNotifier policyNotifier; + /** * Constructs the object. * @@ -90,7 +95,6 @@ public class PdpMessageGenerator { */ @EventListener(ApplicationReadyEvent.class) public void initialize() { - modelProviderWrapper = Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class); updateLock = Registry.get(PapConstants.REG_PDP_MODIFY_LOCK, Object.class); requestMap = Registry.get(PapConstants.REG_PDP_MODIFY_MAP, PdpModifyRequestMap.class); @@ -126,16 +130,14 @@ public class PdpMessageGenerator { * Method to return a list of policies. * * @param subGroup PdpSubGroup to retrieve policies from - * @param databaseProvider PolicyModelsProvider used to retrieve list of policies + * @throws PfModelException the exception * @returns a list of ToscaPolicy **/ - public List<ToscaPolicy> getToscaPolicies(final PdpSubGroup subGroup, - final PolicyModelsProvider databaseProvider) - throws PfModelException { + public List<ToscaPolicy> getToscaPolicies(final PdpSubGroup subGroup) throws PfModelException { final List<ToscaPolicy> policies = new LinkedList<>(); for (final ToscaConceptIdentifier policyIdentifier : subGroup.getPolicies()) { - policies.addAll(databaseProvider.getPolicyList(policyIdentifier.getName(), policyIdentifier.getVersion())); + policies.addAll(toscaService.getPolicyList(policyIdentifier.getName(), policyIdentifier.getVersion())); } LOGGER.debug("Created ToscaPolicy list - {}", policies); @@ -164,14 +166,12 @@ public class PdpMessageGenerator { * @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 { - var deploymentStatus = new DeploymentStatus(databaseProvider); + PdpState pdpState, List<ToscaPolicy> policies) { + var deploymentStatus = new DeploymentStatus(policyStatusService); deploymentStatus.loadByGroup(pdpGroupName); if (pdpState.equals(PdpState.PASSIVE)) { deploymentStatus.deleteDeployment(pdpInstanceId); @@ -183,7 +183,6 @@ public class PdpMessageGenerator { } var notification = new PolicyNotification(); deploymentStatus.flush(notification); - PolicyNotifier notifier = Registry.get(PapConstants.REG_POLICY_NOTIFIER); - notifier.publish(notification); + policyNotifier.publish(notification); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java index f231130a..e23026be 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2022 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. @@ -32,7 +32,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import lombok.Setter; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pap.concepts.PolicyNotification; import org.onap.policy.models.pdp.concepts.Pdp; @@ -44,9 +43,7 @@ import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.concepts.PdpUpdate; import org.onap.policy.models.pdp.enums.PdpState; -import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper; import org.onap.policy.pap.main.comm.msgdata.Request; import org.onap.policy.pap.main.comm.msgdata.RequestListener; import org.onap.policy.pap.main.comm.msgdata.StateChangeReq; @@ -55,12 +52,16 @@ import org.onap.policy.pap.main.notification.DeploymentStatus; import org.onap.policy.pap.main.notification.PolicyNotifier; import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams; import org.onap.policy.pap.main.parameters.RequestParams; +import org.onap.policy.pap.main.service.PdpGroupService; +import org.onap.policy.pap.main.service.PolicyStatusService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; /** * Maps a PDP name to requests that modify PDPs. */ +@Component public class PdpModifyRequestMap { private static final Logger logger = LoggerFactory.getLogger(PdpModifyRequestMap.class); @@ -74,17 +75,12 @@ public class PdpModifyRequestMap { /** * PDP modification lock. */ - private final Object modifyLock; + private Object modifyLock; /** * The configuration parameters. */ - private final PdpModifyRequestMapParams params; - - /** - * Factory for PAP DAO. - */ - private final PolicyModelsProviderFactoryWrapper daoFactory; + private PdpModifyRequestMapParams params; /** * Used to notify when policy updates completes. @@ -95,28 +91,46 @@ public class PdpModifyRequestMap { * Used to undeploy policies from the system, when they cannot be deployed to a PDP. * * <p/> - * Note: there's a "catch-22" here. The request map needs an undeployer, but the - * undeployer needs the request map. Consequently, the request map is created first, - * then the undeployer, and finally, this field is set. + * Note: The request map needs an undeployer during creation, and the undeployer + * needs the request map when it's initialize method is called. */ - @Setter - private PolicyUndeployer policyUndeployer; + private final PolicyUndeployer policyUndeployer; + + private final PdpGroupService pdpGroupService; + private final PolicyStatusService policyStatusService; + + private final PdpStatusMessageHandler pdpStatusMessageHandler; /** * Constructs the object. * - * @param params configuration parameters + * @param pdpGroupService the pdpGroupService + * @param policyStatusService the policyStatusService + * @param pdpStatusMessageHandler the pdpStatusMessageHandler + * @param policyUndeployer the policyUndeployer + * @param policyNotifier the policyNotifier + */ + public PdpModifyRequestMap(PdpGroupService pdpGroupService, PolicyStatusService policyStatusService, + PdpStatusMessageHandler pdpStatusMessageHandler, PolicyUndeployer policyUndeployer, + PolicyNotifier policyNotifier) { + this.pdpGroupService = pdpGroupService; + this.policyStatusService = policyStatusService; + this.pdpStatusMessageHandler = pdpStatusMessageHandler; + this.policyUndeployer = policyUndeployer; + this.policyNotifier = policyNotifier; + } + + /** + * Initializes the requestMap. * - * @throws IllegalArgumentException if a required parameter is not set + * @param params the parameters. */ - public PdpModifyRequestMap(PdpModifyRequestMapParams params) { + public void initialize(PdpModifyRequestMapParams params) { params.validate(); this.params = params; this.modifyLock = params.getModifyLock(); - this.daoFactory = params.getDaoFactory(); - this.policyNotifier = params.getPolicyNotifier(); } /** @@ -267,13 +281,13 @@ public class PdpModifyRequestMap { synchronized (modifyLock) { logger.info("check for PDP records older than {}ms", params.getMaxPdpAgeMs()); - try (PolicyModelsProvider dao = daoFactory.create()) { + try { PdpGroupFilter filter = PdpGroupFilter.builder().groupState(PdpState.ACTIVE).build(); - List<PdpGroup> groups = dao.getFilteredPdpGroups(filter); + List<PdpGroup> groups = pdpGroupService.getFilteredPdpGroups(filter); List<PdpGroup> updates = new ArrayList<>(1); - var status = new DeploymentStatus(dao); + var status = new DeploymentStatus(policyStatusService); Instant minAge = Instant.now().minusMillis(params.getMaxPdpAgeMs()); @@ -287,7 +301,7 @@ public class PdpModifyRequestMap { } if (!updates.isEmpty()) { - dao.updatePdpGroups(updates); + pdpGroupService.updatePdpGroups(updates); var notification = new PolicyNotification(); status.flush(notification); @@ -295,7 +309,7 @@ public class PdpModifyRequestMap { policyNotifier.publish(notification); } - } catch (PfModelException | RuntimeException e) { + } catch (RuntimeException e) { logger.warn("failed to remove expired PDPs", e); } } @@ -353,14 +367,6 @@ public class PdpModifyRequestMap { } /** - * Makes a handler for PDP responses. - * @return a response handler - */ - protected PdpStatusMessageHandler makePdpResponseHandler() { - return new PdpStatusMessageHandler(params.getParams(), params.isSavePdpStatistics()); - } - - /** * Listener for singleton request events. */ private class SingletonListener implements RequestListener { @@ -419,8 +425,7 @@ public class PdpModifyRequestMap { * Update PDP time stamps. Also send pdp-update and pdp-state-change, as * necessary, if the response does not reflect what's in the DB. */ - var handler = makePdpResponseHandler(); - handler.handlePdpStatus(response); + pdpStatusMessageHandler.handlePdpStatus(response); } /** 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 fa90266d..070261db 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,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2022 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. @@ -43,13 +43,16 @@ import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.enums.PdpState; -import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.pap.main.PolicyPapException; +import org.onap.policy.pap.main.parameters.PapParameterGroup; import org.onap.policy.pap.main.parameters.PdpParameters; +import org.onap.policy.pap.main.service.PdpGroupService; +import org.onap.policy.pap.main.service.PdpStatisticsService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; /** @@ -57,6 +60,8 @@ import org.slf4j.LoggerFactory; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ + +@Component public class PdpStatusMessageHandler extends PdpMessageGenerator { private static final Logger LOGGER = LoggerFactory.getLogger(PdpStatusMessageHandler.class); @@ -64,6 +69,10 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { private final boolean savePdpStatistics; + private final PdpGroupService pdpGroupService; + + private final PdpStatisticsService pdpStatisticsService; + /** * List to store policies present in db. */ @@ -82,13 +91,17 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { /** * Constructs the object. * - * @param params PDP parameters + * @param parameterGroup the parameterGroup + * @param pdpGroupService the pdpGroupService + * @param pdpStatisticsService the pdpStatisticsService */ - public PdpStatusMessageHandler(PdpParameters params, boolean savePdpStatistics) { + public PdpStatusMessageHandler(PapParameterGroup parameterGroup, PdpGroupService pdpGroupService, + PdpStatisticsService pdpStatisticsService) { super(true); - super.initialize(); - this.params = params; - this.savePdpStatistics = savePdpStatistics; + this.params = parameterGroup.getPdpParameters(); + this.savePdpStatistics = parameterGroup.isSavePdpStatisticsInDb(); + this.pdpGroupService = pdpGroupService; + this.pdpStatisticsService = pdpStatisticsService; } /** @@ -109,11 +122,11 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { } synchronized (updateLock) { - try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) { + try { if (message.getPdpSubgroup() == null) { - handlePdpRegistration(message, databaseProvider); + handlePdpRegistration(message); } else { - handlePdpHeartbeat(message, databaseProvider); + handlePdpHeartbeat(message); } } catch (final PolicyPapException exp) { LOGGER.error("Operation Failed", exp); @@ -159,36 +172,34 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { return false; } - private void handlePdpRegistration(final PdpStatus message, final PolicyModelsProvider databaseProvider) - throws PfModelException, PolicyPapException { - if (!findAndUpdatePdpGroup(message, databaseProvider)) { + private void handlePdpRegistration(final PdpStatus message) throws PfModelException, PolicyPapException { + if (!findAndUpdatePdpGroup(message)) { final var errorMessage = "Failed to register PDP. No matching PdpGroup/SubGroup Found - "; LOGGER.debug("{}{}", errorMessage, message); throw new PolicyPapException(errorMessage + message); } } - private boolean findAndUpdatePdpGroup(final PdpStatus message, final PolicyModelsProvider databaseProvider) + private boolean findAndUpdatePdpGroup(final PdpStatus message) throws PfModelException { var pdpGroupFound = false; final PdpGroupFilter filter = PdpGroupFilter.builder().name(message.getPdpGroup()).groupState(PdpState.ACTIVE).build(); - final List<PdpGroup> pdpGroups = databaseProvider.getFilteredPdpGroups(filter); + final List<PdpGroup> pdpGroups = pdpGroupService.getFilteredPdpGroups(filter); if (!pdpGroups.isEmpty()) { - pdpGroupFound = registerPdp(message, databaseProvider, pdpGroups.get(0)); + pdpGroupFound = registerPdp(message, pdpGroups.get(0)); } return pdpGroupFound; } - private boolean registerPdp(final PdpStatus message, final PolicyModelsProvider databaseProvider, - final PdpGroup finalizedPdpGroup) throws PfModelException { + private boolean registerPdp(final PdpStatus message, final PdpGroup finalizedPdpGroup) throws PfModelException { Optional<PdpSubGroup> subGroup; var pdpGroupFound = false; subGroup = findPdpSubGroup(message, finalizedPdpGroup); if (subGroup.isPresent()) { - policies = getToscaPolicies(subGroup.get(), databaseProvider); + policies = getToscaPolicies(subGroup.get()); policiesToBeDeployed = policies.stream().collect(Collectors .toMap(ToscaPolicy::getIdentifier, policy -> policy)); policiesToBeUndeployed = null; @@ -196,18 +207,17 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { LOGGER.debug("Found pdpGroup - {}, going for registration of PDP - {}", finalizedPdpGroup, message); Optional<Pdp> pdp = findPdpInstance(message, subGroup.get()); if (pdp.isPresent()) { - updatePdpHealthStatus(message, subGroup.get(), pdp.get(), finalizedPdpGroup, databaseProvider); + updatePdpHealthStatus(message, subGroup.get(), pdp.get(), finalizedPdpGroup); } else { - updatePdpSubGroup(finalizedPdpGroup, subGroup.get(), message, databaseProvider); + updatePdpSubGroup(finalizedPdpGroup, subGroup.get(), message); } - sendPdpMessage(finalizedPdpGroup.getName(), subGroup.get(), message.getName(), null, databaseProvider); + sendPdpMessage(finalizedPdpGroup.getName(), subGroup.get(), message.getName(), null); pdpGroupFound = true; } return pdpGroupFound; } - private void updatePdpSubGroup(final PdpGroup pdpGroup, final PdpSubGroup pdpSubGroup, final PdpStatus message, - final PolicyModelsProvider databaseProvider) throws PfModelException { + private void updatePdpSubGroup(final PdpGroup pdpGroup, final PdpSubGroup pdpSubGroup, final PdpStatus message) { final var pdpInstance = new Pdp(); pdpInstance.setInstanceId(message.getName()); @@ -219,27 +229,26 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { pdpSubGroup.setCurrentInstanceCount(pdpSubGroup.getCurrentInstanceCount() + 1); - databaseProvider.updatePdpSubGroup(pdpGroup.getName(), pdpSubGroup); + pdpGroupService.updatePdpSubGroup(pdpGroup.getName(), pdpSubGroup); LOGGER.debug("Updated PdpSubGroup in DB - {} belonging to PdpGroup - {}", pdpSubGroup, pdpGroup.getName()); } - private void handlePdpHeartbeat(final PdpStatus message, final PolicyModelsProvider databaseProvider) - throws PfModelException { + private void handlePdpHeartbeat(final PdpStatus message) throws PfModelException { final PdpGroupFilter filter = PdpGroupFilter.builder().name(message.getPdpGroup()).groupState(PdpState.ACTIVE).build(); - final List<PdpGroup> pdpGroups = databaseProvider.getFilteredPdpGroups(filter); + final List<PdpGroup> pdpGroups = pdpGroupService.getFilteredPdpGroups(filter); if (!pdpGroups.isEmpty()) { var pdpGroup = pdpGroups.get(0); Optional<PdpSubGroup> pdpSubgroup = findPdpSubGroup(message, pdpGroup); if (pdpSubgroup.isPresent()) { Optional<Pdp> pdpInstance = findPdpInstance(message, pdpSubgroup.get()); if (pdpInstance.isPresent()) { - processPdpDetails(message, pdpSubgroup.get(), pdpInstance.get(), pdpGroup, databaseProvider); + processPdpDetails(message, pdpSubgroup.get(), pdpInstance.get(), pdpGroup); } else { LOGGER.debug("PdpInstance not Found in DB. Sending Pdp for registration - {}", message); - registerPdp(message, databaseProvider, pdpGroup); + registerPdp(message, pdpGroup); } } } @@ -268,10 +277,9 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { } private void processPdpDetails(final PdpStatus message, final PdpSubGroup pdpSubGroup, final Pdp pdpInstance, - final PdpGroup pdpGroup, final PolicyModelsProvider databaseProvider) - throws PfModelException { + final PdpGroup pdpGroup) throws PfModelException { // all policies - policies = getToscaPolicies(pdpSubGroup, databaseProvider); + policies = getToscaPolicies(pdpSubGroup); Map<ToscaConceptIdentifier, ToscaPolicy> policyMap = policies.stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy)); @@ -285,13 +293,13 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { policiesToBeDeployed.keySet().removeAll(message.getPolicies()); if (PdpState.TERMINATED.equals(message.getState())) { - processPdpTermination(pdpSubGroup, pdpInstance, pdpGroup, databaseProvider); + processPdpTermination(pdpSubGroup, pdpInstance, pdpGroup); } else if (validatePdpDetails(message, pdpGroup, pdpSubGroup, pdpInstance)) { LOGGER.debug("PdpInstance details are correct. Saving current state in DB - {}", pdpInstance); - updatePdpHealthStatus(message, pdpSubGroup, pdpInstance, pdpGroup, databaseProvider); + updatePdpHealthStatus(message, pdpSubGroup, pdpInstance, pdpGroup); if (savePdpStatistics) { - processPdpStatistics(message, pdpSubGroup, pdpInstance, pdpGroup, databaseProvider); + processPdpStatistics(message, pdpSubGroup, pdpInstance, pdpGroup); } else { LOGGER.debug("Not processing PdpStatistics - {}", message.getStatistics()); } @@ -299,28 +307,26 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { LOGGER.debug("PdpInstance details are not correct. Sending PdpUpdate message - {}", pdpInstance); LOGGER.debug("Policy list in DB - {}. Policy list in heartbeat - {}", pdpSubGroup.getPolicies(), message.getPolicies()); - updatePdpHealthStatus(message, pdpSubGroup, pdpInstance, pdpGroup, databaseProvider); - sendPdpMessage(pdpGroup.getName(), pdpSubGroup, pdpInstance.getInstanceId(), pdpInstance.getPdpState(), - databaseProvider); + updatePdpHealthStatus(message, pdpSubGroup, pdpInstance, pdpGroup); + sendPdpMessage(pdpGroup.getName(), pdpSubGroup, pdpInstance.getInstanceId(), pdpInstance.getPdpState()); } } private void processPdpStatistics(final PdpStatus message, final PdpSubGroup pdpSubGroup, final Pdp pdpInstance, - final PdpGroup pdpGroup, final PolicyModelsProvider databaseProvider) throws PfModelException { + final PdpGroup pdpGroup) { if (validatePdpStatisticsDetails(message, pdpInstance, pdpGroup, pdpSubGroup)) { LOGGER.debug("PdpStatistics details are correct. Saving current statistics in DB - {}", message.getStatistics()); - createPdpStatistics(message.getStatistics(), databaseProvider); + createPdpStatistics(message.getStatistics()); } else { LOGGER.debug("PdpStatistics details are not correct - {}", message.getStatistics()); } } - private void processPdpTermination(final PdpSubGroup pdpSubGroup, final Pdp pdpInstance, final PdpGroup pdpGroup, - final PolicyModelsProvider databaseProvider) throws PfModelException { + private void processPdpTermination(final PdpSubGroup pdpSubGroup, final Pdp pdpInstance, final PdpGroup pdpGroup) { pdpSubGroup.getPdpInstances().remove(pdpInstance); pdpSubGroup.setCurrentInstanceCount(pdpSubGroup.getCurrentInstanceCount() - 1); - databaseProvider.updatePdpSubGroup(pdpGroup.getName(), pdpSubGroup); + pdpGroupService.updatePdpSubGroup(pdpGroup.getName(), pdpSubGroup); LOGGER.debug("Deleted PdpInstance - {} belonging to PdpSubGroup - {} and PdpGroup - {}", pdpInstance, pdpSubGroup, pdpGroup); @@ -363,24 +369,22 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { } private void updatePdpHealthStatus(final PdpStatus message, final PdpSubGroup pdpSubgroup, final Pdp pdpInstance, - final PdpGroup pdpGroup, final PolicyModelsProvider databaseProvider) throws PfModelException { + final PdpGroup pdpGroup) { pdpInstance.setHealthy(message.getHealthy()); pdpInstance.setMessage(message.getDescription()); pdpInstance.setLastUpdate(Instant.now()); - databaseProvider.updatePdp(pdpGroup.getName(), pdpSubgroup.getPdpType(), pdpInstance); + pdpGroupService.updatePdp(pdpGroup.getName(), pdpSubgroup.getPdpType(), pdpInstance); LOGGER.debug("Updated Pdp in DB - {}", pdpInstance); } - private void createPdpStatistics(final PdpStatistics pdpStatistics, final PolicyModelsProvider databaseProvider) - throws PfModelException { - databaseProvider.createPdpStatistics(Arrays.asList(pdpStatistics)); + private void createPdpStatistics(final PdpStatistics pdpStatistics) { + pdpStatisticsService.createPdpStatistics(Arrays.asList(pdpStatistics)); LOGGER.debug("Created PdpStatistics in DB - {}", pdpStatistics); } private void sendPdpMessage(final String pdpGroupName, final PdpSubGroup subGroup, final String pdpInstanceId, - final PdpState pdpState, final PolicyModelsProvider databaseProvider) - throws PfModelException { + final PdpState pdpState) { final List<ToscaPolicy> polsToBeDeployed = new LinkedList<>(policiesToBeDeployed.values()); final var pdpUpdatemessage = createPdpUpdateMessage(pdpGroupName, subGroup, pdpInstanceId, @@ -388,7 +392,7 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { final var pdpStateChangeMessage = createPdpStateChangeMessage(pdpGroupName, subGroup, pdpInstanceId, pdpState); updateDeploymentStatus(pdpGroupName, subGroup.getPdpType(), pdpInstanceId, pdpStateChangeMessage.getState(), - databaseProvider, pdpUpdatemessage.getPoliciesToBeDeployed()); + pdpUpdatemessage.getPoliciesToBeDeployed()); requestMap.addRequest(pdpUpdatemessage, pdpStateChangeMessage); LOGGER.debug("Sent PdpUpdate message - {}", pdpUpdatemessage); |