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