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.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
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;
259 * @param name the name of the policy to get, null to get all PDP groups
260 * @return the PDP groups found
261 * @throws PfModelException on errors getting PDP groups
263 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
266 * Get filtered PDP groups.
268 * @param filter the filter for the PDP groups to get
269 * @return the PDP groups found
270 * @throws PfModelException on errors getting policies
272 public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
275 * Creates PDP groups.
277 * @param pdpGroups a specification of the PDP groups to create
278 * @return the PDP groups created
279 * @throws PfModelException on errors creating PDP groups
281 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
284 * Updates PDP groups.
286 * @param pdpGroups a specification of the PDP groups to update
287 * @return the PDP groups updated
288 * @throws PfModelException on errors updating PDP groups
290 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
293 * Update a PDP subgroup.
295 * @param pdpGroupName the name of the PDP group of the PDP subgroup
296 * @param pdpSubGroup the PDP subgroup to be updated
297 * @throws PfModelException on errors updating PDP subgroups
299 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
300 throws PfModelException;
305 * @param pdpGroupName the name of the PDP group of the PDP subgroup
306 * @param pdpSubGroup the PDP subgroup to be updated
307 * @param pdp the PDP to be updated
308 * @throws PfModelException on errors updating PDP subgroups
310 public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
311 throws PfModelException;
314 * Delete a PDP group.
316 * @param name the name of the policy to get, null to get all PDP groups
317 * @return the PDP group deleted
318 * @throws PfModelException on errors deleting PDP groups
320 public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
323 * Get PDP statistics.
325 * @param name the name of the PDP group to get statistics for, null to get all PDP groups
326 * @return the statistics found
327 * @throws PfModelException on errors getting statistics
329 public List<PdpStatistics> getPdpStatistics(final String name, final Instant timestamp) throws PfModelException;
333 * Get filtered PdpStatistics.
335 * @param name the pdpInstance name for the PDP statistics to get
336 * @param pdpGroupName pdpGroupName to filter statistics
337 * @param pdpSubGroup pdpSubGroupType name to filter statistics
338 * @param startTimeStamp startTimeStamp to filter statistics
339 * @param endTimeStamp endTimeStamp to filter statistics
340 * @param sortOrder sortOrder to query database
341 * @param getRecordNum Total query count from database
342 * @return the PDP statistics found
343 * @throws PfModelException on errors getting policies
345 public List<PdpStatistics> getFilteredPdpStatistics(String name, @NonNull String pdpGroupName, String pdpSubGroup,
346 Instant startTimeStamp, Instant endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException;
349 * Creates PDP statistics.
351 * @param pdpStatisticsList a specification of the PDP statistics to create
352 * @return the PDP statistics created
353 * @throws PfModelException on errors creating PDP statistics
355 public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
356 throws PfModelException;
359 * Updates PDP statistics.
361 * @param pdpStatisticsList a specification of the PDP statistics to update
362 * @return the PDP statistics updated
363 * @throws PfModelException on errors updating PDP statistics
365 public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
366 throws PfModelException;
369 * Delete a PDP statistics.
371 * @param name the name of the policy to get, null to get all PDP statistics
372 * @param timestamp the timestamp of statistics to delete, null to delete all statistics record of given pdp
373 * @return the PDP statistics deleted
374 * @throws PfModelException on errors deleting PDP statistics
376 public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Instant timestamp) throws PfModelException;
379 * Gets all policy deployments.
381 * @return the deployments found
382 * @throws PfModelException on errors getting PDP groups
384 public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException;
387 * Gets all deployments for a policy.
389 * @return the deployments found
390 * @throws PfModelException on errors getting PDP groups
392 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
393 throws PfModelException;
396 * Gets the policy deployments for a PDP group.
398 * @param groupName the name of the PDP group of interest, null to get results for all PDP groups
399 * @return the deployments found
400 * @throws PfModelException on errors getting PDP groups
402 public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException;
405 * Creates, updates, and deletes collections of policy status.
407 * @param createObjs the objects to create
408 * @param updateObjs the objects to update
409 * @param deleteObjs the objects to delete
411 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
412 Collection<PdpPolicyStatus> deleteObjs);
415 * Creates records for audit actions on policies.
417 * @param auditRecords the objects to create
419 public void createAuditRecords(@NonNull List<PolicyAudit> auditRecords);
422 * Collect the audit records.
423 * @param auditFilter filter for search
424 * @param numRecords max number of records to be collected
425 * @return list of {@link PolicyAudit} or empty if none or not match with filter
427 public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter, @NonNull Integer numRecords);