Add PDP-Policy deployment table to DB
[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.ToscaPolicy;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter;
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(@NonNull final ToscaServiceTemplateFilter filter)
79             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 ToscaPolicyTypeFilter 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 ToscaPolicyTypeFilter 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 ToscaPolicyFilter filter) throws PfModelException;
211
212     /**
213      * Get filtered policies.
214      *
215      * @param filter the filter for the policies to get
216      * @return the policies found
217      * @throws PfModelException on errors getting policies
218      */
219     public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
220
221     /**
222      * Create policies.
223      *
224      * @param serviceTemplate the service template containing the definitions of the new policies to be created.
225      * @return the TOSCA service template containing the policy types that were created
226      * @throws PfModelException on errors creating policies
227      */
228     public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
229             throws PfModelException;
230
231     /**
232      * Update policies.
233      *
234      * @param serviceTemplate the service template containing the definitions of the policies to be updated.
235      * @return the TOSCA service template containing the policies that were updated
236      * @throws PfModelException on errors updating policies
237      */
238     public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
239             throws PfModelException;
240
241     /**
242      * Delete policy.
243      *
244      * @param name the name of the policy to delete.
245      * @param version the version of the policy to delete.
246      * @return the TOSCA service template containing the policy that was deleted
247      * @throws PfModelException on errors deleting a policy
248      */
249     public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
250             throws PfModelException;
251
252     /**
253      * Get PDP groups.
254      *
255      * @param name the name of the policy to get, null to get all PDP groups
256      * @return the PDP groups found
257      * @throws PfModelException on errors getting PDP groups
258      */
259     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
260
261     /**
262      * Get filtered PDP groups.
263      *
264      * @param filter the filter for the PDP groups to get
265      * @return the PDP groups found
266      * @throws PfModelException on errors getting policies
267      */
268     public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
269
270     /**
271      * Creates PDP groups.
272      *
273      * @param pdpGroups a specification of the PDP groups to create
274      * @return the PDP groups created
275      * @throws PfModelException on errors creating PDP groups
276      */
277     public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
278
279     /**
280      * Updates PDP groups.
281      *
282      * @param pdpGroups a specification of the PDP groups to update
283      * @return the PDP groups updated
284      * @throws PfModelException on errors updating PDP groups
285      */
286     public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
287
288     /**
289      * Update a PDP subgroup.
290      *
291      * @param pdpGroupName the name of the PDP group of the PDP subgroup
292      * @param pdpSubGroup the PDP subgroup to be updated
293      * @throws PfModelException on errors updating PDP subgroups
294      */
295     public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
296             throws PfModelException;
297
298     /**
299      * Update a PDP.
300      *
301      * @param pdpGroupName the name of the PDP group of the PDP subgroup
302      * @param pdpSubGroup the PDP subgroup to be updated
303      * @param pdp the PDP to be updated
304      * @throws PfModelException on errors updating PDP subgroups
305      */
306     public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
307             throws PfModelException;
308
309     /**
310      * Delete a PDP group.
311      *
312      * @param name the name of the policy to get, null to get all PDP groups
313      * @return the PDP group deleted
314      * @throws PfModelException on errors deleting PDP groups
315      */
316     public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
317
318     /**
319      * Get PDP statistics.
320      *
321      * @param name the name of the PDP group to get statistics for, null to get all PDP groups
322      * @return the statistics found
323      * @throws PfModelException on errors getting statistics
324      */
325     public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException;
326
327
328     /**
329      * Get filtered PdpStatistics.
330      *
331      * @param name the pdpInstance name for the PDP statistics to get
332      * @param pdpGroupName pdpGroupName to filter statistics
333      * @param pdpSubGroup pdpSubGroupType name to filter statistics
334      * @param startTimeStamp startTimeStamp to filter statistics
335      * @param endTimeStamp endTimeStamp to filter statistics
336      * @param sortOrder sortOrder to query database
337      * @param getRecordNum Total query count from database
338      * @return the PDP statistics found
339      * @throws PfModelException on errors getting policies
340      */
341     public List<PdpStatistics> getFilteredPdpStatistics(String name, @NonNull String pdpGroupName, String pdpSubGroup,
342             Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException;
343
344     /**
345      * Creates PDP statistics.
346      *
347      * @param pdpStatisticsList a specification of the PDP statistics to create
348      * @return the PDP statistics created
349      * @throws PfModelException on errors creating PDP statistics
350      */
351     public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
352             throws PfModelException;
353
354     /**
355      * Updates PDP statistics.
356      *
357      * @param pdpStatisticsList a specification of the PDP statistics to update
358      * @return the PDP statistics updated
359      * @throws PfModelException on errors updating PDP statistics
360      */
361     public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
362             throws PfModelException;
363
364     /**
365      * Delete a PDP statistics.
366      *
367      * @param name the name of the policy to get, null to get all PDP statistics
368      * @param timestamp the timestamp of statistics to delete, null to delete all statistics record of given pdp
369      * @return the PDP statistics deleted
370      * @throws PfModelException on errors deleting PDP statistics
371      */
372     public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Date timestamp) throws PfModelException;
373
374     /**
375      * Gets the policy deployments for a PDP group.
376      *
377      * @param groupName the name of the PDP group of interest, null to get results for all
378      *        PDP groups
379      * @return the deployments found
380      * @throws PfModelException on errors getting PDP groups
381      */
382     public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName)
383                     throws PfModelException;
384
385     /**
386      * Creates, updates, and deletes collections of policy status.
387      *
388      * @param createObjs the objects to create
389      * @param updateObjs the objects to update
390      * @param deleteObjs the objects to delete
391      */
392     public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs,
393                     Collection<PdpPolicyStatus> updateObjs, Collection<PdpPolicyStatus> deleteObjs);
394 }