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.Pdp;
31 import org.onap.policy.models.pdp.concepts.PdpGroup;
32 import org.onap.policy.models.pdp.concepts.PdpStatistics;
33 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
37 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
38 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
39 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
42 * This interface describes the operations that are provided to users and components for reading objects from and
43 * writing objects to the database.
45 * @author Liam Fallon (liam.fallon@est.tech)
47 public interface PolicyModelsProvider extends AutoCloseable {
49 * Open the policy model provider initializing whatever internal handling it needs.
51 * @throws PfModelException on errors opening the models provider
53 public void init() throws PfModelException;
56 public void close() throws PfModelException;
61 * @param name the name of the policy type to get, set to null to get all policy types
62 * @param version the version of the policy type to get, set to null to get all versions
63 * @return the policy types found
64 * @throws PfModelException on errors getting policy types
66 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
71 * @param name the name of the policy type to get, set to null to get all policy types
72 * @param version the version of the policy type to get, set to null to get all versions
73 * @return the policy types found
74 * @throws PfModelException on errors getting policy types
76 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
79 * Get latest policy types.
81 * @param name the name of the policy type to get, set to null to get all policy types
82 * @return the policy types found
83 * @throws PfModelException on errors getting policy types
85 public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException;
88 * Get latest policy types.
90 * @param name the name of the policy type to get, set to null to get all policy types
91 * @return the policy types found
92 * @throws PfModelException on errors getting policy types
94 public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException;
97 * Create policy types.
99 * @param serviceTemplate the service template containing the definition of the policy types to be created
100 * @return the TOSCA service template containing the created policy types
101 * @throws PfModelException on errors creating policy types
103 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
104 throws PfModelException;
107 * Create policy types.
109 * @param serviceTemplate the service template containing the definition of the policy types to be modified
110 * @return the TOSCA service template containing the modified policy types
111 * @throws PfModelException on errors updating policy types
113 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
114 throws PfModelException;
117 * Delete policy type.
119 * @param name the name of the policy type to delete.
120 * @param version the version of the policy type to delete.
121 * @return the TOSCA service template containing the policy type that was deleted
122 * @throws PfModelException on errors deleting policy types
124 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
125 throws PfModelException;
130 * @param name the name of the policy to get, null to get all policies
131 * @param version the version of the policy to get, null to get all versions of a policy
132 * @return the policies found
133 * @throws PfModelException on errors getting policies
135 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
140 * @param name the name of the policy to get, null to get all policies
141 * @param version the version of the policy to get, null to get all versions of a policy
142 * @return the policies found
143 * @throws PfModelException on errors getting policies
145 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
148 * Get policies for a policy type name.
150 * @param policyTypeName the name of the policy type for which to get policies
151 * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
153 * @return the policies found
154 * @throws PfModelException on errors getting policies
156 public ToscaServiceTemplate getPolicies4PolicyType(@NonNull final String policyTypeName,
157 final String policyTypeVersion) throws PfModelException;
160 * Get policies for a policy type name.
162 * @param policyTypeName the name of the policy type for which to get policies
163 * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
165 * @return the policies found
166 * @throws PfModelException on errors getting policies
168 public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
169 final String policyTypeVersion) throws PfModelException;
172 * Get latest policies.
174 * @param name the name of the policy to get, null to get all policies
175 * @return the policies found
176 * @throws PfModelException on errors getting policies
178 public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException;
181 * Get latest policies.
183 * @param name the name of the policy to get, null to get all policies
184 * @return the policies found
185 * @throws PfModelException on errors getting policies
187 public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException;
192 * @param serviceTemplate the service template containing the definitions of the new policies to be created.
193 * @return the TOSCA service template containing the policy types that were created
194 * @throws PfModelException on errors creating policies
196 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
197 throws PfModelException;
202 * @param serviceTemplate the service template containing the definitions of the policies to be updated.
203 * @return the TOSCA service template containing the policies that were updated
204 * @throws PfModelException on errors updating policies
206 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
207 throws PfModelException;
212 * @param name the name of the policy to delete.
213 * @param version the version of the policy to delete.
214 * @return the TOSCA service template containing the policy that was deleted
215 * @throws PfModelException on errors deleting a policy
217 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
218 throws PfModelException;
221 * Get legacy operational policy.
223 * @param policyId ID of the policy.
224 * @return the policies found
225 * @throws PfModelException on errors getting policies
227 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException;
230 * Create legacy operational policy.
232 * @param legacyOperationalPolicy the definition of the policy to be created.
233 * @return the created policy
234 * @throws PfModelException on errors creating policies
236 public LegacyOperationalPolicy createOperationalPolicy(
237 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
240 * Update legacy operational policy.
242 * @param legacyOperationalPolicy the definition of the policy to be updated
243 * @return the updated policy
244 * @throws PfModelException on errors updating policies
246 public LegacyOperationalPolicy updateOperationalPolicy(
247 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
250 * Delete legacy operational policy.
252 * @param policyId ID of the policy.
253 * @return the deleted policy
254 * @throws PfModelException on errors deleting policies
256 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException;
259 * Get legacy guard policy.
261 * @param policyId ID of the policy.
262 * @return the policies found
263 * @throws PfModelException on errors getting policies
265 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException;
268 * Create legacy guard policy.
270 * @param legacyGuardPolicy the definition of the policy to be created.
271 * @return the created policy
272 * @throws PfModelException on errors creating policies
274 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
275 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
278 * Update legacy guard policy.
280 * @param legacyGuardPolicy the definition of the policy to be updated
281 * @return the updated policy
282 * @throws PfModelException on errors updating policies
284 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
285 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
288 * Delete legacy guard policy.
290 * @param policyId ID of the policy.
291 * @return the deleted policy
292 * @throws PfModelException on errors deleting policies
294 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
295 throws PfModelException;
300 * @param name the name of the policy to get, null to get all PDP groups
301 * @param version the version of the policy to get, null to get all versions of a PDP group
302 * @return the PDP groups found
303 * @throws PfModelException on errors getting PDP groups
305 public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException;
308 * Get latest PDP Groups, returns PDP groups in all states.
310 * @param name the name of the PDP group to get, null to get all PDP groups
311 * @return the PDP groups found
312 * @throws PfModelException on errors getting policies
314 public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException;
317 * Get a filtered list of PDP groups, returns only active PDP groups.
319 * @param pdpType The PDP type filter for the returned PDP groups, null to get policy types across PDP subgroups
320 * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
321 * @return the PDP groups found
323 public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
324 @NonNull final List<Pair<String, String>> supportedPolicyTypes);
327 * Creates PDP groups.
329 * @param pdpGroups a specification of the PDP groups to create
330 * @return the PDP groups created
331 * @throws PfModelException on errors creating PDP groups
333 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
336 * Updates PDP groups.
338 * @param pdpGroups a specification of the PDP groups to update
339 * @return the PDP groups updated
340 * @throws PfModelException on errors updating PDP groups
342 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
345 * Update a PDP subgroup.
347 * @param pdpGroupName the name of the PDP group of the PDP subgroup
348 * @param pdpGroupVersion the version of the PDP group of the PDP subgroup
349 * @param pdpSubGroup the PDP subgroup to be updated
350 * @throws PfModelException on errors updating PDP subgroups
352 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
353 @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException;
358 * @param pdpGroupName the name of the PDP group of the PDP subgroup
359 * @param pdpGroupVersion the version of the PDP group of the PDP subgroup
360 * @param pdpSubGroup the PDP subgroup to be updated
361 * @param pdp the PDP to be updated
362 * @throws PfModelException on errors updating PDP subgroups
364 public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
365 @NonNull final String pdpSubGroup, @NonNull final Pdp pdp) throws PfModelException;
368 * Delete a PDP group.
370 * @param name the name of the policy to get, null to get all PDP groups
371 * @param version the version of the policy to get, null to get all versions of a PDP group
372 * @return the PDP group deleted
373 * @throws PfModelException on errors deleting PDP groups
375 public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException;
378 * Get PDP statistics.
380 * @param name the name of the PDP group to get statistics for, null to get all PDP groups
381 * @param version the version of the PDP group to get statistics for, null to get all versions of a PDP group
382 * @return the statistics found
383 * @throws PfModelException on errors getting statistics
385 public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException;
388 * Update PDP statistics for a PDP.
390 * @param pdpGroupName the name of the PDP group containing the PDP that the statistics are for
391 * @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for
392 * @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for
393 * @param pdpInstanceId the instance ID of the PDP to update statistics for
394 * @throws PfModelException on errors updating statistics
396 public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
397 @NonNull final String pdpType, @NonNull final String pdpInstanceId,
398 @NonNull final PdpStatistics pdppStatistics) throws PfModelException;
401 * Get deployed policies.
403 * @param name the name of the policy to get, null to get all policies
404 * @return the policies deployed as a map of policy lists keyed by PDP group name and version
405 * @throws PfModelException on errors getting policies
407 public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
408 throws PfModelException;