import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter.ToscaPolicyFilterBuilder;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.pap.main.notification.PolicyPdpNotificationData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
private final Map<ToscaPolicyTypeIdentifier, ToscaPolicyType> typeCache = new HashMap<>();
+ /**
+ * Policies to be deployed. This is just used to build up the data, which is then
+ * passed to the notifier once the update is "committed".
+ */
+ private final Map<ToscaPolicyIdentifier, PolicyPdpNotificationData> deploy = new HashMap<>();
+
+ /**
+ * Policies to be undeployed. This is just used to build up the data, which is then
+ * passed to the notifier once the update is "committed".
+ */
+ private final Map<ToscaPolicyIdentifier, PolicyPdpNotificationData> undeploy = new HashMap<>();
+
/**
* Constructs the object.
logger.info("deleting DB group {}", group.getName());
dao.deletePdpGroup(group.getName());
}
+
+ /**
+ * Adds policy deployment data.
+ *
+ * @param policyId ID of the policy being deployed
+ * @param pdps PDPs to which the policy is being deployed
+ * @throws PfModelException if an error occurred
+ */
+ protected void trackDeploy(ToscaPolicyIdentifier policyId, Collection<String> pdps) throws PfModelException {
+ trackDeploy(policyId, new HashSet<>(pdps));
+ }
+
+ /**
+ * Adds policy deployment data.
+ *
+ * @param policyId ID of the policy being deployed
+ * @param pdps PDPs to which the policy is being deployed
+ * @throws PfModelException if an error occurred
+ */
+ protected void trackDeploy(ToscaPolicyIdentifier policyId, Set<String> pdps) throws PfModelException {
+ addData(policyId, pdps, deploy, undeploy);
+ }
+
+ /**
+ * Adds policy undeployment data.
+ *
+ * @param policyId ID of the policy being undeployed
+ * @param pdps PDPs to which the policy is being undeployed
+ * @throws PfModelException if an error occurred
+ */
+ protected void trackUndeploy(ToscaPolicyIdentifier policyId, Collection<String> pdps) throws PfModelException {
+ trackUndeploy(policyId, new HashSet<>(pdps));
+ }
+
+ /**
+ * Adds policy undeployment data.
+ *
+ * @param policyId ID of the policy being undeployed
+ * @param pdps PDPs to which the policy is being undeployed
+ * @throws PfModelException if an error occurred
+ */
+ protected void trackUndeploy(ToscaPolicyIdentifier policyId, Set<String> pdps) throws PfModelException {
+ addData(policyId, pdps, undeploy, deploy);
+ }
+
+ /**
+ * Adds policy deployment/undeployment data.
+ *
+ * @param policyId ID of the policy being deployed/undeployed
+ * @param pdps PDPs to which the policy is being deployed/undeployed
+ * @param addMap map to which it should be added
+ * @param removeMap map from which it should be removed
+ * @throws PfModelException if an error occurred
+ */
+ private void addData(ToscaPolicyIdentifier policyId, Set<String> pdps,
+ Map<ToscaPolicyIdentifier, PolicyPdpNotificationData> addMap,
+ Map<ToscaPolicyIdentifier, PolicyPdpNotificationData> removeMap) throws PfModelException {
+
+ PolicyPdpNotificationData removeData = removeMap.get(policyId);
+ if (removeData != null) {
+ removeData.removeAll(pdps);
+ }
+
+ ToscaPolicyIdentifierOptVersion optid = new ToscaPolicyIdentifierOptVersion(policyId);
+ ToscaPolicyTypeIdentifier policyType = getPolicy(optid).getTypeIdentifier();
+
+ addMap.computeIfAbsent(policyId, key -> new PolicyPdpNotificationData(policyId, policyType)).addAll(pdps);
+ }
+
+ /**
+ * Gets the policies to be deployed.
+ *
+ * @return the policies to be deployed
+ */
+ public Collection<PolicyPdpNotificationData> getDeployData() {
+ return deploy.values();
+ }
+
+ /**
+ * Gets the policies to be undeployed.
+ *
+ * @return the policies to be undeployed
+ */
+ public Collection<PolicyPdpNotificationData> getUndeployData() {
+ return undeploy.values();
+ }
}