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