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.ToscaConceptIdentifierOptVersion;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter;
45 * This interface describes the operations that are provided to users and components for reading objects from and
46 * writing objects to the database.
48 * @author Liam Fallon (liam.fallon@est.tech)
50 public interface PolicyModelsProvider extends AutoCloseable {
52 * Open the policy model provider initializing whatever internal handling it needs.
54 * @throws PfModelException on errors opening the models provider
56 public void init() throws PfModelException;
59 public void close() throws PfModelException;
62 * Get service templates.
64 * @param name the name of the topology template to get, set to null to get all service templates
65 * @param version the version of the service template to get, set to null to get all service templates
66 * @return the topology templates found
67 * @throws PfModelException on errors getting service templates
69 public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version)
70 throws PfModelException;
73 * Get filtered service templates.
75 * @param filter the filter for the service templates to get
76 * @return the service templates found
77 * @throws PfModelException on errors getting service templates
79 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull final ToscaServiceTemplateFilter filter)
80 throws PfModelException;
83 * Create service template.
85 * @param serviceTemplate the service template to be created
86 * @return the created service template
87 * @throws PfModelException on errors creating the service template
89 public ToscaServiceTemplate createServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
90 throws PfModelException;
93 * Update service template.
95 * @param serviceTemplate the service template to be updated
96 * @return the updated service template
97 * @throws PfModelException on errors updating the service template
99 public ToscaServiceTemplate updateServiceTemplate(@NonNull final ToscaServiceTemplate serviceTemplate)
100 throws PfModelException;
103 * Delete service template.
105 * @param name the name of the service template to delete.
106 * @param version the version of the service template to delete.
107 * @return the TOSCA service template that was deleted
108 * @throws PfModelException on errors deleting policy types
110 public ToscaServiceTemplate deleteServiceTemplate(@NonNull final String name, @NonNull final String version)
111 throws PfModelException;
116 * @param name the name of the policy type to get, set to null to get all policy types
117 * @param version the version of the policy type to get, set to null to get all versions
118 * @return the policy types found
119 * @throws PfModelException on errors getting policy types
121 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
126 * @param name the name of the policy type to get, set to null to get all policy types
127 * @param version the version of the policy type to get, set to null to get all versions
128 * @return the policy types found
129 * @throws PfModelException on errors getting policy types
131 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
134 * Get filtered policy types.
136 * @param filter the filter for the policy types to get
137 * @return the policy types found
138 * @throws PfModelException on errors getting policy types
140 public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaPolicyTypeFilter filter)
141 throws PfModelException;
144 * Get filtered policy types.
146 * @param filter the filter for the policy types to get
147 * @return the policy types found
148 * @throws PfModelException on errors getting policy types
150 public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaPolicyTypeFilter filter)
151 throws PfModelException;
154 * Create policy types.
156 * @param serviceTemplate the service template containing the definition of the policy types to be created
157 * @return the TOSCA service template containing the created policy types
158 * @throws PfModelException on errors creating policy types
160 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
161 throws PfModelException;
164 * Update policy types.
166 * @param serviceTemplate the service template containing the definition of the policy types to be modified
167 * @return the TOSCA service template containing the modified policy types
168 * @throws PfModelException on errors updating policy types
170 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
171 throws PfModelException;
174 * Delete policy type.
176 * @param name the name of the policy type to delete.
177 * @param version the version of the policy type to delete.
178 * @return the TOSCA service template containing the policy type that was deleted
179 * @throws PfModelException on errors deleting the policy type
181 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
182 throws PfModelException;
187 * @param name the name of the policy to get, null to get all policies
188 * @param version the version of the policy to get, null to get all versions of a policy
189 * @return the policies found
190 * @throws PfModelException on errors getting policies
192 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
197 * @param name the name of the policy to get, null to get all policies
198 * @param version the version of the policy to get, null to get all versions of a policy
199 * @return the policies found
200 * @throws PfModelException on errors getting policies
202 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
205 * Get filtered policies.
207 * @param filter the filter for the policies to get
208 * @return the policies found
209 * @throws PfModelException on errors getting policies
211 public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
214 * Get filtered policies.
216 * @param filter the filter for the policies to get
217 * @return the policies found
218 * @throws PfModelException on errors getting policies
220 public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
225 * @param serviceTemplate the service template containing the definitions of the new policies to be created.
226 * @return the TOSCA service template containing the policy types that were created
227 * @throws PfModelException on errors creating policies
229 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
230 throws PfModelException;
235 * @param serviceTemplate the service template containing the definitions of the policies to be updated.
236 * @return the TOSCA service template containing the policies that were updated
237 * @throws PfModelException on errors updating policies
239 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
240 throws PfModelException;
245 * @param name the name of the policy to delete.
246 * @param version the version of the policy to delete.
247 * @return the TOSCA service template containing the policy that was deleted
248 * @throws PfModelException on errors deleting a policy
250 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
251 throws PfModelException;
256 * @param name the name of the policy to get, null to get all PDP groups
257 * @return the PDP groups found
258 * @throws PfModelException on errors getting PDP groups
260 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException;
263 * Get filtered PDP groups.
265 * @param filter the filter for the PDP groups to get
266 * @return the PDP groups found
267 * @throws PfModelException on errors getting policies
269 public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
272 * Creates PDP groups.
274 * @param pdpGroups a specification of the PDP groups to create
275 * @return the PDP groups created
276 * @throws PfModelException on errors creating PDP groups
278 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
281 * Updates PDP groups.
283 * @param pdpGroups a specification of the PDP groups to update
284 * @return the PDP groups updated
285 * @throws PfModelException on errors updating PDP groups
287 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
290 * Update a PDP subgroup.
292 * @param pdpGroupName the name of the PDP group of the PDP subgroup
293 * @param pdpSubGroup the PDP subgroup to be updated
294 * @throws PfModelException on errors updating PDP subgroups
296 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final PdpSubGroup pdpSubGroup)
297 throws PfModelException;
302 * @param pdpGroupName the name of the PDP group of the PDP subgroup
303 * @param pdpSubGroup the PDP subgroup to be updated
304 * @param pdp the PDP to be updated
305 * @throws PfModelException on errors updating PDP subgroups
307 public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
308 throws PfModelException;
311 * Delete a PDP group.
313 * @param name the name of the policy to get, null to get all PDP groups
314 * @return the PDP group deleted
315 * @throws PfModelException on errors deleting PDP groups
317 public PdpGroup deletePdpGroup(@NonNull final String name) throws PfModelException;
320 * Get PDP statistics.
322 * @param name the name of the PDP group to get statistics for, null to get all PDP groups
323 * @return the statistics found
324 * @throws PfModelException on errors getting statistics
326 public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException;
330 * Get filtered PdpStatistics.
332 * @param name the pdpInstance name for the PDP statistics to get
333 * @param pdpGroupName pdpGroupName to filter statistics
334 * @param pdpSubGroup pdpSubGroupType name to filter statistics
335 * @param startTimeStamp startTimeStamp to filter statistics
336 * @param endTimeStamp endTimeStamp to filter statistics
337 * @param sortOrder sortOrder to query database
338 * @param getRecordNum Total query count from database
339 * @return the PDP statistics found
340 * @throws PfModelException on errors getting policies
342 public List<PdpStatistics> getFilteredPdpStatistics(String name, @NonNull String pdpGroupName, String pdpSubGroup,
343 Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException;
346 * Creates PDP statistics.
348 * @param pdpStatisticsList a specification of the PDP statistics to create
349 * @return the PDP statistics created
350 * @throws PfModelException on errors creating PDP statistics
352 public List<PdpStatistics> createPdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
353 throws PfModelException;
356 * Updates PDP statistics.
358 * @param pdpStatisticsList a specification of the PDP statistics to update
359 * @return the PDP statistics updated
360 * @throws PfModelException on errors updating PDP statistics
362 public List<PdpStatistics> updatePdpStatistics(@NonNull List<PdpStatistics> pdpStatisticsList)
363 throws PfModelException;
366 * Delete a PDP statistics.
368 * @param name the name of the policy to get, null to get all PDP statistics
369 * @param timestamp the timestamp of statistics to delete, null to delete all statistics record of given pdp
370 * @return the PDP statistics deleted
371 * @throws PfModelException on errors deleting PDP statistics
373 public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Date timestamp) 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()
382 throws PfModelException;
385 * Gets all deployments for a policy.
387 * @return the deployments found
388 * @throws PfModelException on errors getting PDP groups
390 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
391 throws PfModelException;
394 * Gets the policy deployments for a PDP group.
396 * @param groupName the name of the PDP group of interest, null to get results for all
398 * @return the deployments found
399 * @throws PfModelException on errors getting PDP groups
401 public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName)
402 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,
412 Collection<PdpPolicyStatus> updateObjs, Collection<PdpPolicyStatus> deleteObjs);