aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpModifyRequestMap.java77
1 files changed, 41 insertions, 36 deletions
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);
}
/**