Fix sonar in policy/models
[policy/models.git] / models-provider / src / main / java / org / onap / policy / models / provider / PolicyModelsProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2021 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 lombok.NonNull;
29 import org.onap.policy.models.base.PfModelException;
30 import org.onap.policy.models.pap.concepts.PolicyAudit;
31 import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
32 import org.onap.policy.models.pdp.concepts.Pdp;
33 import org.onap.policy.models.pdp.concepts.PdpGroup;
34 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
35 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
36 import org.onap.policy.models.pdp.concepts.PdpStatistics;
37 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
44
45 /**
46  * This interface describes the operations that are provided to users and components for reading objects from and
47  * writing objects to the database.
48  *
49  * @author Liam Fallon (liam.fallon@est.tech)
50  */
51 public interface PolicyModelsProvider extends AutoCloseable {
52     /**
53      * Open the policy model provider initializing whatever internal handling it needs.
54      *
55      * @throws PfModelException on errors opening the models provider
56      */
57     public void init() throws PfModelException;
58
59     @Override
60     public void close() throws PfModelException;
61
62     /**
63      * Get service templates.
64      *
65      * @param name the name of the topology template to get, set to null to get all service templates
66      * @param version the version of the service template to get, set to null to get all service templates
67      * @return the topology templates found
68      * @throws PfModelException on errors getting service templates
69      */
70     public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version)
71             throws PfModelException;
72
73     /**
74      * Get filtered service templates.
75      *
76      * @param filter the filter for the service templates to get
77      * @return the service templates found
78      * @throws PfModelException on errors getting service templates
79      */
80     public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
81             @NonNull final ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException;
82
83     /**
84      * Create service template.
85      *
86      * @param serviceTemplate the service template to be created
87      * @return the created service template
88      * @throws PfModelException on errors creating the service template
89      */
90     public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
91             throws PfModelException;
92
93     /**
94      * Update service template.
95      *
96      * @param serviceTemplate the service template to be updated
97      * @return the updated service template
98      * @throws PfModelException on errors updating the service template
99      */
100     public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
101             throws PfModelException;
102
103     /**
104      * Delete service template.
105      *
106      * @param name the name of the service template to delete.
107      * @param version the version of the service template to delete.
108      * @return the TOSCA service template that was deleted
109      * @throws PfModelException on errors deleting policy types
110      */
111     public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version)
112             throws PfModelException;
113
114     /**
115      * Get policy types.
116      *
117      * @param name the name of the policy type to get, set to null to get all policy types
118      * @param version the version of the policy type to get, set to null to get all versions
119      * @return the policy types found
120      * @throws PfModelException on errors getting policy types
121      */
122     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
123
124     /**
125      * Get policy types.
126      *
127      * @param name the name of the policy type to get, set to null to get all policy types
128      * @param version the version of the policy type to get, set to null to get all versions
129      * @return the policy types found
130      * @throws PfModelException on errors getting policy types
131      */
132     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
133
134     /**
135      * Get filtered policy types.
136      *
137      * @param filter the filter for the policy types to get
138      * @return the policy types found
139      * @throws PfModelException on errors getting policy types
140      */
141     public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
142             throws PfModelException;
143
144     /**
145      * Get filtered policy types.
146      *
147      * @param filter the filter for the policy types to get
148      * @return the policy types found
149      * @throws PfModelException on errors getting policy types
150      */
151     public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
152             throws PfModelException;
153
154     /**
155      * Create policy types.
156      *
157      * @param serviceTemplate the service template containing the definition of the policy types to be created
158      * @return the TOSCA service template containing the created policy types
159      * @throws PfModelException on errors creating policy types
160      */
161     public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
162             throws PfModelException;
163
164     /**
165      * Update policy types.
166      *
167      * @param serviceTemplate the service template containing the definition of the policy types to be modified
168      * @return the TOSCA service template containing the modified policy types
169      * @throws PfModelException on errors updating policy types
170      */
171     public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
172             throws PfModelException;
173
174     /**
175      * Delete policy type.
176      *
177      * @param name the name of the policy type to delete.
178      * @param version the version of the policy type to delete.
179      * @return the TOSCA service template containing the policy type that was deleted
180      * @throws PfModelException on errors deleting the policy type
181      */
182     public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
183             throws PfModelException;
184
185     /**
186      * Get policies.
187      *
188      * @param name the name of the policy to get, null to get all policies
189      * @param version the version of the policy to get, null to get all versions of a policy
190      * @return the policies found
191      * @throws PfModelException on errors getting policies
192      */
193     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
194
195     /**
196      * Get policies.
197      *
198      * @param name the name of the policy to get, null to get all policies
199      * @param version the version of the policy to get, null to get all versions of a policy
200      * @return the policies found
201      * @throws PfModelException on errors getting policies
202      */
203     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
204
205     /**
206      * Get filtered policies.
207      *
208      * @param filter the filter for the policies to get
209      * @return the policies found
210      * @throws PfModelException on errors getting policies
211      */
212     public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
213             throws PfModelException;
214
215     /**
216      * Get filtered policies.
217      *
218      * @param filter the filter for the policies to get
219      * @return the policies found
220      * @throws PfModelException on errors getting policies
221      */
222     public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
223             throws PfModelException;
224
225     /**
226      * Create policies.
227      *
228      * @param serviceTemplate the service template containing the definitions of the new policies to be created.
229      * @return the TOSCA service template containing the policy types that were created
230      * @throws PfModelException on errors creating policies
231      */
232     public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
233             throws PfModelException;
234
235     /**
236      * Update policies.
237      *
238      * @param serviceTemplate the service template containing the definitions of the policies to be updated.
239      * @return the TOSCA service template containing the policies that were updated
240      * @throws PfModelException on errors updating policies
241      */
242     public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
243             throws PfModelException;
244
245     /**
246      * Delete policy.
247      *
248      * @param name the name of the policy to delete.
249      * @param version the version of the policy to delete.
250      * @return the TOSCA service template containing the policy that was deleted
251      * @throws PfModelException on errors deleting a policy
252      */
253     public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
254             throws PfModelException;
255
256     /**
257      * Get PDP groups.
258      *
259      * @param name the name of the policy to get, null to get all PDP groups
260      * @return the PDP groups found
261      * @throws PfModelException on errors getting PDP groups
262      */
263     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
264
265     /**
266      * Get filtered PDP groups.
267      *
268      * @param filter the filter for the PDP groups to get
269      * @return the PDP groups found
270      * @throws PfModelException on errors getting policies
271      */
272     public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
273
274     /**
275      * Creates PDP groups.
276      *
277      * @param pdpGroups a specification of the PDP groups to create
278      * @return the PDP groups created
279      * @throws PfModelException on errors creating PDP groups
280      */
281     public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
282
283     /**
284      * Updates PDP groups.
285      *
286      * @param pdpGroups a specification of the PDP groups to update
287      * @return the PDP groups updated
288      * @throws PfModelException on errors updating PDP groups
289      */
290     public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
291
292     /**
293      * Update a PDP subgroup.
294      *
295      * @param pdpGroupName the name of the PDP group of the PDP subgroup
296      * @param pdpSubGroup the PDP subgroup to be updated
297      * @throws PfModelException on errors updating PDP subgroups
298      */
299     public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
300             throws PfModelException;
301
302     /**
303      * Update a PDP.
304      *
305      * @param pdpGroupName the name of the PDP group of the PDP subgroup
306      * @param pdpSubGroup the PDP subgroup to be updated
307      * @param pdp the PDP to be updated
308      * @throws PfModelException on errors updating PDP subgroups
309      */
310     public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
311             throws PfModelException;
312
313     /**
314      * Delete a PDP group.
315      *
316      * @param name the name of the policy to get, null to get all PDP groups
317      * @return the PDP group deleted
318      * @throws PfModelException on errors deleting PDP groups
319      */
320     public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
321
322     /**
323      * Get PDP statistics.
324      *
325      * @param name the name of the PDP group to get statistics for, null to get all PDP groups
326      * @return the statistics found
327      * @throws PfModelException on errors getting statistics
328      */
329     public List<PdpStatistics> getPdpStatistics(final String name, final Instant timestamp) throws PfModelException;
330
331
332     /**
333      * Get filtered PdpStatistics.
334      *
335      * @param name the pdpInstance name for the PDP statistics to get
336      * @param pdpGroupName pdpGroupName to filter statistics
337      * @param pdpSubGroup pdpSubGroupType name to filter statistics
338      * @param startTimeStamp startTimeStamp to filter statistics
339      * @param endTimeStamp endTimeStamp to filter statistics
340      * @param sortOrder sortOrder to query database
341      * @param getRecordNum Total query count from database
342      * @return the PDP statistics found
343      * @throws PfModelException on errors getting policies
344      */
345     public List<PdpStatistics> getFilteredPdpStatistics(String name, @NonNull String pdpGroupName, String pdpSubGroup,
346             Instant startTimeStamp, Instant endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException;
347
348     /**
349      * Creates PDP statistics.
350      *
351      * @param pdpStatisticsList a specification of the PDP statistics to create
352      * @return the PDP statistics created
353      * @throws PfModelException on errors creating PDP statistics
354      */
355     public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
356             throws PfModelException;
357
358     /**
359      * Updates PDP statistics.
360      *
361      * @param pdpStatisticsList a specification of the PDP statistics to update
362      * @return the PDP statistics updated
363      * @throws PfModelException on errors updating PDP statistics
364      */
365     public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
366             throws PfModelException;
367
368     /**
369      * Delete a PDP statistics.
370      *
371      * @param name the name of the policy to get, null to get all PDP statistics
372      * @param timestamp the timestamp of statistics to delete, null to delete all statistics record of given pdp
373      * @return the PDP statistics deleted
374      * @throws PfModelException on errors deleting PDP statistics
375      */
376     public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Instant timestamp) throws PfModelException;
377
378     /**
379      * Gets all policy deployments.
380      *
381      * @return the deployments found
382      * @throws PfModelException on errors getting PDP groups
383      */
384     public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException;
385
386     /**
387      * Gets all deployments for a policy.
388      *
389      * @return the deployments found
390      * @throws PfModelException on errors getting PDP groups
391      */
392     public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
393             throws PfModelException;
394
395     /**
396      * Gets the policy deployments for a PDP group.
397      *
398      * @param groupName the name of the PDP group of interest, null to get results for all PDP groups
399      * @return the deployments found
400      * @throws PfModelException on errors getting PDP groups
401      */
402     public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException;
403
404     /**
405      * Creates, updates, and deletes collections of policy status.
406      *
407      * @param createObjs the objects to create
408      * @param updateObjs the objects to update
409      * @param deleteObjs the objects to delete
410      */
411     public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
412             Collection<PdpPolicyStatus> deleteObjs);
413
414     /**
415      * Creates records for audit actions on policies.
416      *
417      * @param auditRecords the objects to create
418      */
419     public void createAuditRecords(@NonNull List<PolicyAudit> auditRecords);
420
421     /**
422      * Collect the audit records.
423      * @param auditFilter filter for search
424      * @param numRecords max number of records to be collected
425      * @return list of {@link PolicyAudit} or empty if none or not match with filter
426      */
427     public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter,  @NonNull Integer numRecords);
428 }