2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 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.util.Collection;
26 import java.util.Date;
27 import java.util.List;
28 import lombok.NonNull;
29 import org.onap.policy.models.base.PfModelException;
30 import org.onap.policy.models.pdp.concepts.Pdp;
31 import org.onap.policy.models.pdp.concepts.PdpGroup;
32 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
33 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
34 import org.onap.policy.models.pdp.concepts.PdpStatistics;
35 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter;
44 * This interface describes the operations that are provided to users and components for reading objects from and
45 * writing objects to the database.
47 * @author Liam Fallon (liam.fallon@est.tech)
49 public interface PolicyModelsProvider extends AutoCloseable {
51 * Open the policy model provider initializing whatever internal handling it needs.
53 * @throws PfModelException on errors opening the models provider
55 public void init() throws PfModelException;
58 public void close() throws PfModelException;
61 * Get service templates.
63 * @param name the name of the topology template to get, set to null to get all service templates
64 * @param version the version of the service template to get, set to null to get all service templates
65 * @return the topology templates found
66 * @throws PfModelException on errors getting service templates
68 public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version)
69 throws PfModelException;
72 * Get filtered service templates.
74 * @param filter the filter for the service templates to get
75 * @return the service templates found
76 * @throws PfModelException on errors getting service templates
78 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull final ToscaServiceTemplateFilter filter)
79 throws PfModelException;
82 * Create service template.
84 * @param serviceTemplate the service template to be created
85 * @return the created service template
86 * @throws PfModelException on errors creating the service template
88 public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
89 throws PfModelException;
92 * Update service template.
94 * @param serviceTemplate the service template to be updated
95 * @return the updated service template
96 * @throws PfModelException on errors updating the service template
98 public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
99 throws PfModelException;
102 * Delete service template.
104 * @param name the name of the service template to delete.
105 * @param version the version of the service template to delete.
106 * @return the TOSCA service template that was deleted
107 * @throws PfModelException on errors deleting policy types
109 public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version)
110 throws PfModelException;
115 * @param name the name of the policy type to get, set to null to get all policy types
116 * @param version the version of the policy type to get, set to null to get all versions
117 * @return the policy types found
118 * @throws PfModelException on errors getting policy types
120 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
125 * @param name the name of the policy type to get, set to null to get all policy types
126 * @param version the version of the policy type to get, set to null to get all versions
127 * @return the policy types found
128 * @throws PfModelException on errors getting policy types
130 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
133 * Get filtered policy types.
135 * @param filter the filter for the policy types to get
136 * @return the policy types found
137 * @throws PfModelException on errors getting policy types
139 public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaPolicyTypeFilter filter)
140 throws PfModelException;
143 * Get filtered policy types.
145 * @param filter the filter for the policy types to get
146 * @return the policy types found
147 * @throws PfModelException on errors getting policy types
149 public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaPolicyTypeFilter filter)
150 throws PfModelException;
153 * Create policy types.
155 * @param serviceTemplate the service template containing the definition of the policy types to be created
156 * @return the TOSCA service template containing the created policy types
157 * @throws PfModelException on errors creating policy types
159 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
160 throws PfModelException;
163 * Update policy types.
165 * @param serviceTemplate the service template containing the definition of the policy types to be modified
166 * @return the TOSCA service template containing the modified policy types
167 * @throws PfModelException on errors updating policy types
169 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
170 throws PfModelException;
173 * Delete policy type.
175 * @param name the name of the policy type to delete.
176 * @param version the version of the policy type to delete.
177 * @return the TOSCA service template containing the policy type that was deleted
178 * @throws PfModelException on errors deleting the policy type
180 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
181 throws PfModelException;
186 * @param name the name of the policy to get, null to get all policies
187 * @param version the version of the policy to get, null to get all versions of a policy
188 * @return the policies found
189 * @throws PfModelException on errors getting policies
191 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
196 * @param name the name of the policy to get, null to get all policies
197 * @param version the version of the policy to get, null to get all versions of a policy
198 * @return the policies found
199 * @throws PfModelException on errors getting policies
201 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
204 * Get filtered policies.
206 * @param filter the filter for the policies to get
207 * @return the policies found
208 * @throws PfModelException on errors getting policies
210 public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
213 * Get filtered policies.
215 * @param filter the filter for the policies to get
216 * @return the policies found
217 * @throws PfModelException on errors getting policies
219 public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
224 * @param serviceTemplate the service template containing the definitions of the new policies to be created.
225 * @return the TOSCA service template containing the policy types that were created
226 * @throws PfModelException on errors creating policies
228 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
229 throws PfModelException;
234 * @param serviceTemplate the service template containing the definitions of the policies to be updated.
235 * @return the TOSCA service template containing the policies that were updated
236 * @throws PfModelException on errors updating policies
238 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
239 throws PfModelException;
244 * @param name the name of the policy to delete.
245 * @param version the version of the policy to delete.
246 * @return the TOSCA service template containing the policy that was deleted
247 * @throws PfModelException on errors deleting a policy
249 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
250 throws PfModelException;
255 * @param name the name of the policy to get, null to get all PDP groups
256 * @return the PDP groups found
257 * @throws PfModelException on errors getting PDP groups
259 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
262 * Get filtered PDP groups.
264 * @param filter the filter for the PDP groups to get
265 * @return the PDP groups found
266 * @throws PfModelException on errors getting policies
268 public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
271 * Creates PDP groups.
273 * @param pdpGroups a specification of the PDP groups to create
274 * @return the PDP groups created
275 * @throws PfModelException on errors creating PDP groups
277 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
280 * Updates PDP groups.
282 * @param pdpGroups a specification of the PDP groups to update
283 * @return the PDP groups updated
284 * @throws PfModelException on errors updating PDP groups
286 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
289 * Update a PDP subgroup.
291 * @param pdpGroupName the name of the PDP group of the PDP subgroup
292 * @param pdpSubGroup the PDP subgroup to be updated
293 * @throws PfModelException on errors updating PDP subgroups
295 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
296 throws PfModelException;
301 * @param pdpGroupName the name of the PDP group of the PDP subgroup
302 * @param pdpSubGroup the PDP subgroup to be updated
303 * @param pdp the PDP to be updated
304 * @throws PfModelException on errors updating PDP subgroups
306 public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
307 throws PfModelException;
310 * Delete a PDP group.
312 * @param name the name of the policy to get, null to get all PDP groups
313 * @return the PDP group deleted
314 * @throws PfModelException on errors deleting PDP groups
316 public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
319 * Get PDP statistics.
321 * @param name the name of the PDP group to get statistics for, null to get all PDP groups
322 * @return the statistics found
323 * @throws PfModelException on errors getting statistics
325 public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException;
329 * Get filtered PdpStatistics.
331 * @param name the pdpInstance name for the PDP statistics to get
332 * @param pdpGroupName pdpGroupName to filter statistics
333 * @param pdpSubGroup pdpSubGroupType name to filter statistics
334 * @param startTimeStamp startTimeStamp to filter statistics
335 * @param endTimeStamp endTimeStamp to filter statistics
336 * @param sortOrder sortOrder to query database
337 * @param getRecordNum Total query count from database
338 * @return the PDP statistics found
339 * @throws PfModelException on errors getting policies
341 public List<PdpStatistics> getFilteredPdpStatistics(String name, @NonNull String pdpGroupName, String pdpSubGroup,
342 Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException;
345 * Creates PDP statistics.
347 * @param pdpStatisticsList a specification of the PDP statistics to create
348 * @return the PDP statistics created
349 * @throws PfModelException on errors creating PDP statistics
351 public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
352 throws PfModelException;
355 * Updates PDP statistics.
357 * @param pdpStatisticsList a specification of the PDP statistics to update
358 * @return the PDP statistics updated
359 * @throws PfModelException on errors updating PDP statistics
361 public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
362 throws PfModelException;
365 * Delete a PDP statistics.
367 * @param name the name of the policy to get, null to get all PDP statistics
368 * @param timestamp the timestamp of statistics to delete, null to delete all statistics record of given pdp
369 * @return the PDP statistics deleted
370 * @throws PfModelException on errors deleting PDP statistics
372 public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Date timestamp) throws PfModelException;
375 * Gets the policy deployments for a PDP group.
377 * @param groupName the name of the PDP group of interest, null to get results for all
379 * @return the deployments found
380 * @throws PfModelException on errors getting PDP groups
382 public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName)
383 throws PfModelException;
386 * Creates, updates, and deletes collections of policy status.
388 * @param createObjs the objects to create
389 * @param updateObjs the objects to update
390 * @param deleteObjs the objects to delete
392 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs,
393 Collection<PdpPolicyStatus> updateObjs, Collection<PdpPolicyStatus> deleteObjs);