5cc5fc96bfe7b0d70ef9e568a4168313013bc444
[policy/models.git] / models-provider / src / main / java / org / onap / policy / models / provider / PolicyModelsProvider.java
1 /*-
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.models.provider;
24
25 import java.time.Instant;
26 import java.util.Collection;
27 import java.util.List;
28 import java.util.Map;
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;
50
51 /**
52  * This interface describes the operations that are provided to users and components for reading objects from and
53  * writing objects to the database.
54  *
55  * @author Liam Fallon (liam.fallon@est.tech)
56  */
57 public interface PolicyModelsProvider extends AutoCloseable {
58     /**
59      * Open the policy model provider initializing whatever internal handling it needs.
60      *
61      * @throws PfModelException on errors opening the models provider
62      */
63     public void init() throws PfModelException;
64
65     @Override
66     public void close() throws PfModelException;
67
68     /**
69      * Get service templates.
70      *
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
75      */
76     public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version)
77             throws PfModelException;
78
79     /**
80      * Get filtered service templates.
81      *
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
85      */
86     public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
87             @NonNull final ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException;
88
89     /**
90      * Create service template.
91      *
92      * @param serviceTemplate the service template to be created
93      * @return the created service template
94      * @throws PfModelException on errors creating the service template
95      */
96     public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
97             throws PfModelException;
98
99     /**
100      * Update service template.
101      *
102      * @param serviceTemplate the service template to be updated
103      * @return the updated service template
104      * @throws PfModelException on errors updating the service template
105      */
106     public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
107             throws PfModelException;
108
109     /**
110      * Delete service template.
111      *
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
116      */
117     public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version)
118             throws PfModelException;
119
120     /**
121      * Get policy types.
122      *
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
127      */
128     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
129
130     /**
131      * Get policy types.
132      *
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
137      */
138     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
139
140     /**
141      * Get filtered policy types.
142      *
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
146      */
147     public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
148             throws PfModelException;
149
150     /**
151      * Get filtered policy types.
152      *
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
156      */
157     public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
158             throws PfModelException;
159
160     /**
161      * Create policy types.
162      *
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
166      */
167     public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
168             throws PfModelException;
169
170     /**
171      * Update policy types.
172      *
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
176      */
177     public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
178             throws PfModelException;
179
180     /**
181      * Delete policy type.
182      *
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
187      */
188     public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
189             throws PfModelException;
190
191     /**
192      * Get policies.
193      *
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
198      */
199     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
200
201     /**
202      * Get policies.
203      *
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
208      */
209     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
210
211     /**
212      * Get filtered policies.
213      *
214      * @param filter the filter for the policies to get
215      * @return the policies found
216      * @throws PfModelException on errors getting policies
217      */
218     public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
219             throws PfModelException;
220
221     /**
222      * Get filtered policies.
223      *
224      * @param filter the filter for the policies to get
225      * @return the policies found
226      * @throws PfModelException on errors getting policies
227      */
228     public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
229             throws PfModelException;
230
231     /**
232      * Create policies.
233      *
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
237      */
238     public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
239             throws PfModelException;
240
241     /**
242      * Update policies.
243      *
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
247      */
248     public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
249             throws PfModelException;
250
251     /**
252      * Delete policy.
253      *
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
258      */
259     public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
260             throws PfModelException;
261
262
263     /**
264      * Create tosca node templates.
265      *
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
269      */
270     public ToscaServiceTemplate createToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
271         throws PfModelException;
272
273     /**
274      * Update tosca node templates.
275      *
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
279      */
280     public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
281         throws PfModelRuntimeException, PfModelException;
282
283     /**
284      * Delete a tosca node template.
285      *
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
290      */
291     public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @NonNull final String version)
292         throws PfModelException;
293
294
295     /**
296      * Get filtered node template metadataSet entities.
297      *
298      * @return the list of metadataSet found
299      * @throws PfModelException on errors getting node template metadataSet
300      */
301     public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(final String name,
302                                                                                       final String version)
303         throws PfModelException;
304
305     /**
306      * Get filtered node template entities.
307      *
308      * @return the list of nodeTemplates found
309      * @throws PfModelException on errors getting node template
310      */
311     public List<Map<PfConceptKey, ToscaNodeTemplate>> getToscaNodeTemplate(final String name,
312                                                                            final String version)
313         throws PfModelException;
314
315     /**
316      * Get PDP groups.
317      *
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
321      */
322     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
323
324     /**
325      * Get filtered PDP groups.
326      *
327      * @param filter the filter for the PDP groups to get
328      * @return the PDP groups found
329      * @throws PfModelException on errors getting policies
330      */
331     public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
332
333     /**
334      * Creates PDP groups.
335      *
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
339      */
340     public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
341
342     /**
343      * Updates PDP groups.
344      *
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
348      */
349     public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
350
351     /**
352      * Update a PDP subgroup.
353      *
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
357      */
358     public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
359             throws PfModelException;
360
361     /**
362      * Update a PDP.
363      *
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
368      */
369     public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
370             throws PfModelException;
371
372     /**
373      * Delete a PDP group.
374      *
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
378      */
379     public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
380
381
382     /**
383      * Get filtered PdpStatistics.
384      *
385      * @param filterParams filter parameters
386      * @return the PDP statistics found
387      * @throws PfModelException on errors getting policies
388      */
389     public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException;
390
391     /**
392      * Creates PDP statistics.
393      *
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
397      */
398     public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
399             throws PfModelException;
400
401     /**
402      * Updates PDP statistics.
403      *
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
407      */
408     public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
409             throws PfModelException;
410
411     /**
412      * Delete a PDP statistics.
413      *
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
418      */
419     public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Instant timestamp) throws PfModelException;
420
421     /**
422      * Gets all policy deployments.
423      *
424      * @return the deployments found
425      * @throws PfModelException on errors getting PDP groups
426      */
427     public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException;
428
429     /**
430      * Gets all deployments for a policy.
431      *
432      * @return the deployments found
433      * @throws PfModelException on errors getting PDP groups
434      */
435     public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
436             throws PfModelException;
437
438     /**
439      * Gets the policy deployments for a PDP group.
440      *
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
444      */
445     public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException;
446
447     /**
448      * Creates, updates, and deletes collections of policy status.
449      *
450      * @param createObjs the objects to create
451      * @param updateObjs the objects to update
452      * @param deleteObjs the objects to delete
453      */
454     public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
455             Collection<PdpPolicyStatus> deleteObjs);
456
457     /**
458      * Creates records for audit actions on policies.
459      *
460      * @param auditRecords the objects to create
461      */
462     public void createAuditRecords(@NonNull List<PolicyAudit> auditRecords);
463
464     /**
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
468      */
469     public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter);
470 }