767a0fb6fb91681b01298e86720e06eef8df98e2
[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  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.provider;
22
23 import java.util.Date;
24 import java.util.List;
25 import java.util.Map;
26 import lombok.NonNull;
27 import org.onap.policy.models.base.PfModelException;
28 import org.onap.policy.models.pdp.concepts.Pdp;
29 import org.onap.policy.models.pdp.concepts.PdpGroup;
30 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
31 import org.onap.policy.models.pdp.concepts.PdpStatistics;
32 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
38 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
39 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
40 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
41
42 /**
43  * This interface describes the operations that are provided to users and components for reading objects from and
44  * writing objects to the database.
45  *
46  * @author Liam Fallon (liam.fallon@est.tech)
47  */
48 public interface PolicyModelsProvider extends AutoCloseable {
49     /**
50      * Open the policy model provider initializing whatever internal handling it needs.
51      *
52      * @throws PfModelException on errors opening the models provider
53      */
54     public void init() throws PfModelException;
55
56     @Override
57     public void close() throws PfModelException;
58
59     /**
60      * Get policy types.
61      *
62      * @param name the name of the policy type to get, set to null to get all policy types
63      * @param version the version of the policy type to get, set to null to get all versions
64      * @return the policy types found
65      * @throws PfModelException on errors getting policy types
66      */
67     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
68
69     /**
70      * Get policy types.
71      *
72      * @param name the name of the policy type to get, set to null to get all policy types
73      * @param version the version of the policy type to get, set to null to get all versions
74      * @return the policy types found
75      * @throws PfModelException on errors getting policy types
76      */
77     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
78
79     /**
80      * Get filtered policy types.
81      *
82      * @param filter the filter for the policy types to get
83      * @return the policy types found
84      * @throws PfModelException on errors getting policy types
85      */
86     public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaPolicyTypeFilter filter)
87             throws PfModelException;
88
89     /**
90      * Get filtered policy types.
91      *
92      * @param filter the filter for the policy types to get
93      * @return the policy types found
94      * @throws PfModelException on errors getting policy types
95      */
96     public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaPolicyTypeFilter filter)
97             throws PfModelException;
98
99     /**
100      * Create policy types.
101      *
102      * @param serviceTemplate the service template containing the definition of the policy types to be created
103      * @return the TOSCA service template containing the created policy types
104      * @throws PfModelException on errors creating policy types
105      */
106     public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
107             throws PfModelException;
108
109     /**
110      * Create policy types.
111      *
112      * @param serviceTemplate the service template containing the definition of the policy types to be modified
113      * @return the TOSCA service template containing the modified policy types
114      * @throws PfModelException on errors updating policy types
115      */
116     public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
117             throws PfModelException;
118
119     /**
120      * Delete policy type.
121      *
122      * @param name the name of the policy type to delete.
123      * @param version the version of the policy type to delete.
124      * @return the TOSCA service template containing the policy type that was deleted
125      * @throws PfModelException on errors deleting policy types
126      */
127     public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
128             throws PfModelException;
129
130     /**
131      * Get policies.
132      *
133      * @param name the name of the policy to get, null to get all policies
134      * @param version the version of the policy to get, null to get all versions of a policy
135      * @return the policies found
136      * @throws PfModelException on errors getting policies
137      */
138     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
139
140     /**
141      * Get policies.
142      *
143      * @param name the name of the policy to get, null to get all policies
144      * @param version the version of the policy to get, null to get all versions of a policy
145      * @return the policies found
146      * @throws PfModelException on errors getting policies
147      */
148     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
149
150     /**
151      * Get filtered policies.
152      *
153      * @param filter the filter for the policies to get
154      * @return the policies found
155      * @throws PfModelException on errors getting policies
156      */
157     public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
158
159     /**
160      * Get filtered policies.
161      *
162      * @param filter the filter for the policies to get
163      * @return the policies found
164      * @throws PfModelException on errors getting policies
165      */
166     public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
167
168     /**
169      * Create policies.
170      *
171      * @param serviceTemplate the service template containing the definitions of the new policies to be created.
172      * @return the TOSCA service template containing the policy types that were created
173      * @throws PfModelException on errors creating policies
174      */
175     public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
176             throws PfModelException;
177
178     /**
179      * Update policies.
180      *
181      * @param serviceTemplate the service template containing the definitions of the policies to be updated.
182      * @return the TOSCA service template containing the policies that were updated
183      * @throws PfModelException on errors updating policies
184      */
185     public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
186             throws PfModelException;
187
188     /**
189      * Delete policy.
190      *
191      * @param name the name of the policy to delete.
192      * @param version the version of the policy to delete.
193      * @return the TOSCA service template containing the policy that was deleted
194      * @throws PfModelException on errors deleting a policy
195      */
196     public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
197             throws PfModelException;
198
199     /**
200      * Get legacy operational policy.
201      *
202      * @param policyId ID of the policy
203      * @param policyVersion version of the policy, set to null to get the latest policy
204      * @return the policies found
205      * @throws PfModelException on errors getting policies
206      */
207     public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion)
208             throws PfModelException;
209
210     /**
211      * Create legacy operational policy.
212      *
213      * @param legacyOperationalPolicy the definition of the policy to be created.
214      * @return the created policy
215      * @throws PfModelException on errors creating policies
216      */
217     public LegacyOperationalPolicy createOperationalPolicy(
218             @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
219
220     /**
221      * Update legacy operational policy.
222      *
223      * @param legacyOperationalPolicy the definition of the policy to be updated
224      * @return the updated policy
225      * @throws PfModelException on errors updating policies
226      */
227     public LegacyOperationalPolicy updateOperationalPolicy(
228             @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
229
230     /**
231      * Delete legacy operational policy.
232      *
233      * @param policyId ID of the policy.
234      * @param policyVersion version of the policy
235      * @return the deleted policy
236      * @throws PfModelException on errors deleting policies
237      */
238     public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId,
239             @NonNull final String policyVersion) throws PfModelException;
240
241     /**
242      * Get legacy guard policy.
243      *
244      * @param policyId ID of the policy
245      * @param policyVersion version of the policy, set to null to get the latest policy
246      * @return the policies found
247      * @throws PfModelException on errors getting policies
248      */
249     public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId,
250             final String policyVersion) throws PfModelException;
251
252     /**
253      * Create legacy guard policy.
254      *
255      * @param legacyGuardPolicy the definition of the policy to be created.
256      * @return the created policy
257      * @throws PfModelException on errors creating policies
258      */
259     public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
260             @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
261
262     /**
263      * Update legacy guard policy.
264      *
265      * @param legacyGuardPolicy the definition of the policy to be updated
266      * @return the updated policy
267      * @throws PfModelException on errors updating policies
268      */
269     public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
270             @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
271
272     /**
273      * Delete legacy guard policy.
274      *
275      * @param policyId ID of the policy.
276      * @param policyVersion version of the policy
277      * @return the deleted policy
278      * @throws PfModelException on errors deleting policies
279      */
280     public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId,
281             @NonNull final String policyVersion) throws PfModelException;
282
283     /**
284      * Get PDP groups.
285      *
286      * @param name the name of the policy to get, null to get all PDP groups
287      * @return the PDP groups found
288      * @throws PfModelException on errors getting PDP groups
289      */
290     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
291
292     /**
293      * Get filtered PDP groups.
294      *
295      * @param filter the filter for the PDP groups to get
296      * @return the PDP groups found
297      * @throws PfModelException on errors getting policies
298      */
299     public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
300
301     /**
302      * Creates PDP groups.
303      *
304      * @param pdpGroups a specification of the PDP groups to create
305      * @return the PDP groups created
306      * @throws PfModelException on errors creating PDP groups
307      */
308     public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
309
310     /**
311      * Updates PDP groups.
312      *
313      * @param pdpGroups a specification of the PDP groups to update
314      * @return the PDP groups updated
315      * @throws PfModelException on errors updating PDP groups
316      */
317     public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
318
319     /**
320      * Update a PDP subgroup.
321      *
322      * @param pdpGroupName the name of the PDP group of the PDP subgroup
323      * @param pdpSubGroup the PDP subgroup to be updated
324      * @throws PfModelException on errors updating PDP subgroups
325      */
326     public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
327             throws PfModelException;
328
329     /**
330      * Update a PDP.
331      *
332      * @param pdpGroupName the name of the PDP group of the PDP subgroup
333      * @param pdpSubGroup the PDP subgroup to be updated
334      * @param pdp the PDP to be updated
335      * @throws PfModelException on errors updating PDP subgroups
336      */
337     public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
338             throws PfModelException;
339
340     /**
341      * Delete a PDP group.
342      *
343      * @param name the name of the policy to get, null to get all PDP groups
344      * @return the PDP group deleted
345      * @throws PfModelException on errors deleting PDP groups
346      */
347     public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
348
349     /**
350      * Get PDP statistics.
351      *
352      * @param name the name of the PDP group to get statistics for, null to get all PDP groups
353      * @return the statistics found
354      * @throws PfModelException on errors getting statistics
355      */
356     public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException;
357
358
359     /**
360      * Get filtered PdpStatistics.
361      *
362      * @param name the pdpInstance name for the PDP statistics to get
363      * @param pdpGroupName pdpGroupName to filter statistics
364      * @param pdpSubGroup pdpSubGroupType name to filter statistics
365      * @param startTimeStamp startTimeStamp to filter statistics
366      * @param endTimeStamp endTimeStamp to filter statistics
367      * @param sortOrder sortOrder to query database
368      * @param getRecordNum Total query count from database
369      * @return the PDP statistics found
370      * @throws PfModelException on errors getting policies
371      */
372     public List<PdpStatistics> getFilteredPdpStatistics(String name, @NonNull String pdpGroupName, String pdpSubGroup,
373             Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException;
374
375     /**
376      * Creates PDP statistics.
377      *
378      * @param pdpStatisticsList a specification of the PDP statistics to create
379      * @return the PDP statistics created
380      * @throws PfModelException on errors creating PDP statistics
381      */
382     public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
383             throws PfModelException;
384
385     /**
386      * Updates PDP statistics.
387      *
388      * @param pdpStatisticsList a specification of the PDP statistics to update
389      * @return the PDP statistics updated
390      * @throws PfModelException on errors updating PDP statistics
391      */
392     public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
393             throws PfModelException;
394
395     /**
396      * Delete a PDP statistics.
397      *
398      * @param name the name of the policy to get, null to get all PDP statistics
399      * @param timestamp the timestamp of statistics to delete, null to delete all statistics record of given pdp
400      * @return the PDP statistics deleted
401      * @throws PfModelException on errors deleting PDP statistics
402      */
403     public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Date timestamp) throws PfModelException;
404 }