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.PdpGroup;
38 import org.onap.policy.models.pdp.concepts.PdpStatistics;
39 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
40 import org.onap.policy.models.provider.PolicyModelsProvider;
41 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
45 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
46 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
47 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
50 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
52 * @author Liam Fallon (liam.fallon@est.tech)
53 * @author Chenfei Gao (cgao@research.att.com)
55 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
57 * Constructor that takes the parameters.
59 * @param parameters the parameters for the provider
61 public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {}
64 public void init() throws PfModelException {
65 // Not required on the dummy provider
70 // Not required on the dummy provider
74 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
75 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
79 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
80 return new ArrayList<>();
84 public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException {
89 public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException {
90 return new ArrayList<>();
94 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
95 throws PfModelException {
96 return serviceTemplate;
100 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
101 throws PfModelException {
102 return serviceTemplate;
106 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
107 throws PfModelException {
108 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
112 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
113 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
117 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
118 return new ArrayList<>();
122 public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
123 final String policyTypeVersion) throws PfModelException {
124 return new ArrayList<>();
128 public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException {
133 public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException {
134 return new ArrayList<>();
138 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
139 throws PfModelException {
140 return serviceTemplate;
144 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
145 throws PfModelException {
146 return serviceTemplate;
150 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
151 throws PfModelException {
152 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
157 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
158 return new LegacyOperationalPolicy();
162 public LegacyOperationalPolicy createOperationalPolicy(
163 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
164 return legacyOperationalPolicy;
168 public LegacyOperationalPolicy updateOperationalPolicy(
169 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
170 return legacyOperationalPolicy;
174 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
175 return new LegacyOperationalPolicy();
179 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
180 return new HashMap<>();
184 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
185 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
186 return new HashMap<>();
190 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
191 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
192 return new HashMap<>();
196 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
197 throws PfModelException {
198 return new HashMap<>();
202 public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException {
203 return new ArrayList<>();
207 public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException {
208 return new ArrayList<>();
212 public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
213 @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
214 return new ArrayList<>();
218 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
219 return new ArrayList<>();
223 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
224 return new ArrayList<>();
228 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
229 @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException {
234 public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException {
239 public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException {
240 return new ArrayList<>();
244 public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
245 @NonNull final String pdpType, @NonNull final String pdpInstanceId,
246 @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
251 public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
252 throws PfModelException {
257 * Return a ToscaServicetemplate dummy response.
259 * @param fileName the file name containing the dummy response
260 * @return the ToscaServiceTemplate with the dummy response
262 protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
263 StandardCoder standardCoder = new StandardCoder();
264 ToscaServiceTemplate serviceTemplate;
268 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
269 if (serviceTemplate == null) {
270 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
272 } catch (Exception exc) {
273 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
276 return serviceTemplate;