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.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;
47 * This interface describes the operations that are provided to users and components for reading objects from and
48 * writing objects to the database.
50 * @author Liam Fallon (liam.fallon@est.tech)
52 public interface PolicyModelsProvider extends AutoCloseable {
54 * Open the policy model provider initializing whatever internal handling it needs.
56 * @throws PfModelException on errors opening the models provider
58 public void init() throws PfModelException;
61 public void close() throws PfModelException;
64 * Get service templates.
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
71 public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version)
72 throws PfModelException;
75 * Get filtered service templates.
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
81 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
82 @NonNull final ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException;
85 * Create service template.
87 * @param serviceTemplate the service template to be created
88 * @return the created service template
89 * @throws PfModelException on errors creating the service template
91 public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
92 throws PfModelException;
95 * Update service template.
97 * @param serviceTemplate the service template to be updated
98 * @return the updated service template
99 * @throws PfModelException on errors updating the service template
101 public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
102 throws PfModelException;
105 * Delete service template.
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
112 public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version)
113 throws PfModelException;
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
123 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
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
133 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
136 * Get filtered policy types.
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
142 public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
143 throws PfModelException;
146 * Get filtered policy types.
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
152 public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter)
153 throws PfModelException;
156 * Create policy types.
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
162 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
163 throws PfModelException;
166 * Update policy types.
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
172 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
173 throws PfModelException;
176 * Delete policy type.
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
183 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
184 throws PfModelException;
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
194 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
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
204 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
207 * Get filtered policies.
209 * @param filter the filter for the policies to get
210 * @return the policies found
211 * @throws PfModelException on errors getting policies
213 public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
214 throws PfModelException;
217 * Get filtered policies.
219 * @param filter the filter for the policies to get
220 * @return the policies found
221 * @throws PfModelException on errors getting policies
223 public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter)
224 throws PfModelException;
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
233 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
234 throws PfModelException;
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
243 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
244 throws PfModelException;
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
254 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
255 throws PfModelException;
259 * Create tosca node templates.
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
265 public ToscaServiceTemplate createToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
266 throws PfModelException;
269 * Update tosca node templates.
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
275 public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate)
276 throws PfModelRuntimeException, PfModelException;
279 * Delete a tosca node template.
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
286 public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @NonNull final String version)
287 throws PfModelException;
291 * Get filtered node template metadataSet entities.
293 * @return the list of metadataSet found
294 * @throws PfModelException on errors getting node template metadataSet
296 public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(final String name,
297 final String version)
298 throws PfModelException;
301 * Get filtered node template entities.
303 * @return the list of nodeTemplates found
304 * @throws PfModelException on errors getting node template
306 public List<ToscaNodeTemplate> getToscaNodeTemplate(final String name, final String version)
307 throws PfModelException;
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
316 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
319 * Get filtered PDP groups.
321 * @param filter the filter for the PDP groups to get
322 * @return the PDP groups found
323 * @throws PfModelException on errors getting policies
325 public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
328 * Creates PDP groups.
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
334 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
337 * Updates PDP groups.
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
343 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
346 * Update a PDP subgroup.
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
352 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
353 throws PfModelException;
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
363 public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
364 throws PfModelException;
367 * Delete a PDP group.
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
373 public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
376 * Gets all policy deployments.
378 * @return the deployments found
379 * @throws PfModelException on errors getting PDP groups
381 public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException;
384 * Gets all deployments for a policy.
386 * @return the deployments found
387 * @throws PfModelException on errors getting PDP groups
389 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
390 throws PfModelException;
393 * Gets the policy deployments for a PDP group.
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
399 public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException;
402 * Creates, updates, and deletes collections of policy status.
404 * @param createObjs the objects to create
405 * @param updateObjs the objects to update
406 * @param deleteObjs the objects to delete
408 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
409 Collection<PdpPolicyStatus> deleteObjs);