2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2021 Nordix Foundation.
4 * Modifications Copyright (C) 2020 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.time.Instant;
26 import java.util.Collection;
27 import java.util.List;
28 import lombok.NonNull;
29 import org.onap.policy.models.base.PfModelException;
30 import org.onap.policy.models.pap.concepts.PolicyAudit;
31 import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
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.PdpStatistics;
37 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
38 import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
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;
260 * @param name the name of the policy to get, null to get all PDP groups
261 * @return the PDP groups found
262 * @throws PfModelException on errors getting PDP groups
264 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
267 * Get filtered PDP groups.
269 * @param filter the filter for the PDP groups to get
270 * @return the PDP groups found
271 * @throws PfModelException on errors getting policies
273 public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
276 * Creates PDP groups.
278 * @param pdpGroups a specification of the PDP groups to create
279 * @return the PDP groups created
280 * @throws PfModelException on errors creating PDP groups
282 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
285 * Updates PDP groups.
287 * @param pdpGroups a specification of the PDP groups to update
288 * @return the PDP groups updated
289 * @throws PfModelException on errors updating PDP groups
291 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
294 * Update a PDP subgroup.
296 * @param pdpGroupName the name of the PDP group of the PDP subgroup
297 * @param pdpSubGroup the PDP subgroup to be updated
298 * @throws PfModelException on errors updating PDP subgroups
300 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
301 throws PfModelException;
306 * @param pdpGroupName the name of the PDP group of the PDP subgroup
307 * @param pdpSubGroup the PDP subgroup to be updated
308 * @param pdp the PDP to be updated
309 * @throws PfModelException on errors updating PDP subgroups
311 public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
312 throws PfModelException;
315 * Delete a PDP group.
317 * @param name the name of the policy to get, null to get all PDP groups
318 * @return the PDP group deleted
319 * @throws PfModelException on errors deleting PDP groups
321 public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
324 * Get PDP statistics.
326 * @param name the name of the PDP group to get statistics for, null to get all PDP groups
327 * @return the statistics found
328 * @throws PfModelException on errors getting statistics
330 public List<PdpStatistics> getPdpStatistics(final String name, final Instant timestamp) throws PfModelException;
334 * Get filtered PdpStatistics.
336 * @param filterParams filter parameters
337 * @return the PDP statistics found
338 * @throws PfModelException on errors getting policies
340 public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException;
343 * Creates PDP statistics.
345 * @param pdpStatisticsList a specification of the PDP statistics to create
346 * @return the PDP statistics created
347 * @throws PfModelException on errors creating PDP statistics
349 public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
350 throws PfModelException;
353 * Updates PDP statistics.
355 * @param pdpStatisticsList a specification of the PDP statistics to update
356 * @return the PDP statistics updated
357 * @throws PfModelException on errors updating PDP statistics
359 public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
360 throws PfModelException;
363 * Delete a PDP statistics.
365 * @param name the name of the policy to get, null to get all PDP statistics
366 * @param timestamp the timestamp of statistics to delete, null to delete all statistics record of given pdp
367 * @return the PDP statistics deleted
368 * @throws PfModelException on errors deleting PDP statistics
370 public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Instant timestamp) throws PfModelException;
373 * Gets all policy deployments.
375 * @return the deployments found
376 * @throws PfModelException on errors getting PDP groups
378 public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException;
381 * Gets all deployments for a policy.
383 * @return the deployments found
384 * @throws PfModelException on errors getting PDP groups
386 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
387 throws PfModelException;
390 * Gets the policy deployments for a PDP group.
392 * @param groupName the name of the PDP group of interest, null to get results for all PDP groups
393 * @return the deployments found
394 * @throws PfModelException on errors getting PDP groups
396 public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException;
399 * Creates, updates, and deletes collections of policy status.
401 * @param createObjs the objects to create
402 * @param updateObjs the objects to update
403 * @param deleteObjs the objects to delete
405 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
406 Collection<PdpPolicyStatus> deleteObjs);
409 * Creates records for audit actions on policies.
411 * @param auditRecords the objects to create
413 public void createAuditRecords(@NonNull List<PolicyAudit> auditRecords);
416 * Collect the audit records.
417 * @param auditFilter filter for search
418 * @return list of {@link PolicyAudit} or empty if none or not match with filter
420 public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter);