af1c88f2be477b44a78cbf409b8123dfa4201bd7
[policy/models.git] / models-provider / src / main / java / org / onap / policy / models / provider / PolicyModelsProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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.List;
24 import java.util.Map;
25
26 import lombok.NonNull;
27
28 import org.apache.commons.lang3.tuple.Pair;
29 import org.onap.policy.models.base.PfModelException;
30 import org.onap.policy.models.pdp.concepts.PdpGroup;
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.ToscaPolicyType;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
36 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
37 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
38 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
39
40 /**
41  * This interface describes the operations that are provided to users and components for reading objects from and
42  * writing objects to the database.
43  *
44  * @author Liam Fallon (liam.fallon@est.tech)
45  */
46 public interface PolicyModelsProvider extends AutoCloseable {
47     /**
48      * Open the policy model provider initializing whatever internal handling it needs.
49      *
50      * @throws PfModelException on errors opening the models provider
51      */
52     public void init() throws PfModelException;
53
54     @Override
55     public void close() throws PfModelException;
56
57     /**
58      * Get policy types.
59      *
60      * @param name the name of the policy type to get, set to null to get all policy types
61      * @param version the version of the policy type to get, set to null to get all versions
62      * @return the policy types found
63      * @throws PfModelException on errors getting policy types
64      */
65     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
66
67     /**
68      * Get policy types.
69      *
70      * @param name the name of the policy type to get, set to null to get all policy types
71      * @param version the version of the policy type to get, set to null to get all versions
72      * @return the policy types found
73      * @throws PfModelException on errors getting policy types
74      */
75     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
76
77     /**
78      * Get latest policy types.
79      *
80      * @param name the name of the policy type to get, set to null to get all policy types
81      * @return the policy types found
82      * @throws PfModelException on errors getting policy types
83      */
84     public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException;
85
86     /**
87      * Get latest policy types.
88      *
89      * @param name the name of the policy type to get, set to null to get all policy types
90      * @return the policy types found
91      * @throws PfModelException on errors getting policy types
92      */
93     public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException;
94
95     /**
96      * Create policy types.
97      *
98      * @param serviceTemplate the service template containing the definition of the policy types to be created
99      * @return the TOSCA service template containing the created policy types
100      * @throws PfModelException on errors creating policy types
101      */
102     public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
103             throws PfModelException;
104
105     /**
106      * Create policy types.
107      *
108      * @param serviceTemplate the service template containing the definition of the policy types to be modified
109      * @return the TOSCA service template containing the modified policy types
110      * @throws PfModelException on errors updating policy types
111      */
112     public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
113             throws PfModelException;
114
115     /**
116      * Delete policy type.
117      *
118      * @param name the name of the policy type to delete.
119      * @param version the version of the policy type to delete.
120      * @return the TOSCA service template containing the policy type that was deleted
121      * @throws PfModelException on errors deleting policy types
122      */
123     public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
124             throws PfModelException;
125
126     /**
127      * Get policies.
128      *
129      * @param name the name of the policy to get, null to get all policies
130      * @param version the version of the policy to get, null to get all versions of a policy
131      * @return the policies found
132      * @throws PfModelException on errors getting policies
133      */
134     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
135
136     /**
137      * Get policies.
138      *
139      * @param name the name of the policy to get, null to get all policies
140      * @param version the version of the policy to get, null to get all versions of a policy
141      * @return the policies found
142      * @throws PfModelException on errors getting policies
143      */
144     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
145
146     /**
147      * Get policies for a policy type name.
148      *
149      * @param policyTypeName the name of the policy type for which to get policies
150      * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
151      *        policy types
152      * @return the policies found
153      * @throws PfModelException on errors getting policies
154      */
155     public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
156             final String policyTypeVersion) throws PfModelException;
157
158     /**
159      * Get latest policies.
160      *
161      * @param name the name of the policy to get, null to get all policies
162      * @return the policies found
163      * @throws PfModelException on errors getting policies
164      */
165     public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException;
166
167     /**
168      * Get latest policies.
169      *
170      * @param name the name of the policy to get, null to get all policies
171      * @return the policies found
172      * @throws PfModelException on errors getting policies
173      */
174     public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException;
175
176     /**
177      * Create policies.
178      *
179      * @param serviceTemplate the service template containing the definitions of the new policies to be created.
180      * @return the TOSCA service template containing the policy types that were created
181      * @throws PfModelException on errors creating policies
182      */
183     public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
184             throws PfModelException;
185
186     /**
187      * Update policies.
188      *
189      * @param serviceTemplate the service template containing the definitions of the policies to be updated.
190      * @return the TOSCA service template containing the policies that were updated
191      * @throws PfModelException on errors updating policies
192      */
193     public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
194             throws PfModelException;
195
196     /**
197      * Delete policy.
198      *
199      * @param name the name of the policy to delete.
200      * @param version the version of the policy to delete.
201      * @return the TOSCA service template containing the policy that was deleted
202      * @throws PfModelException on errors deleting a policy
203      */
204     public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
205             throws PfModelException;
206
207     /**
208      * Get legacy operational policy.
209      *
210      * @param policyId ID of the policy.
211      * @return the policies found
212      * @throws PfModelException on errors getting policies
213      */
214     public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException;
215
216     /**
217      * Create legacy operational policy.
218      *
219      * @param legacyOperationalPolicy the definition of the policy to be created.
220      * @return the created policy
221      * @throws PfModelException on errors creating policies
222      */
223     public LegacyOperationalPolicy createOperationalPolicy(
224             @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
225
226     /**
227      * Update legacy operational policy.
228      *
229      * @param legacyOperationalPolicy the definition of the policy to be updated
230      * @return the updated policy
231      * @throws PfModelException on errors updating policies
232      */
233     public LegacyOperationalPolicy updateOperationalPolicy(
234             @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
235
236     /**
237      * Delete legacy operational policy.
238      *
239      * @param policyId ID of the policy.
240      * @return the deleted policy
241      * @throws PfModelException on errors deleting policies
242      */
243     public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException;
244
245     /**
246      * Get legacy guard policy.
247      *
248      * @param policyId ID of the policy.
249      * @return the policies found
250      * @throws PfModelException on errors getting policies
251      */
252     public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException;
253
254     /**
255      * Create legacy guard policy.
256      *
257      * @param legacyGuardPolicy the definition of the policy to be created.
258      * @return the created policy
259      * @throws PfModelException on errors creating policies
260      */
261     public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
262             @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
263
264     /**
265      * Update legacy guard policy.
266      *
267      * @param legacyGuardPolicy the definition of the policy to be updated
268      * @return the updated policy
269      * @throws PfModelException on errors updating policies
270      */
271     public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
272             @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
273
274     /**
275      * Delete legacy guard policy.
276      *
277      * @param policyId ID of the policy.
278      * @return the deleted policy
279      * @throws PfModelException on errors deleting policies
280      */
281     public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
282             throws PfModelException;
283
284     /**
285      * Get PDP groups.
286      *
287      * @param name the name of the policy to get, null to get all PDP groups
288      * @param version the version of the policy to get, null to get all versions of a PDP group
289      * @return the PDP groups found
290      * @throws PfModelException on errors getting PDP groups
291      */
292     public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException;
293
294     /**
295      * Get latest PDP Groups, returns PDP groups in all states.
296      *
297      * @param name the name of the PDP group to get, null to get all PDP groups
298      * @return the PDP groups found
299      * @throws PfModelException on errors getting policies
300      */
301     public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException;
302
303     /**
304      * Get a filtered list of PDP groups, returns only active PDP groups.
305      *
306      * @param pdpType The PDP type filter for the returned PDP groups, null to get policy types across PDP subgroups
307      * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
308      * @return the PDP groups found
309      */
310     public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
311             @NonNull final List<Pair<String, String>> supportedPolicyTypes);
312
313     /**
314      * Creates PDP groups.
315      *
316      * @param pdpGroups a specification of the PDP groups to create
317      * @return the PDP groups created
318      * @throws PfModelException on errors creating PDP groups
319      */
320     public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
321
322     /**
323      * Updates PDP groups.
324      *
325      * @param pdpGroups a specification of the PDP groups to update
326      * @return the PDP groups updated
327      * @throws PfModelException on errors updating PDP groups
328      */
329     public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
330
331
332     /**
333      * Update a PDP subgroup.
334      *
335      * @param pdpGroupName the name of the PDP group of the PDP subgroup
336      * @param pdpGroupVersion the version of the PDP group of the PDP subgroup
337      * @param pdpSubGroup the PDP subgroup to be updated
338      * @throws PfModelException on errors updating PDP subgroups
339      */
340     public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
341             @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException;
342
343     /**
344      * Delete a PDP group.
345      *
346      * @param name the name of the policy to get, null to get all PDP groups
347      * @param version the version of the policy to get, null to get all versions of a PDP group
348      * @return the PDP group deleted
349      * @throws PfModelException on errors deleting PDP groups
350      */
351     public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException;
352
353     /**
354      * Get PDP statistics.
355      *
356      * @param name the name of the PDP group to get statistics for, null to get all PDP groups
357      * @param version the version of the PDP group to get statistics for, null to get all versions of a PDP group
358      * @return the statistics found
359      * @throws PfModelException on errors getting statistics
360      */
361     public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException;
362
363     /**
364      * Update PDP statistics for a PDP.
365      *
366      * @param pdpGroupName the name of the PDP group containing the PDP that the statistics are for
367      * @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for
368      * @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for
369      * @param pdpInstanceId the instance ID of the PDP to update statistics for
370      * @throws PfModelException on errors updating statistics
371      */
372     public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
373             @NonNull final String pdpType, @NonNull final String pdpInstanceId,
374             @NonNull final PdpStatistics pdppStatistics) throws PfModelException;
375
376     /**
377      * Get deployed policies.
378      *
379      * @param name the name of the policy to get, null to get all policies
380      * @return the policies deployed as a map of policy lists keyed by PDP group name and version
381      * @throws PfModelException on errors getting policies
382      */
383     public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
384             throws PfModelException;
385 }