2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.provider;
23 import java.util.List;
26 import lombok.NonNull;
28 import org.apache.commons.lang3.tuple.Pair;
29 import org.onap.policy.models.base.PfModelException;
30 import org.onap.policy.models.pdp.concepts.PdpGroup;
31 import org.onap.policy.models.pdp.concepts.PdpStatistics;
32 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
36 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
37 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
38 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
41 * This interface describes the operations that are provided to users and components for reading objects from and
42 * writing objects to the database.
44 * @author Liam Fallon (liam.fallon@est.tech)
46 public interface PolicyModelsProvider extends AutoCloseable {
48 * Open the policy model provider initializing whatever internal handling it needs.
50 * @throws PfModelException on errors opening the models provider
52 public void init() throws PfModelException;
55 public void close() throws PfModelException;
60 * @param name the name of the policy type to get, set to null to get all policy types
61 * @param version the version of the policy type to get, set to null to get all versions
62 * @return the policy types found
63 * @throws PfModelException on errors getting policy types
65 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
70 * @param name the name of the policy type to get, set to null to get all policy types
71 * @param version the version of the policy type to get, set to null to get all versions
72 * @return the policy types found
73 * @throws PfModelException on errors getting policy types
75 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
78 * Get latest policy types.
80 * @param name the name of the policy type to get, set to null to get all policy types
81 * @return the policy types found
82 * @throws PfModelException on errors getting policy types
84 public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException;
87 * Get latest policy types.
89 * @param name the name of the policy type to get, set to null to get all policy types
90 * @return the policy types found
91 * @throws PfModelException on errors getting policy types
93 public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException;
96 * Create policy types.
98 * @param serviceTemplate the service template containing the definition of the policy types to be created
99 * @return the TOSCA service template containing the created policy types
100 * @throws PfModelException on errors creating policy types
102 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
103 throws PfModelException;
106 * Create policy types.
108 * @param serviceTemplate the service template containing the definition of the policy types to be modified
109 * @return the TOSCA service template containing the modified policy types
110 * @throws PfModelException on errors updating policy types
112 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
113 throws PfModelException;
116 * Delete policy type.
118 * @param name the name of the policy type to delete.
119 * @param version the version of the policy type to delete.
120 * @return the TOSCA service template containing the policy type that was deleted
121 * @throws PfModelException on errors deleting policy types
123 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
124 throws PfModelException;
129 * @param name the name of the policy to get, null to get all policies
130 * @param version the version of the policy to get, null to get all versions of a policy
131 * @return the policies found
132 * @throws PfModelException on errors getting policies
134 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
139 * @param name the name of the policy to get, null to get all policies
140 * @param version the version of the policy to get, null to get all versions of a policy
141 * @return the policies found
142 * @throws PfModelException on errors getting policies
144 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
147 * Get policies for a policy type name.
149 * @param policyTypeName the name of the policy type for which to get policies
150 * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
152 * @return the policies found
153 * @throws PfModelException on errors getting policies
155 public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
156 final String policyTypeVersion) throws PfModelException;
159 * Get latest policies.
161 * @param name the name of the policy to get, null to get all policies
162 * @return the policies found
163 * @throws PfModelException on errors getting policies
165 public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException;
168 * Get latest policies.
170 * @param name the name of the policy to get, null to get all policies
171 * @return the policies found
172 * @throws PfModelException on errors getting policies
174 public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException;
179 * @param serviceTemplate the service template containing the definitions of the new policies to be created.
180 * @return the TOSCA service template containing the policy types that were created
181 * @throws PfModelException on errors creating policies
183 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
184 throws PfModelException;
189 * @param serviceTemplate the service template containing the definitions of the policies to be updated.
190 * @return the TOSCA service template containing the policies that were updated
191 * @throws PfModelException on errors updating policies
193 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
194 throws PfModelException;
199 * @param name the name of the policy to delete.
200 * @param version the version of the policy to delete.
201 * @return the TOSCA service template containing the policy that was deleted
202 * @throws PfModelException on errors deleting a policy
204 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
205 throws PfModelException;
208 * Get legacy operational policy.
210 * @param policyId ID of the policy.
211 * @return the policies found
212 * @throws PfModelException on errors getting policies
214 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException;
217 * Create legacy operational policy.
219 * @param legacyOperationalPolicy the definition of the policy to be created.
220 * @return the created policy
221 * @throws PfModelException on errors creating policies
223 public LegacyOperationalPolicy createOperationalPolicy(
224 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
227 * Update legacy operational policy.
229 * @param legacyOperationalPolicy the definition of the policy to be updated
230 * @return the updated policy
231 * @throws PfModelException on errors updating policies
233 public LegacyOperationalPolicy updateOperationalPolicy(
234 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
237 * Delete legacy operational policy.
239 * @param policyId ID of the policy.
240 * @return the deleted policy
241 * @throws PfModelException on errors deleting policies
243 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException;
246 * Get legacy guard policy.
248 * @param policyId ID of the policy.
249 * @return the policies found
250 * @throws PfModelException on errors getting policies
252 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException;
255 * Create legacy guard policy.
257 * @param legacyGuardPolicy the definition of the policy to be created.
258 * @return the created policy
259 * @throws PfModelException on errors creating policies
261 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
262 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
265 * Update legacy guard policy.
267 * @param legacyGuardPolicy the definition of the policy to be updated
268 * @return the updated policy
269 * @throws PfModelException on errors updating policies
271 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
272 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
275 * Delete legacy guard policy.
277 * @param policyId ID of the policy.
278 * @return the deleted policy
279 * @throws PfModelException on errors deleting policies
281 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
282 throws PfModelException;
287 * @param name the name of the policy to get, null to get all PDP groups
288 * @param version the version of the policy to get, null to get all versions of a PDP group
289 * @return the PDP groups found
290 * @throws PfModelException on errors getting PDP groups
292 public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException;
295 * Get latest PDP Groups, returns PDP groups in all states.
297 * @param name the name of the PDP group to get, null to get all PDP groups
298 * @return the PDP groups found
299 * @throws PfModelException on errors getting policies
301 public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException;
304 * Get a filtered list of PDP groups, returns only active PDP groups.
306 * @param pdpType The PDP type filter for the returned PDP groups, null to get policy types across PDP subgroups
307 * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
308 * @return the PDP groups found
310 public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
311 @NonNull final List<Pair<String, String>> supportedPolicyTypes);
314 * Creates PDP groups.
316 * @param pdpGroups a specification of the PDP groups to create
317 * @return the PDP groups created
318 * @throws PfModelException on errors creating PDP groups
320 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
323 * Updates PDP groups.
325 * @param pdpGroups a specification of the PDP groups to update
326 * @return the PDP groups updated
327 * @throws PfModelException on errors updating PDP groups
329 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
333 * Update a PDP subgroup.
335 * @param pdpGroupName the name of the PDP group of the PDP subgroup
336 * @param pdpGroupVersion the version of the PDP group of the PDP subgroup
337 * @param pdpSubGroup the PDP subgroup to be updated
338 * @throws PfModelException on errors updating PDP subgroups
340 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
341 @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException;
344 * Delete a PDP group.
346 * @param name the name of the policy to get, null to get all PDP groups
347 * @param version the version of the policy to get, null to get all versions of a PDP group
348 * @return the PDP group deleted
349 * @throws PfModelException on errors deleting PDP groups
351 public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException;
354 * Get PDP statistics.
356 * @param name the name of the PDP group to get statistics for, null to get all PDP groups
357 * @param version the version of the PDP group to get statistics for, null to get all versions of a PDP group
358 * @return the statistics found
359 * @throws PfModelException on errors getting statistics
361 public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException;
364 * Update PDP statistics for a PDP.
366 * @param pdpGroupName the name of the PDP group containing the PDP that the statistics are for
367 * @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for
368 * @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for
369 * @param pdpInstanceId the instance ID of the PDP to update statistics for
370 * @throws PfModelException on errors updating statistics
372 public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
373 @NonNull final String pdpType, @NonNull final String pdpInstanceId,
374 @NonNull final PdpStatistics pdppStatistics) throws PfModelException;
377 * Get deployed policies.
379 * @param name the name of the policy to get, null to get all policies
380 * @return the policies deployed as a map of policy lists keyed by PDP group name and version
381 * @throws PfModelException on errors getting policies
383 public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
384 throws PfModelException;