* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
package org.onap.policy.pap.main.rest;
import java.util.Collection;
-import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pap.concepts.PolicyNotification;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
import org.onap.policy.pap.main.comm.PdpModifyRequestMap;
import org.onap.policy.pap.main.notification.PolicyNotifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Super class of providers that deploy and undeploy PDP groups. The following items must
* </ul>
*/
public abstract class ProviderBase {
- private static final String DEPLOY_FAILED = "failed to deploy/undeploy policies";
public static final String DB_ERROR_MSG = "DB error";
- private static final Logger logger = LoggerFactory.getLogger(ProviderBase.class);
-
/**
* Lock used when updating PDPs.
*/
*/
private final PolicyModelsProviderFactoryWrapper daoFactory;
-
/**
* Constructs the object.
*/
- public ProviderBase() {
+ protected ProviderBase() {
this.updateLock = Registry.get(PapConstants.REG_PDP_MODIFY_LOCK, Object.class);
this.requestMap = Registry.get(PapConstants.REG_PDP_MODIFY_MAP, PdpModifyRequestMap.class);
this.daoFactory = Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
synchronized (updateLock) {
SessionData data;
+ var notif = new PolicyNotification();
try (PolicyModelsProvider dao = daoFactory.create()) {
processor.accept(data, request);
// make all of the DB updates
- data.updateDb();
+ data.updateDb(notif);
} catch (PfModelException | PfModelRuntimeException e) {
- logger.warn(DEPLOY_FAILED, e);
throw e;
} catch (RuntimeException e) {
- logger.warn(DEPLOY_FAILED, e);
throw new PfModelException(Status.INTERNAL_SERVER_ERROR, "request failed", e);
}
- // track responses for notification purposes
- data.getDeployData().forEach(notifier::addDeploymentData);
- data.getUndeployData().forEach(notifier::addUndeploymentData);
-
// publish the requests
data.getPdpRequests().forEach(pair -> requestMap.addRequest(pair.getLeft(), pair.getRight()));
+
+ // publish the notifications
+ notifier.publish(notif);
}
}
* @param desiredPolicy request policy
* @throws PfModelException if an error occurred
*/
- protected void processPolicy(SessionData data, ToscaPolicyIdentifierOptVersion desiredPolicy)
+ protected void processPolicy(SessionData data, ToscaConceptIdentifierOptVersion desiredPolicy)
throws PfModelException {
ToscaPolicy policy = getPolicy(data, desiredPolicy);
+ desiredPolicy.getName() + " " + desiredPolicy.getVersion());
}
- Updater updater = makeUpdater(data, policy, desiredPolicy);
+ var updater = makeUpdater(data, policy, desiredPolicy);
for (PdpGroup group : groups) {
upgradeGroup(data, group, updater);
* @return a function to update a subgroup
*/
protected abstract Updater makeUpdater(SessionData data, ToscaPolicy policy,
- ToscaPolicyIdentifierOptVersion desiredPolicy);
+ ToscaConceptIdentifierOptVersion desiredPolicy);
/**
* Finds the active PDP group(s) that supports the given policy type.
* given PDP types
* @throws PfModelException if an error occurred
*/
- private Collection<PdpGroup> getGroups(SessionData data, ToscaPolicyTypeIdentifier policyType)
+ private Collection<PdpGroup> getGroups(SessionData data, ToscaConceptIdentifier policyType)
throws PfModelException {
return data.getActivePdpGroupsByPolicyType(policyType);
* @param updater function to update a group
* @throws PfModelException if an error occurred
*/
- private void upgradeGroup(SessionData data, PdpGroup group, Updater updater) throws PfModelException {
+ private void upgradeGroup(SessionData data, PdpGroup group, Updater updater)
+ throws PfModelException {
- boolean updated = false;
+ var updated = false;
for (PdpSubGroup subgroup : group.getPdpSubgroups()) {
makeUpdates(data, group, subgroup);
}
-
if (updated) {
// something changed
data.update(group);
*/
private PdpUpdate makeUpdate(SessionData data, PdpGroup group, PdpSubGroup subgroup, Pdp pdp) {
- PdpUpdate update = new PdpUpdate();
+ var update = new PdpUpdate();
+ update.setSource(PapConstants.PAP_NAME);
update.setName(pdp.getInstanceId());
update.setDescription(group.getDescription());
update.setPdpGroup(group.getName());
update.setPdpSubgroup(subgroup.getPdpType());
- update.setPolicies(subgroup.getPolicies().stream().map(ToscaPolicyIdentifierOptVersion::new)
- .map(ident -> getPolicy(data, ident)).collect(Collectors.toList()));
+ update.setPoliciesToBeDeployed(data.getPoliciesToBeDeployed());
+ update.setPoliciesToBeUndeployed(data.getPoliciesToBeUndeployed());
return update;
}
* @return the policy of interest
* @throws PfModelRuntimeException if an error occurred or the policy was not found
*/
- private ToscaPolicy getPolicy(SessionData data, ToscaPolicyIdentifierOptVersion ident) {
+ private ToscaPolicy getPolicy(SessionData data, ToscaConceptIdentifierOptVersion ident) {
try {
ToscaPolicy policy = data.getPolicy(ident);
if (policy == null) {