2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.provider.impl;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
29 import javax.ws.rs.core.Response;
30 import lombok.NonNull;
32 import org.apache.commons.lang3.tuple.Pair;
33 import org.onap.policy.common.utils.coder.StandardCoder;
34 import org.onap.policy.common.utils.resources.ResourceUtils;
35 import org.onap.policy.models.base.PfModelException;
36 import org.onap.policy.models.base.PfModelRuntimeException;
37 import org.onap.policy.models.pdp.concepts.Pdp;
38 import org.onap.policy.models.pdp.concepts.PdpGroup;
39 import org.onap.policy.models.pdp.concepts.PdpStatistics;
40 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
41 import org.onap.policy.models.provider.PolicyModelsProvider;
42 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
46 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
47 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
48 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
51 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
53 * @author Liam Fallon (liam.fallon@est.tech)
54 * @author Chenfei Gao (cgao@research.att.com)
56 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
58 * Constructor that takes the parameters.
60 * @param parameters the parameters for the provider
62 public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {}
65 public void init() throws PfModelException {
66 // Not required on the dummy provider
71 // Not required on the dummy provider
75 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
76 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
80 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
81 return new ArrayList<>();
85 public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException {
90 public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException {
91 return new ArrayList<>();
95 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
96 throws PfModelException {
97 return serviceTemplate;
101 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
102 throws PfModelException {
103 return serviceTemplate;
107 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
108 throws PfModelException {
109 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
113 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
114 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
118 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
119 return new ArrayList<>();
123 public ToscaServiceTemplate getPolicies4PolicyType(@NonNull String policyTypeName, String policyTypeVersion)
124 throws PfModelException {
129 public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
130 final String policyTypeVersion) throws PfModelException {
131 return new ArrayList<>();
135 public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException {
140 public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException {
141 return new ArrayList<>();
145 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
146 throws PfModelException {
147 return serviceTemplate;
151 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
152 throws PfModelException {
153 return serviceTemplate;
157 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
158 throws PfModelException {
159 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
164 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
165 return new LegacyOperationalPolicy();
169 public LegacyOperationalPolicy createOperationalPolicy(
170 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
171 return legacyOperationalPolicy;
175 public LegacyOperationalPolicy updateOperationalPolicy(
176 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
177 return legacyOperationalPolicy;
181 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
182 return new LegacyOperationalPolicy();
186 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
187 return new HashMap<>();
191 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
192 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
193 return new HashMap<>();
197 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
198 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
199 return new HashMap<>();
203 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
204 throws PfModelException {
205 return new HashMap<>();
209 public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException {
210 return new ArrayList<>();
214 public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException {
215 return new ArrayList<>();
219 public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
220 @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
221 return new ArrayList<>();
225 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
226 return new ArrayList<>();
230 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
231 return new ArrayList<>();
235 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
236 @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException {
241 public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion,
242 @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException {
247 public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException {
252 public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException {
253 return new ArrayList<>();
257 public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
258 @NonNull final String pdpType, @NonNull final String pdpInstanceId,
259 @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
264 public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
265 throws PfModelException {
270 * Return a ToscaServicetemplate dummy response.
272 * @param fileName the file name containing the dummy response
273 * @return the ToscaServiceTemplate with the dummy response
275 protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
276 StandardCoder standardCoder = new StandardCoder();
277 ToscaServiceTemplate serviceTemplate;
281 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
282 if (serviceTemplate == null) {
283 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
285 } catch (Exception exc) {
286 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
289 return serviceTemplate;