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