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