2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2022 Nordix Foundation.
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.models.provider;
25 import java.time.Instant;
26 import java.util.Collection;
27 import java.util.List;
29 import lombok.NonNull;
30 import org.onap.policy.models.base.PfConceptKey;
31 import org.onap.policy.models.base.PfModelException;
32 import org.onap.policy.models.base.PfModelRuntimeException;
33 import org.onap.policy.models.pap.concepts.PolicyAudit;
34 import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
35 import org.onap.policy.models.pdp.concepts.Pdp;
36 import org.onap.policy.models.pdp.concepts.PdpGroup;
37 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
38 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
39 import org.onap.policy.models.pdp.concepts.PdpStatistics;
40 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
41 import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
49 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
52 * This interface describes the operations that are provided to users and components for reading objects from and
53 * writing objects to the database.
55 * @author Liam Fallon (liam.fallon@est.tech)
57 public interface PolicyModelsProvider extends AutoCloseable {
59 * Open the policy model provider initializing whatever internal handling it needs.
61 * @throws PfModelException on errors opening the models provider
63 public void init() throws PfModelException;
66 public void close() throws PfModelException;
69 * Get service templates.
71 * @param name the name of the topology template to get, set to null to get all service templates
72 * @param version the version of the service template to get, set to null to get all service templates
73 * @return the topology templates found
74 * @throws PfModelException on errors getting service templates
76 public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version)
77 throws PfModelException;
80 * Get filtered service templates.
82 * @param filter the filter for the service templates to get
83 * @return the service templates found
84 * @throws PfModelException on errors getting service templates
86 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
87 @NonNull final ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException;
90 * Create service template.
92 * @param serviceTemplate the service template to be created
93 * @return the created service template
94 * @throws PfModelException on errors creating the service template
96 public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
97 throws PfModelException;
100 * Update service template.
102 * @param serviceTemplate the service template to be updated
103 * @return the updated service template
104 * @throws PfModelException on errors updating the service template
106 public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
107 throws PfModelException;
110 * Delete service template.
112 * @param name the name of the service template to delete.
113 * @param version the version of the service template to delete.
114 * @return the TOSCA service template that was deleted
115 * @throws PfModelException on errors deleting policy types
117 public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version)
118 throws PfModelException;
123 * @param name the name of the policy type to get, set to null to get all policy types
124 * @param version the version of the policy type to get, set to null to get all versions
125 * @return the policy types found
126 * @throws PfModelException on errors getting policy types
128 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
133 * @param name the name of the policy type to get, set to null to get all policy types
134 * @param version the version of the policy type to get, set to null to get all versions
135 * @return the policy types found
136 * @throws PfModelException on errors getting policy types
138 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
141 * Get filtered policy types.
143 * @param filter the filter for the policy types to get
144 * @return the policy types found
145 * @throws PfModelException on errors getting policy types
147 public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
148 throws PfModelException;
151 * Get filtered policy types.
153 * @param filter the filter for the policy types to get
154 * @return the policy types found
155 * @throws PfModelException on errors getting policy types
157 public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
158 throws PfModelException;
161 * Create policy types.
163 * @param serviceTemplate the service template containing the definition of the policy types to be created
164 * @return the TOSCA service template containing the created policy types
165 * @throws PfModelException on errors creating policy types
167 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
168 throws PfModelException;
171 * Update policy types.
173 * @param serviceTemplate the service template containing the definition of the policy types to be modified
174 * @return the TOSCA service template containing the modified policy types
175 * @throws PfModelException on errors updating policy types
177 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
178 throws PfModelException;
181 * Delete policy type.
183 * @param name the name of the policy type to delete.
184 * @param version the version of the policy type to delete.
185 * @return the TOSCA service template containing the policy type that was deleted
186 * @throws PfModelException on errors deleting the policy type
188 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
189 throws PfModelException;
194 * @param name the name of the policy to get, null to get all policies
195 * @param version the version of the policy to get, null to get all versions of a policy
196 * @return the policies found
197 * @throws PfModelException on errors getting policies
199 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
204 * @param name the name of the policy to get, null to get all policies
205 * @param version the version of the policy to get, null to get all versions of a policy
206 * @return the policies found
207 * @throws PfModelException on errors getting policies
209 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
212 * Get filtered policies.
214 * @param filter the filter for the policies to get
215 * @return the policies found
216 * @throws PfModelException on errors getting policies
218 public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
219 throws PfModelException;
222 * Get filtered policies.
224 * @param filter the filter for the policies to get
225 * @return the policies found
226 * @throws PfModelException on errors getting policies
228 public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
229 throws PfModelException;
234 * @param serviceTemplate the service template containing the definitions of the new policies to be created.
235 * @return the TOSCA service template containing the policy types that were created
236 * @throws PfModelException on errors creating policies
238 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
239 throws PfModelException;
244 * @param serviceTemplate the service template containing the definitions of the policies to be updated.
245 * @return the TOSCA service template containing the policies that were updated
246 * @throws PfModelException on errors updating policies
248 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
249 throws PfModelException;
254 * @param name the name of the policy to delete.
255 * @param version the version of the policy to delete.
256 * @return the TOSCA service template containing the policy that was deleted
257 * @throws PfModelException on errors deleting a policy
259 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
260 throws PfModelException;
264 * Create tosca node templates.
266 * @param serviceTemplate the definitions of the new node templates to be created.
267 * @return the tosca node templates that were created
268 * @throws PfModelException on errors creating tosca node templates
270 public ToscaServiceTemplate createToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
271 throws PfModelException;
274 * Update tosca node templates.
276 * @param serviceTemplate with node templates to be updated.
277 * @return the service template with node templates that were updated
278 * @throws PfModelException on errors updating tosca node templates
280 public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
281 throws PfModelRuntimeException, PfModelException;
284 * Delete a tosca node template.
286 * @param name the name of the node template to delete.
287 * @param version the version of the node template to delete.
288 * @return the service template with node templates that was deleted
289 * @throws PfModelException on errors deleting a node template
291 public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @NonNull final String version)
292 throws PfModelException;
296 * Get filtered node template metadataSet entities.
298 * @return the list of metadataSet found
299 * @throws PfModelException on errors getting node template metadataSet
301 public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(final String name,
302 final String version)
303 throws PfModelException;
306 * Get filtered node template entities.
308 * @return the list of nodeTemplates found
309 * @throws PfModelException on errors getting node template
311 public List<Map<PfConceptKey, ToscaNodeTemplate>> getToscaNodeTemplate(final String name,
312 final String version)
313 throws PfModelException;
318 * @param name the name of the policy to get, null to get all PDP groups
319 * @return the PDP groups found
320 * @throws PfModelException on errors getting PDP groups
322 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
325 * Get filtered PDP groups.
327 * @param filter the filter for the PDP groups to get
328 * @return the PDP groups found
329 * @throws PfModelException on errors getting policies
331 public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
334 * Creates PDP groups.
336 * @param pdpGroups a specification of the PDP groups to create
337 * @return the PDP groups created
338 * @throws PfModelException on errors creating PDP groups
340 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
343 * Updates PDP groups.
345 * @param pdpGroups a specification of the PDP groups to update
346 * @return the PDP groups updated
347 * @throws PfModelException on errors updating PDP groups
349 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
352 * Update a PDP subgroup.
354 * @param pdpGroupName the name of the PDP group of the PDP subgroup
355 * @param pdpSubGroup the PDP subgroup to be updated
356 * @throws PfModelException on errors updating PDP subgroups
358 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
359 throws PfModelException;
364 * @param pdpGroupName the name of the PDP group of the PDP subgroup
365 * @param pdpSubGroup the PDP subgroup to be updated
366 * @param pdp the PDP to be updated
367 * @throws PfModelException on errors updating PDP subgroups
369 public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
370 throws PfModelException;
373 * Delete a PDP group.
375 * @param name the name of the policy to get, null to get all PDP groups
376 * @return the PDP group deleted
377 * @throws PfModelException on errors deleting PDP groups
379 public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
383 * Get filtered PdpStatistics.
385 * @param filterParams filter parameters
386 * @return the PDP statistics found
387 * @throws PfModelException on errors getting policies
389 public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException;
392 * Creates PDP statistics.
394 * @param pdpStatisticsList a specification of the PDP statistics to create
395 * @return the PDP statistics created
396 * @throws PfModelException on errors creating PDP statistics
398 public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
399 throws PfModelException;
402 * Updates PDP statistics.
404 * @param pdpStatisticsList a specification of the PDP statistics to update
405 * @return the PDP statistics updated
406 * @throws PfModelException on errors updating PDP statistics
408 public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
409 throws PfModelException;
412 * Delete a PDP statistics.
414 * @param name the name of the policy to get, null to get all PDP statistics
415 * @param timestamp the timestamp of statistics to delete, null to delete all statistics record of given pdp
416 * @return the PDP statistics deleted
417 * @throws PfModelException on errors deleting PDP statistics
419 public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Instant timestamp) throws PfModelException;
422 * Gets all policy deployments.
424 * @return the deployments found
425 * @throws PfModelException on errors getting PDP groups
427 public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException;
430 * Gets all deployments for a policy.
432 * @return the deployments found
433 * @throws PfModelException on errors getting PDP groups
435 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
436 throws PfModelException;
439 * Gets the policy deployments for a PDP group.
441 * @param groupName the name of the PDP group of interest, null to get results for all PDP groups
442 * @return the deployments found
443 * @throws PfModelException on errors getting PDP groups
445 public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException;
448 * Creates, updates, and deletes collections of policy status.
450 * @param createObjs the objects to create
451 * @param updateObjs the objects to update
452 * @param deleteObjs the objects to delete
454 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
455 Collection<PdpPolicyStatus> deleteObjs);
458 * Creates records for audit actions on policies.
460 * @param auditRecords the objects to create
462 public void createAuditRecords(@NonNull List<PolicyAudit> auditRecords);
465 * Collect the audit records.
466 * @param auditFilter filter for search
467 * @return list of {@link PolicyAudit} or empty if none or not match with filter
469 public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter);