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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.models.provider;
25 import java.util.Collection;
26 import java.util.List;
28 import lombok.NonNull;
29 import org.onap.policy.models.base.PfModelException;
30 import org.onap.policy.models.base.PfModelRuntimeException;
31 import org.onap.policy.models.pdp.concepts.Pdp;
32 import org.onap.policy.models.pdp.concepts.PdpGroup;
33 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
34 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
35 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
46 * This interface describes the operations that are provided to users and components for reading objects from and
47 * writing objects to the database.
49 * @author Liam Fallon (liam.fallon@est.tech)
51 public interface PolicyModelsProvider extends AutoCloseable {
53 * Open the policy model provider initializing whatever internal handling it needs.
55 * @throws PfModelException on errors opening the models provider
57 public void init() throws PfModelException;
60 public void close() throws PfModelException;
63 * Get service templates.
65 * @param name the name of the topology template to get, set to null to get all service templates
66 * @param version the version of the service template to get, set to null to get all service templates
67 * @return the topology templates found
68 * @throws PfModelException on errors getting service templates
70 public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version)
71 throws PfModelException;
74 * Get filtered service templates.
76 * @param filter the filter for the service templates to get
77 * @return the service templates found
78 * @throws PfModelException on errors getting service templates
80 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
81 @NonNull final ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException;
84 * Create service template.
86 * @param serviceTemplate the service template to be created
87 * @return the created service template
88 * @throws PfModelException on errors creating the service template
90 public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
91 throws PfModelException;
94 * Update service template.
96 * @param serviceTemplate the service template to be updated
97 * @return the updated service template
98 * @throws PfModelException on errors updating the service template
100 public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
101 throws PfModelException;
104 * Delete service template.
106 * @param name the name of the service template to delete.
107 * @param version the version of the service template to delete.
108 * @return the TOSCA service template that was deleted
109 * @throws PfModelException on errors deleting policy types
111 public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version)
112 throws PfModelException;
117 * @param name the name of the policy type to get, set to null to get all policy types
118 * @param version the version of the policy type to get, set to null to get all versions
119 * @return the policy types found
120 * @throws PfModelException on errors getting policy types
122 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
127 * @param name the name of the policy type to get, set to null to get all policy types
128 * @param version the version of the policy type to get, set to null to get all versions
129 * @return the policy types found
130 * @throws PfModelException on errors getting policy types
132 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
135 * Get filtered policy types.
137 * @param filter the filter for the policy types to get
138 * @return the policy types found
139 * @throws PfModelException on errors getting policy types
141 public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
142 throws PfModelException;
145 * Get filtered policy types.
147 * @param filter the filter for the policy types to get
148 * @return the policy types found
149 * @throws PfModelException on errors getting policy types
151 public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
152 throws PfModelException;
155 * Create policy types.
157 * @param serviceTemplate the service template containing the definition of the policy types to be created
158 * @return the TOSCA service template containing the created policy types
159 * @throws PfModelException on errors creating policy types
161 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
162 throws PfModelException;
165 * Update policy types.
167 * @param serviceTemplate the service template containing the definition of the policy types to be modified
168 * @return the TOSCA service template containing the modified policy types
169 * @throws PfModelException on errors updating policy types
171 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
172 throws PfModelException;
175 * Delete policy type.
177 * @param name the name of the policy type to delete.
178 * @param version the version of the policy type to delete.
179 * @return the TOSCA service template containing the policy type that was deleted
180 * @throws PfModelException on errors deleting the policy type
182 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
183 throws PfModelException;
188 * @param name the name of the policy to get, null to get all policies
189 * @param version the version of the policy to get, null to get all versions of a policy
190 * @return the policies found
191 * @throws PfModelException on errors getting policies
193 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
198 * @param name the name of the policy to get, null to get all policies
199 * @param version the version of the policy to get, null to get all versions of a policy
200 * @return the policies found
201 * @throws PfModelException on errors getting policies
203 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
206 * Get filtered policies.
208 * @param filter the filter for the policies to get
209 * @return the policies found
210 * @throws PfModelException on errors getting policies
212 public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
213 throws PfModelException;
216 * Get filtered policies.
218 * @param filter the filter for the policies to get
219 * @return the policies found
220 * @throws PfModelException on errors getting policies
222 public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
223 throws PfModelException;
228 * @param serviceTemplate the service template containing the definitions of the new policies to be created.
229 * @return the TOSCA service template containing the policy types that were created
230 * @throws PfModelException on errors creating policies
232 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
233 throws PfModelException;
238 * @param serviceTemplate the service template containing the definitions of the policies to be updated.
239 * @return the TOSCA service template containing the policies that were updated
240 * @throws PfModelException on errors updating policies
242 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
243 throws PfModelException;
248 * @param name the name of the policy to delete.
249 * @param version the version of the policy to delete.
250 * @return the TOSCA service template containing the policy that was deleted
251 * @throws PfModelException on errors deleting a policy
253 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
254 throws PfModelException;
258 * Create tosca node templates.
260 * @param serviceTemplate the definitions of the new node templates to be created.
261 * @return the tosca node templates that were created
262 * @throws PfModelException on errors creating tosca node templates
264 public ToscaServiceTemplate createToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
265 throws PfModelException;
268 * Update tosca node templates.
270 * @param serviceTemplate with node templates to be updated.
271 * @return the service template with node templates that were updated
272 * @throws PfModelException on errors updating tosca node templates
274 public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
275 throws PfModelRuntimeException, PfModelException;
278 * Delete a tosca node template.
280 * @param name the name of the node template to delete.
281 * @param version the version of the node template to delete.
282 * @return the service template with node templates that was deleted
283 * @throws PfModelException on errors deleting a node template
285 public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @NonNull final String version)
286 throws PfModelException;
290 * Get filtered node template metadataSet entities.
292 * @return the list of metadataSet found
293 * @throws PfModelException on errors getting node template metadataSet
295 public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(final String name,
296 final String version)
297 throws PfModelException;
300 * Get filtered node template entities.
302 * @return the list of nodeTemplates found
303 * @throws PfModelException on errors getting node template
305 public List<ToscaNodeTemplate> getToscaNodeTemplate(final String name, final String version)
306 throws PfModelException;
311 * @param name the name of the policy to get, null to get all PDP groups
312 * @return the PDP groups found
313 * @throws PfModelException on errors getting PDP groups
315 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
318 * Get filtered PDP groups.
320 * @param filter the filter for the PDP groups to get
321 * @return the PDP groups found
322 * @throws PfModelException on errors getting policies
324 public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
327 * Creates PDP groups.
329 * @param pdpGroups a specification of the PDP groups to create
330 * @return the PDP groups created
331 * @throws PfModelException on errors creating PDP groups
333 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
336 * Updates PDP groups.
338 * @param pdpGroups a specification of the PDP groups to update
339 * @return the PDP groups updated
340 * @throws PfModelException on errors updating PDP groups
342 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
345 * Update a PDP subgroup.
347 * @param pdpGroupName the name of the PDP group of the PDP subgroup
348 * @param pdpSubGroup the PDP subgroup to be updated
349 * @throws PfModelException on errors updating PDP subgroups
351 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
352 throws PfModelException;
357 * @param pdpGroupName the name of the PDP group of the PDP subgroup
358 * @param pdpSubGroup the PDP subgroup to be updated
359 * @param pdp the PDP to be updated
360 * @throws PfModelException on errors updating PDP subgroups
362 public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
363 throws PfModelException;
366 * Delete a PDP group.
368 * @param name the name of the policy to get, null to get all PDP groups
369 * @return the PDP group deleted
370 * @throws PfModelException on errors deleting PDP groups
372 public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
375 * Gets all policy deployments.
377 * @return the deployments found
378 * @throws PfModelException on errors getting PDP groups
380 public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException;
383 * Gets all deployments for a policy.
385 * @return the deployments found
386 * @throws PfModelException on errors getting PDP groups
388 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
389 throws PfModelException;
392 * Gets the policy deployments for a PDP group.
394 * @param groupName the name of the PDP group of interest, null to get results for all PDP groups
395 * @return the deployments found
396 * @throws PfModelException on errors getting PDP groups
398 public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException;
401 * Creates, updates, and deletes collections of policy status.
403 * @param createObjs the objects to create
404 * @param updateObjs the objects to update
405 * @param deleteObjs the objects to delete
407 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
408 Collection<PdpPolicyStatus> deleteObjs);