diff options
Diffstat (limited to 'main/src/main/java')
18 files changed, 138 insertions, 129 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 e5246eb1..79a5e990 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 @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +31,8 @@ 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.models.tosca.authorative.concepts.ToscaPolicyIdentifier; import org.onap.policy.pap.main.PapConstants; import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper; import org.onap.policy.pap.main.parameters.PapParameterGroup; @@ -106,7 +107,7 @@ public class PdpMessageGenerator { throws PfModelException { final List<ToscaPolicy> policies = new LinkedList<>(); - for (final ToscaPolicyIdentifier policyIdentifier : subGroup.getPolicies()) { + for (final ToscaConceptIdentifier policyIdentifier : subGroup.getPolicies()) { policies.addAll(databaseProvider.getPolicyList(policyIdentifier.getName(), policyIdentifier.getVersion())); } 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 cb9d51b8..85038dee 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 @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +39,7 @@ 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.ToscaPolicyIdentifier; +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; @@ -350,7 +351,7 @@ public class PdpModifyRequestMap { @Override public void failure(String responsePdpName, String reason) { - Collection<ToscaPolicyIdentifier> undeployPolicies = requestCompleted(responsePdpName); + Collection<ToscaConceptIdentifier> undeployPolicies = requestCompleted(responsePdpName); if (undeployPolicies.isEmpty()) { // nothing to undeploy return; @@ -391,7 +392,7 @@ public class PdpModifyRequestMap { * @param responsePdpName name of the PDP provided in the response * @return a list of policies to be undeployed */ - private Collection<ToscaPolicyIdentifier> requestCompleted(String responsePdpName) { + private Collection<ToscaConceptIdentifier> requestCompleted(String responsePdpName) { if (!pdpName.equals(responsePdpName)) { return Collections.emptyList(); } @@ -407,7 +408,7 @@ public class PdpModifyRequestMap { return Collections.emptyList(); } - Collection<ToscaPolicyIdentifier> undeployPolicies = request.getUndeployPolicies(); + Collection<ToscaConceptIdentifier> undeployPolicies = request.getUndeployPolicies(); if (undeployPolicies.isEmpty()) { // nothing to undeploy - just start the next request startNextRequest(request); diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PolicyUndeployer.java b/main/src/main/java/org/onap/policy/pap/main/comm/PolicyUndeployer.java index ecf34893..b5ea2354 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/PolicyUndeployer.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/PolicyUndeployer.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +23,7 @@ package org.onap.policy.pap.main.comm; import java.util.Collection; import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @FunctionalInterface public interface PolicyUndeployer { @@ -34,6 +35,6 @@ public interface PolicyUndeployer { * @param policies policies to be undeployed * @throws PfModelException if an error occurs */ - public void undeploy(String group, String subgroup, Collection<ToscaPolicyIdentifier> policies) + public void undeploy(String group, String subgroup, Collection<ToscaConceptIdentifier> policies) throws PfModelException; } diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/Request.java b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/Request.java index 7edb9041..d8f8895d 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/Request.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/Request.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +24,7 @@ package org.onap.policy.pap.main.comm.msgdata; import java.util.Collection; import org.onap.policy.models.pdp.concepts.PdpMessage; import org.onap.policy.models.pdp.concepts.PdpStatus; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.pap.main.notification.PolicyNotifier; /** @@ -102,5 +103,5 @@ public interface Request { * * @return a list of policies to be undeployed */ - public Collection<ToscaPolicyIdentifier> getUndeployPolicies(); + public Collection<ToscaConceptIdentifier> getUndeployPolicies(); } diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java index 7e0397a5..9a1184b8 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +32,7 @@ import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.utils.services.ServiceManager; import org.onap.policy.models.pdp.concepts.PdpMessage; import org.onap.policy.models.pdp.concepts.PdpStatus; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.pap.main.comm.QueueToken; import org.onap.policy.pap.main.comm.TimerManager; import org.onap.policy.pap.main.notification.PolicyNotifier; @@ -327,7 +328,7 @@ public abstract class RequestImpl implements Request { * Just returns an empty list. */ @Override - public Collection<ToscaPolicyIdentifier> getUndeployPolicies() { + public Collection<ToscaConceptIdentifier> getUndeployPolicies() { return Collections.emptyList(); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java index 753735d4..ada9d193 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +32,8 @@ import org.apache.commons.lang3.StringUtils; import org.onap.policy.models.pdp.concepts.PdpMessage; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.concepts.PdpUpdate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; import org.onap.policy.pap.main.parameters.RequestParams; @@ -45,7 +46,7 @@ public class UpdateReq extends RequestImpl { * Policies to be undeployed if the request fails. */ @Getter - private Collection<ToscaPolicyIdentifier> undeployPolicies = Collections.emptyList(); + private Collection<ToscaConceptIdentifier> undeployPolicies = Collections.emptyList(); /** * Constructs the object, and validates the parameters. @@ -76,7 +77,7 @@ public class UpdateReq extends RequestImpl { return reason; } - Set<ToscaPolicyIdentifier> actualSet = new HashSet<>(alwaysList(response.getPolicies())); + Set<ToscaConceptIdentifier> actualSet = new HashSet<>(alwaysList(response.getPolicies())); getNotifier().processResponse(response.getName(), actualSet); PdpUpdate message = getMessage(); @@ -95,7 +96,7 @@ public class UpdateReq extends RequestImpl { // see if the policies match - Set<ToscaPolicyIdentifier> expectedSet = new HashSet<>(alwaysList(message.getPolicies()).stream() + Set<ToscaConceptIdentifier> expectedSet = new HashSet<>(alwaysList(message.getPolicies()).stream() .map(ToscaPolicy::getIdentifier).collect(Collectors.toSet())); if (!actualSet.equals(expectedSet)) { diff --git a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java index bd14ffb9..3529ccb7 100644 --- a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java +++ b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyCommonTracker.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +34,7 @@ import java.util.Set; import java.util.function.BiPredicate; import java.util.stream.Collectors; import org.onap.policy.models.pap.concepts.PolicyStatus; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** * Common super class for deploy and undeploy trackers. @@ -48,7 +49,7 @@ public abstract class PolicyCommonTracker { * Use a LinkedHashMap, because we'll be doing lots of iteration over the map, and * iteration over a LinkedHashMap is faster than over a plain HashMap. */ - private final Map<ToscaPolicyIdentifier, PolicyTrackerData> policy2data = new LinkedHashMap<>(); + private final Map<ToscaConceptIdentifier, PolicyTrackerData> policy2data = new LinkedHashMap<>(); /** @@ -85,8 +86,8 @@ public abstract class PolicyCommonTracker { * @param ident identifier of the policy of interest * @return the status of the given policy, or empty if the policy is not found */ - public Optional<PolicyStatus> getStatus(ToscaPolicyIdentifier ident) { - ToscaPolicyIdentifier ident2 = new ToscaPolicyIdentifier(ident.getName(), ident.getVersion()); + public Optional<PolicyStatus> getStatus(ToscaConceptIdentifier ident) { + ToscaConceptIdentifier ident2 = new ToscaConceptIdentifier(ident.getName(), ident.getVersion()); PolicyTrackerData data = policy2data.get(ident2); return Optional.ofNullable(data == null ? null : makeStatus(ident2, data)); } @@ -140,7 +141,7 @@ public abstract class PolicyCommonTracker { * @param statusList status messages are added here if policies become complete as a * result of this operation */ - public void processResponse(String pdp, Collection<ToscaPolicyIdentifier> activePolicies, + public void processResponse(String pdp, Collection<ToscaConceptIdentifier> activePolicies, List<PolicyStatus> statusList) { processResponse(pdp, new HashSet<>(activePolicies), statusList); } @@ -154,7 +155,7 @@ public abstract class PolicyCommonTracker { * @param statusList status messages are added here if policies become complete as a * result of this operation */ - public void processResponse(String pdp, Set<ToscaPolicyIdentifier> activePolicies, List<PolicyStatus> statusList) { + public void processResponse(String pdp, Set<ToscaConceptIdentifier> activePolicies, List<PolicyStatus> statusList) { updateMap(statusList, (policyId, data) -> updateData(pdp, data, activePolicies.contains(policyId))); } @@ -173,13 +174,13 @@ public abstract class PolicyCommonTracker { * policy is complete (i.e., no longer awaiting any responses) */ private void updateMap(List<PolicyStatus> statusList, - BiPredicate<ToscaPolicyIdentifier, PolicyTrackerData> updater) { + BiPredicate<ToscaConceptIdentifier, PolicyTrackerData> updater) { - Iterator<Entry<ToscaPolicyIdentifier, PolicyTrackerData>> iter = policy2data.entrySet().iterator(); + Iterator<Entry<ToscaConceptIdentifier, PolicyTrackerData>> iter = policy2data.entrySet().iterator(); while (iter.hasNext()) { - Entry<ToscaPolicyIdentifier, PolicyTrackerData> ent = iter.next(); + Entry<ToscaConceptIdentifier, PolicyTrackerData> ent = iter.next(); - ToscaPolicyIdentifier policyId = ent.getKey(); + ToscaConceptIdentifier policyId = ent.getKey(); PolicyTrackerData data = ent.getValue(); if (!updater.test(policyId, data)) { @@ -224,7 +225,7 @@ public abstract class PolicyCommonTracker { * @param entry policy entry * @return a new status notification */ - private PolicyStatus makeStatus(Map.Entry<ToscaPolicyIdentifier, PolicyTrackerData> entry) { + private PolicyStatus makeStatus(Map.Entry<ToscaConceptIdentifier, PolicyTrackerData> entry) { return makeStatus(entry.getKey(), entry.getValue()); } @@ -235,7 +236,7 @@ public abstract class PolicyCommonTracker { * @param data data to be used to set the status fields * @return a new status notification */ - private PolicyStatus makeStatus(ToscaPolicyIdentifier policyId, PolicyTrackerData data) { + private PolicyStatus makeStatus(ToscaConceptIdentifier policyId, PolicyTrackerData data) { PolicyStatus status = new PolicyStatus(data.getPolicyType(), policyId); data.putValuesInto(status); diff --git a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java index 12630af2..c13e9b78 100644 --- a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java +++ b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyNotifier.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,10 +36,9 @@ 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.provider.PolicyModelsProvider; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; 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.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper; import org.onap.policy.pap.main.comm.Publisher; import org.onap.policy.pap.main.comm.QueueToken; @@ -81,7 +80,7 @@ public class PolicyNotifier { this.publisher = publisher; try (PolicyModelsProvider dao = daoFactory.create()) { - Map<ToscaPolicyIdentifier, ToscaPolicyTypeIdentifier> id2type = loadPolicyTypes(dao); + Map<ToscaConceptIdentifier, ToscaConceptIdentifier> id2type = loadPolicyTypes(dao); loadPolicies(dao, id2type); } } @@ -93,10 +92,10 @@ public class PolicyNotifier { * @return a mapping from policy id to policy type * @throws PfModelException if a DB error occurs */ - private Map<ToscaPolicyIdentifier, ToscaPolicyTypeIdentifier> loadPolicyTypes(PolicyModelsProvider dao) + private Map<ToscaConceptIdentifier, ToscaConceptIdentifier> loadPolicyTypes(PolicyModelsProvider dao) throws PfModelException { - Map<ToscaPolicyIdentifier, ToscaPolicyTypeIdentifier> id2type = new HashMap<>(); + Map<ToscaConceptIdentifier, ToscaConceptIdentifier> id2type = new HashMap<>(); for (ToscaPolicy policy : dao.getFilteredPolicyList(ToscaPolicyFilter.builder().build())) { id2type.put(policy.getIdentifier(), policy.getTypeIdentifier()); @@ -112,7 +111,7 @@ public class PolicyNotifier { * @param dao provider used to retrieve policies from the DB * @throws PfModelException if a DB error occurs */ - private void loadPolicies(PolicyModelsProvider dao, Map<ToscaPolicyIdentifier, ToscaPolicyTypeIdentifier> id2type) + private void loadPolicies(PolicyModelsProvider dao, Map<ToscaConceptIdentifier, ToscaConceptIdentifier> id2type) throws PfModelException { for (PdpGroup group : dao.getPdpGroups(null)) { for (PdpSubGroup subgrp : group.getPdpSubgroups()) { @@ -128,12 +127,12 @@ public class PolicyNotifier { * @param group group containing the subgroup * @param subgrp subgroup whose policies are to be loaded */ - private void loadPolicies(Map<ToscaPolicyIdentifier, ToscaPolicyTypeIdentifier> id2type, PdpGroup group, + private void loadPolicies(Map<ToscaConceptIdentifier, ToscaConceptIdentifier> id2type, PdpGroup group, PdpSubGroup subgrp) { - for (ToscaPolicyIdentifier policyId : subgrp.getPolicies()) { + for (ToscaConceptIdentifier policyId : subgrp.getPolicies()) { - ToscaPolicyTypeIdentifier type = id2type.get(policyId); + ToscaConceptIdentifier type = id2type.get(policyId); if (type == null) { logger.error("group {}:{} refers to non-existent policy {}", group.getName(), subgrp.getPdpType(), policyId); @@ -171,7 +170,7 @@ public class PolicyNotifier { * @param ident identifier of the policy of interest * @return the status of the given policy, or empty if the policy is not found */ - public synchronized Optional<PolicyStatus> getStatus(ToscaPolicyIdentifier ident) { + public synchronized Optional<PolicyStatus> getStatus(ToscaConceptIdentifier ident) { return deployTracker.getStatus(ident); } @@ -204,7 +203,7 @@ public class PolicyNotifier { * @param activePolicies policies that are still active on the PDP, as specified in * the response */ - public synchronized void processResponse(String pdp, Collection<ToscaPolicyIdentifier> activePolicies) { + public synchronized void processResponse(String pdp, Collection<ToscaConceptIdentifier> activePolicies) { processResponse(pdp, new HashSet<>(activePolicies)); } @@ -215,7 +214,7 @@ public class PolicyNotifier { * @param activePolicies policies that are still active on the PDP, as specified in * the response */ - public synchronized void processResponse(String pdp, Set<ToscaPolicyIdentifier> activePolicies) { + public synchronized void processResponse(String pdp, Set<ToscaConceptIdentifier> activePolicies) { PolicyNotification notification = new PolicyNotification(); undeployTracker.processResponse(pdp, activePolicies, notification.getDeleted()); diff --git a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyPdpNotificationData.java b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyPdpNotificationData.java index a65e46f2..b93f8930 100644 --- a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyPdpNotificationData.java +++ b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyPdpNotificationData.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,16 +25,15 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; import lombok.Getter; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** * Data used to track deploy/undeploy of a policy to PDPs. */ @Getter public class PolicyPdpNotificationData { - private final ToscaPolicyIdentifier policyId; - private final ToscaPolicyTypeIdentifier policyType; + private final ToscaConceptIdentifier policyId; + private final ToscaConceptIdentifier policyType; private final Set<String> pdps = new HashSet<>(); @@ -43,7 +43,7 @@ public class PolicyPdpNotificationData { * @param policyId ID of the policy being deployed/undeployed * @param policyType type of the associated policy */ - public PolicyPdpNotificationData(ToscaPolicyIdentifier policyId, ToscaPolicyTypeIdentifier policyType) { + public PolicyPdpNotificationData(ToscaConceptIdentifier policyId, ToscaConceptIdentifier policyType) { this.policyId = policyId; this.policyType = policyType; } diff --git a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyTrackerData.java b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyTrackerData.java index 29e7b147..7dfb378f 100644 --- a/main/src/main/java/org/onap/policy/pap/main/notification/PolicyTrackerData.java +++ b/main/src/main/java/org/onap/policy/pap/main/notification/PolicyTrackerData.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +26,7 @@ import java.util.HashSet; import java.util.Set; import lombok.Getter; import org.onap.policy.models.pap.concepts.PolicyStatus; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** * Data associated with a policy, used by PolicyTracker. PDPs start in @@ -38,7 +39,7 @@ public class PolicyTrackerData { * The policy type associated with the policy. */ @Getter - private final ToscaPolicyTypeIdentifier policyType; + private final ToscaConceptIdentifier policyType; /** * PDPs that have successfully completed an update of the policy. @@ -61,7 +62,7 @@ public class PolicyTrackerData { * * @param policyType policy type */ - public PolicyTrackerData(ToscaPolicyTypeIdentifier policyType) { + public PolicyTrackerData(ToscaConceptIdentifier policyType) { this.policyType = policyType; } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java index 4e61621b..00db7cc0 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,10 +44,9 @@ 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.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.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -344,7 +343,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { private void trackPdpsDelSubGroup(SessionData data, PdpSubGroup subgrp) throws PfModelException { Set<String> pdps = subgrp.getPdpInstances().stream().map(Pdp::getInstanceId).collect(Collectors.toSet()); - for (ToscaPolicyIdentifier policyId : subgrp.getPolicies()) { + for (ToscaConceptIdentifier policyId : subgrp.getPolicies()) { data.trackUndeploy(policyId, pdps); } } @@ -432,7 +431,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { */ private ValidationResult validateSupportedTypes(SessionData data, PdpSubGroup subgrp) throws PfModelException { BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp); - for (ToscaPolicyTypeIdentifier type : subgrp.getSupportedPolicyTypes()) { + for (ToscaConceptIdentifier type : subgrp.getSupportedPolicyTypes()) { if (!type.getName().endsWith(".*") && data.getPolicyType(type) == null) { result.addResult( new ObjectValidationResult("policy type", type, ValidationStatus.INVALID, "unknown policy type")); @@ -443,7 +442,8 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { } @Override - protected Updater makeUpdater(SessionData data, ToscaPolicy policy, ToscaPolicyIdentifierOptVersion desiredPolicy) { + protected Updater makeUpdater(SessionData data, ToscaPolicy policy, + ToscaConceptIdentifierOptVersion desiredPolicy) { throw new UnsupportedOperationException("makeUpdater should not be invoked"); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java index 80dcda35..658a13cc 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +39,7 @@ import javax.ws.rs.core.Response.Status; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -124,7 +125,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 { @ApiParam(value = "PDP Policy Name", required = true) @PathParam("name") String policyName) { return doOperation(requestId, "undeploy policy failed", - () -> provider.undeploy(new ToscaPolicyIdentifierOptVersion(policyName, null))); + () -> provider.undeploy(new ToscaConceptIdentifierOptVersion(policyName, null))); } /** @@ -166,7 +167,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 { @ApiParam(value = "PDP Policy Version", required = true) @PathParam("version") String version) { return doOperation(requestId, "undeploy policy failed", - () -> provider.undeploy(new ToscaPolicyIdentifierOptVersion(policyName, version))); + () -> provider.undeploy(new ToscaConceptIdentifierOptVersion(policyName, version))); } /** diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java index 44450389..38851cd3 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,9 @@ import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.enums.PdpState; +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.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,7 +93,7 @@ public class PdpGroupDeleteProvider extends ProviderBase { * @param policyIdent identifier of the policy to be undeployed * @throws PfModelException if an error occurred */ - public void undeploy(ToscaPolicyIdentifierOptVersion policyIdent) throws PfModelException { + public void undeploy(ToscaConceptIdentifierOptVersion policyIdent) throws PfModelException { process(policyIdent, this::undeployPolicy); } @@ -104,7 +104,7 @@ public class PdpGroupDeleteProvider extends ProviderBase { * @param ident identifier of the policy to be deleted * @throws PfModelException if an error occurred */ - private void undeployPolicy(SessionData data, ToscaPolicyIdentifierOptVersion ident) throws PfModelException { + private void undeployPolicy(SessionData data, ToscaConceptIdentifierOptVersion ident) throws PfModelException { try { processPolicy(data, ident); @@ -125,10 +125,10 @@ public class PdpGroupDeleteProvider extends ProviderBase { */ @Override protected Updater makeUpdater(SessionData data, ToscaPolicy policy, - ToscaPolicyIdentifierOptVersion desiredIdent) { + ToscaConceptIdentifierOptVersion desiredIdent) { // construct a matcher based on whether or not the version was specified - Predicate<ToscaPolicyIdentifier> matcher; + Predicate<ToscaConceptIdentifier> matcher; if (desiredIdent.getVersion() != null) { // version was specified - match the whole identifier @@ -148,9 +148,9 @@ public class PdpGroupDeleteProvider extends ProviderBase { boolean result = false; - Iterator<ToscaPolicyIdentifier> iter = subgroup.getPolicies().iterator(); + Iterator<ToscaConceptIdentifier> iter = subgroup.getPolicies().iterator(); while (iter.hasNext()) { - ToscaPolicyIdentifier ident = iter.next(); + ToscaConceptIdentifier ident = iter.next(); if (matcher.test(ident)) { result = true; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java index d09e2ea7..c30ee8f9 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,10 +44,9 @@ import org.onap.policy.models.pdp.concepts.DeploymentSubGroup; 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.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.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -226,7 +225,7 @@ public class PdpGroupDeployProvider extends ProviderBase { private boolean addPolicies(SessionData data, PdpSubGroup dbsub, DeploymentSubGroup subgrp) throws PfModelException { - Set<ToscaPolicyIdentifier> policies = new LinkedHashSet<>(dbsub.getPolicies()); + Set<ToscaConceptIdentifier> policies = new LinkedHashSet<>(dbsub.getPolicies()); policies.addAll(subgrp.getPolicies()); DeploymentSubGroup subgrp2 = new DeploymentSubGroup(subgrp); @@ -239,7 +238,7 @@ public class PdpGroupDeployProvider extends ProviderBase { private boolean deletePolicies(SessionData data, PdpSubGroup dbsub, DeploymentSubGroup subgrp) throws PfModelException { - Set<ToscaPolicyIdentifier> policies = new LinkedHashSet<>(dbsub.getPolicies()); + Set<ToscaConceptIdentifier> policies = new LinkedHashSet<>(dbsub.getPolicies()); policies.removeAll(subgrp.getPolicies()); DeploymentSubGroup subgrp2 = new DeploymentSubGroup(subgrp); @@ -252,10 +251,10 @@ public class PdpGroupDeployProvider extends ProviderBase { private boolean updatePolicies(SessionData data, PdpSubGroup dbsub, DeploymentSubGroup subgrp) throws PfModelException { - Set<ToscaPolicyIdentifier> undeployed = new HashSet<>(dbsub.getPolicies()); + Set<ToscaConceptIdentifier> undeployed = new HashSet<>(dbsub.getPolicies()); undeployed.removeAll(subgrp.getPolicies()); - Set<ToscaPolicyIdentifier> deployed = new HashSet<>(subgrp.getPolicies()); + Set<ToscaConceptIdentifier> deployed = new HashSet<>(subgrp.getPolicies()); deployed.removeAll(dbsub.getPolicies()); if (deployed.isEmpty() && undeployed.isEmpty()) { @@ -266,11 +265,11 @@ public class PdpGroupDeployProvider extends ProviderBase { Set<String> pdps = dbsub.getPdpInstances().stream().map(Pdp::getInstanceId).collect(Collectors.toSet()); - for (ToscaPolicyIdentifier policyId : deployed) { + for (ToscaConceptIdentifier policyId : deployed) { data.trackDeploy(policyId, pdps); } - for (ToscaPolicyIdentifier policyId : undeployed) { + for (ToscaConceptIdentifier policyId : undeployed) { data.trackUndeploy(policyId, pdps); } @@ -320,7 +319,7 @@ public class PdpGroupDeployProvider extends ProviderBase { BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp); - for (ToscaPolicyIdentifier ident : subgrp.getPolicies()) { + for (ToscaConceptIdentifier ident : subgrp.getPolicies()) { // note: "ident" may not have a fully qualified version String expectedVersion = dbname2vers.get(ident.getName()); @@ -333,7 +332,7 @@ public class PdpGroupDeployProvider extends ProviderBase { // policy doesn't appear in the DB's policy list - look it up - ToscaPolicy policy = data.getPolicy(new ToscaPolicyIdentifierOptVersion(ident)); + ToscaPolicy policy = data.getPolicy(new ToscaConceptIdentifierOptVersion(ident)); if (policy == null) { result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID, "unknown policy")); @@ -359,7 +358,7 @@ public class PdpGroupDeployProvider extends ProviderBase { * fully qualified * @param result the validation result */ - private void validateVersion(String dbvers, ToscaPolicyIdentifier ident, BeanValidationResult result) { + private void validateVersion(String dbvers, ToscaConceptIdentifier ident, BeanValidationResult result) { String idvers = ident.getVersion(); if (dbvers.equals(idvers)) { return; @@ -397,7 +396,7 @@ public class PdpGroupDeployProvider extends ProviderBase { */ private void deploySimplePolicies(SessionData data, PdpDeployPolicies policies) throws PfModelException { - for (ToscaPolicyIdentifierOptVersion desiredPolicy : policies.getPolicies()) { + for (ToscaConceptIdentifierOptVersion desiredPolicy : policies.getPolicies()) { try { processPolicy(data, desiredPolicy); @@ -415,10 +414,10 @@ public class PdpGroupDeployProvider extends ProviderBase { */ @Override protected Updater makeUpdater(SessionData data, ToscaPolicy policy, - ToscaPolicyIdentifierOptVersion requestedIdent) { + ToscaConceptIdentifierOptVersion requestedIdent) { - ToscaPolicyIdentifier desiredIdent = policy.getIdentifier(); - ToscaPolicyTypeIdentifier desiredType = policy.getTypeIdentifier(); + ToscaConceptIdentifier desiredIdent = policy.getIdentifier(); + ToscaConceptIdentifier desiredType = policy.getTypeIdentifier(); return (group, subgroup) -> { @@ -457,15 +456,15 @@ public class PdpGroupDeployProvider extends ProviderBase { * @param desiredType policy type of interest * @return {@code true} if the policy type is supported, {@code false} otherwise */ - private boolean isPolicySupported(List<ToscaPolicyTypeIdentifier> supportedTypes, - ToscaPolicyTypeIdentifier desiredType) { + private boolean isPolicySupported(List<ToscaConceptIdentifier> supportedTypes, + ToscaConceptIdentifier desiredType) { if (supportedTypes.contains(desiredType)) { return true; } String desiredTypeName = desiredType.getName(); - for (ToscaPolicyTypeIdentifier type : supportedTypes) { + for (ToscaConceptIdentifier type : supportedTypes) { String supType = type.getName(); if (supType.endsWith(".*") && desiredTypeName.startsWith(supType.substring(0, supType.length() - 1))) { // matches everything up to, AND INCLUDING, the "." @@ -487,11 +486,11 @@ public class PdpGroupDeployProvider extends ProviderBase { * @throws PfModelRuntimeException if the subgroup contains a different version of the * desired policy */ - private boolean containsPolicy(PdpGroup group, PdpSubGroup subgroup, ToscaPolicyIdentifier desiredIdent) { + private boolean containsPolicy(PdpGroup group, PdpSubGroup subgroup, ToscaConceptIdentifier desiredIdent) { String desnm = desiredIdent.getName(); String desvers = desiredIdent.getVersion(); - for (ToscaPolicyIdentifier actualIdent : subgroup.getPolicies()) { + for (ToscaConceptIdentifier actualIdent : subgroup.getPolicies()) { if (!actualIdent.getName().equals(desnm)) { continue; } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java index cbacd5bf..bc838621 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +39,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.pap.concepts.PolicyStatus; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.pap.main.PapConstants; import org.onap.policy.pap.main.notification.PolicyNotifier; @@ -173,7 +174,7 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 { @ApiParam(value = "Policy Version", required = true) @PathParam("version") String version, @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) { - ToscaPolicyIdentifier ident = new ToscaPolicyIdentifier(name, version); + ToscaConceptIdentifier ident = new ToscaConceptIdentifier(name, version); Optional<PolicyStatus> result = notifier.getStatus(ident); if (result.isPresent()) { return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId) diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyUndeployerImpl.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyUndeployerImpl.java index 85ad1280..1e7c788b 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyUndeployerImpl.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyUndeployerImpl.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,9 @@ import org.onap.policy.models.base.PfModelException; 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.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.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion; import org.onap.policy.pap.main.comm.PolicyUndeployer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +51,7 @@ public class PolicyUndeployerImpl extends ProviderBase implements PolicyUndeploy } @Override - public void undeploy(String group, String subgroup, Collection<ToscaPolicyIdentifier> policies) + public void undeploy(String group, String subgroup, Collection<ToscaConceptIdentifier> policies) throws PfModelException { process(new Info(group, subgroup, policies), this::undeployPolicies); @@ -84,7 +84,7 @@ public class PolicyUndeployerImpl extends ProviderBase implements PolicyUndeploy boolean updated = false; Set<String> pdps = subgroup.getPdpInstances().stream().map(Pdp::getInstanceId).collect(Collectors.toSet()); - for (ToscaPolicyIdentifier ident : policyInfo.policies) { + for (ToscaConceptIdentifier ident : policyInfo.policies) { if (!subgroup.getPolicies().remove(ident)) { continue; } @@ -104,16 +104,17 @@ public class PolicyUndeployerImpl extends ProviderBase implements PolicyUndeploy } @Override - protected Updater makeUpdater(SessionData data, ToscaPolicy policy, ToscaPolicyIdentifierOptVersion desiredPolicy) { + protected Updater makeUpdater(SessionData data, ToscaPolicy policy, + ToscaConceptIdentifierOptVersion desiredPolicy) { throw new UnsupportedOperationException("makeUpdater should not be invoked"); } private static class Info { private String group; private String subgroup; - private Collection<ToscaPolicyIdentifier> policies; + private Collection<ToscaConceptIdentifier> policies; - public Info(String group, String subgroup, Collection<ToscaPolicyIdentifier> policies) { + public Info(String group, String subgroup, Collection<ToscaConceptIdentifier> policies) { this.group = group; this.subgroup = subgroup; this.policies = policies; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java index 0b8da90b..0de7a6c4 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * 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"); @@ -33,9 +33,9 @@ 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; @@ -127,7 +127,7 @@ public abstract class ProviderBase { * @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); @@ -156,7 +156,7 @@ public abstract class ProviderBase { * @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. @@ -167,7 +167,7 @@ public abstract class ProviderBase { * 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); @@ -233,7 +233,7 @@ public abstract class ProviderBase { update.setDescription(group.getDescription()); update.setPdpGroup(group.getName()); update.setPdpSubgroup(subgroup.getPdpType()); - update.setPolicies(subgroup.getPolicies().stream().map(ToscaPolicyIdentifierOptVersion::new) + update.setPolicies(subgroup.getPolicies().stream().map(ToscaConceptIdentifierOptVersion::new) .map(ident -> getPolicy(data, ident)).collect(Collectors.toList())); return update; @@ -247,7 +247,7 @@ public abstract class ProviderBase { * @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) { diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java index 0d8f7033..cdcc51c6 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,13 +38,12 @@ import org.onap.policy.models.pdp.concepts.PdpStateChange; 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.ToscaConceptIdentifierOptVersion; 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; @@ -75,7 +75,7 @@ public class SessionData { * Maps a policy type to the list of matching groups. Every group appearing within * this map has a corresponding entry in {@link #groupCache}. */ - private final Map<ToscaPolicyTypeIdentifier, List<GroupData>> type2groups = new HashMap<>(); + private final Map<ToscaConceptIdentifier, List<GroupData>> type2groups = new HashMap<>(); /** * Maps a PDP name to its most recently generated update and state-change requests. @@ -85,24 +85,24 @@ public class SessionData { /** * Maps a policy's identifier to the policy. */ - private final Map<ToscaPolicyIdentifierOptVersion, ToscaPolicy> policyCache = new HashMap<>(); + private final Map<ToscaConceptIdentifierOptVersion, ToscaPolicy> policyCache = new HashMap<>(); /** * Maps a policy type's identifier to the policy. */ - private final Map<ToscaPolicyTypeIdentifier, ToscaPolicyType> typeCache = new HashMap<>(); + private final Map<ToscaConceptIdentifier, 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<>(); + private final Map<ToscaConceptIdentifier, 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<>(); + private final Map<ToscaConceptIdentifier, PolicyPdpNotificationData> undeploy = new HashMap<>(); /** @@ -122,7 +122,7 @@ public class SessionData { * @return the specified policy type * @throws PfModelException if an error occurred */ - public ToscaPolicyType getPolicyType(ToscaPolicyTypeIdentifier desiredType) throws PfModelException { + public ToscaPolicyType getPolicyType(ToscaConceptIdentifier desiredType) throws PfModelException { ToscaPolicyType type = typeCache.get(desiredType); if (type == null) { @@ -147,7 +147,7 @@ public class SessionData { * @return the specified policy * @throws PfModelException if an error occurred */ - public ToscaPolicy getPolicy(ToscaPolicyIdentifierOptVersion desiredPolicy) throws PfModelException { + public ToscaPolicy getPolicy(ToscaConceptIdentifierOptVersion desiredPolicy) throws PfModelException { ToscaPolicy policy = policyCache.get(desiredPolicy); if (policy == null) { @@ -164,7 +164,7 @@ public class SessionData { } // desired version may have only been a prefix - cache with full identifier, too - policyCache.putIfAbsent(new ToscaPolicyIdentifierOptVersion(policy.getIdentifier()), policy); + policyCache.putIfAbsent(new ToscaConceptIdentifierOptVersion(policy.getIdentifier()), policy); return policy; } @@ -346,7 +346,7 @@ public class SessionData { * @return the active groups supporting the given policy * @throws PfModelException if an error occurred */ - public List<PdpGroup> getActivePdpGroupsByPolicyType(ToscaPolicyTypeIdentifier type) throws PfModelException { + public List<PdpGroup> getActivePdpGroupsByPolicyType(ToscaConceptIdentifier type) throws PfModelException { /* * Cannot use computeIfAbsent() because the enclosed code throws an unchecked * exception and handling that would obfuscate the code too much, thus disabling @@ -431,7 +431,7 @@ public class SessionData { * @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 { + protected void trackDeploy(ToscaConceptIdentifier policyId, Collection<String> pdps) throws PfModelException { trackDeploy(policyId, new HashSet<>(pdps)); } @@ -442,7 +442,7 @@ public class SessionData { * @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 { + protected void trackDeploy(ToscaConceptIdentifier policyId, Set<String> pdps) throws PfModelException { addData(policyId, pdps, deploy, undeploy); } @@ -453,7 +453,7 @@ public class SessionData { * @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 { + protected void trackUndeploy(ToscaConceptIdentifier policyId, Collection<String> pdps) throws PfModelException { trackUndeploy(policyId, new HashSet<>(pdps)); } @@ -464,7 +464,7 @@ public class SessionData { * @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 { + protected void trackUndeploy(ToscaConceptIdentifier policyId, Set<String> pdps) throws PfModelException { addData(policyId, pdps, undeploy, deploy); } @@ -477,17 +477,17 @@ public class SessionData { * @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 { + private void addData(ToscaConceptIdentifier policyId, Set<String> pdps, + Map<ToscaConceptIdentifier, PolicyPdpNotificationData> addMap, + Map<ToscaConceptIdentifier, 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(); + ToscaConceptIdentifierOptVersion optid = new ToscaConceptIdentifierOptVersion(policyId); + ToscaConceptIdentifier policyType = getPolicy(optid).getTypeIdentifier(); addMap.computeIfAbsent(policyId, key -> new PolicyPdpNotificationData(policyId, policyType)).addAll(pdps); } |