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.PdpGroups;
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;
58 * @param name the name of the policy type to get, set to null to get all policy types
59 * @param version the version of the policy type to get, set to null to get all versions
60 * @return the policy types found
61 * @throws PfModelException on errors getting policy types
63 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException;
68 * @param name the name of the policy type to get, set to null to get all policy types
69 * @param version the version of the policy type to get, set to null to get all versions
70 * @return the policy types found
71 * @throws PfModelException on errors getting policy types
73 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
76 * Get latest policy types.
78 * @param name the name of the policy type to get, set to null to get all policy types
79 * @return the policy types found
80 * @throws PfModelException on errors getting policy types
82 public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException;
85 * Get latest policy types.
87 * @param name the name of the policy type to get, set to null to get all policy types
88 * @return the policy types found
89 * @throws PfModelException on errors getting policy types
91 public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException;
94 * Create policy types.
96 * @param serviceTemplate the service template containing the definition of the policy types to be created
97 * @return the TOSCA service template containing the created policy types
98 * @throws PfModelException on errors creating policy types
100 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
101 throws PfModelException;
104 * Create policy types.
106 * @param serviceTemplate the service template containing the definition of the policy types to be modified
107 * @return the TOSCA service template containing the modified policy types
108 * @throws PfModelException on errors updating policy types
110 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
111 throws PfModelException;
114 * Delete policy type.
116 * @param name the name of the policy type to delete.
117 * @param version the version of the policy type to delete.
118 * @return the TOSCA service template containing the policy type that was deleted
119 * @throws PfModelException on errors deleting policy types
121 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
122 throws PfModelException;
127 * @param name the name of the policy to get, null to get all policies
128 * @param version the version of the policy to get, null to get all versions of a policy
129 * @return the policies found
130 * @throws PfModelException on errors getting policies
132 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException;
137 * @param name the name of the policy to get, null to get all policies
138 * @param version the version of the policy to get, null to get all versions of a policy
139 * @return the policies found
140 * @throws PfModelException on errors getting policies
142 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
145 * Get policies for a policy type name.
147 * @param policyTypeName the name of the policy type for which to get policies
148 * @return the policies found
149 * @throws PfModelException on errors getting policies
151 public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName) throws PfModelException;
154 * Get latest policies.
156 * @param name the name of the policy to get, null to get all policies
157 * @return the policies found
158 * @throws PfModelException on errors getting policies
160 public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException;
163 * Get latest policies.
165 * @param name the name of the policy to get, null to get all policies
166 * @return the policies found
167 * @throws PfModelException on errors getting policies
169 public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException;
174 * @param serviceTemplate the service template containing the definitions of the new policies to be created.
175 * @return the TOSCA service template containing the policy types that were created
176 * @throws PfModelException on errors creating policies
178 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
179 throws PfModelException;
184 * @param serviceTemplate the service template containing the definitions of the policies to be updated.
185 * @return the TOSCA service template containing the policies that were updated
186 * @throws PfModelException on errors updating policies
188 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
189 throws PfModelException;
194 * @param name the name of the policy to delete.
195 * @param version the version of the policy to delete.
196 * @return the TOSCA service template containing the policy that was deleted
197 * @throws PfModelException on errors deleting a policy
199 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
200 throws PfModelException;
203 * Get legacy operational policy.
205 * @param policyId ID of the policy.
206 * @return the policies found
207 * @throws PfModelException on errors getting policies
209 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException;
212 * Create legacy operational policy.
214 * @param legacyOperationalPolicy the definition of the policy to be created.
215 * @return the created policy
216 * @throws PfModelException on errors creating policies
218 public LegacyOperationalPolicy createOperationalPolicy(
219 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
222 * Update legacy operational policy.
224 * @param legacyOperationalPolicy the definition of the policy to be updated
225 * @return the updated policy
226 * @throws PfModelException on errors updating policies
228 public LegacyOperationalPolicy updateOperationalPolicy(
229 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
232 * Delete legacy operational policy.
234 * @param policyId ID of the policy.
235 * @return the deleted policy
236 * @throws PfModelException on errors deleting policies
238 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException;
241 * Get legacy guard policy.
243 * @param policyId ID of the policy.
244 * @return the policies found
245 * @throws PfModelException on errors getting policies
247 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException;
250 * Create legacy guard policy.
252 * @param legacyGuardPolicy the definition of the policy to be created.
253 * @return the created policy
254 * @throws PfModelException on errors creating policies
256 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
257 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
260 * Update legacy guard policy.
262 * @param legacyGuardPolicy the definition of the policy to be updated
263 * @return the updated policy
264 * @throws PfModelException on errors updating policies
266 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
267 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
270 * Delete legacy guard policy.
272 * @param policyId ID of the policy.
273 * @return the deleted policy
274 * @throws PfModelException on errors deleting policies
276 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
277 throws PfModelException;
282 * @param name the name of the policy to get, null to get all PDP groups
283 * @param version the version of the policy to get, null to get all versions of a PDP group
284 * @return the PDP groups found
285 * @throws PfModelException on errors getting PDP groups
287 public PdpGroups getPdpGroups(final String name, final String version) throws PfModelException;
290 * Get latest PDP Groups.
292 * @param name the name of the PDP group to get, null to get all PDP groups
293 * @return the PDP groups found
294 * @throws PfModelException on errors getting policies
296 public PdpGroups getLatestPdpGroups(final String name) throws PfModelException;
299 * Get a filtered list of PDP groups.
301 * @param pdpType The PDP type filter for the returned PDP groups
302 * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
303 * @return the PDP groups found
305 public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
306 @NonNull final List<Pair<String, String>> supportedPolicyTypes);
309 * Creates PDP groups.
311 * @param pdpGroups a specification of the PDP groups to create
312 * @return the PDP groups created
313 * @throws PfModelException on errors creating PDP groups
315 public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException;
318 * Updates PDP groups.
320 * @param pdpGroups a specification of the PDP groups to update
321 * @return the PDP groups updated
322 * @throws PfModelException on errors updating PDP groups
324 public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException;
328 * Update a PDP subgroup.
330 * @param pdpGroupName the name of the PDP group of the PDP subgroup
331 * @param pdpGroupVersion the version of the PDP group of the PDP subgroup
332 * @param pdpSubGroup the PDP subgroup to be updated
333 * @throws PfModelException on errors updating PDP subgroups
335 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
336 @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException;
339 * Delete a PDP group.
341 * @param name the name of the policy to get, null to get all PDP groups
342 * @param version the version of the policy to get, null to get all versions of a PDP group
343 * @return the PDP group deleted
344 * @throws PfModelException on errors deleting PDP groups
346 public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException;
349 * Get PDP statistics.
351 * @param name the name of the PDP group to get statistics for, null to get all PDP groups
352 * @param version the version of the PDP group to get statistics for, null to get all versions of a PDP group
353 * @return the statistics found
354 * @throws PfModelException on errors getting statistics
356 public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException;
359 * Update PDP statistics for a PDP.
361 * @param pdpGroupName the name of the PDP group containing the PDP that the statistics are for
362 * @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for
363 * @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for
364 * @param pdpInstanceId the instance ID of the PDP to update statistics for
365 * @throws PfModelException on errors updating statistics
367 public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
368 @NonNull final String pdpType, @NonNull final String pdpInstanceId,
369 @NonNull final PdpStatistics pdppStatistics) throws PfModelException;
372 * Get deployed policies.
374 * @param name the name of the policy to get, null to get all policies
375 * @return the policies deployed as a map of policy lists keyed by PDP group
376 * @throws PfModelException on errors getting policies
378 public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException;