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.PdpGroups;
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 List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName) 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 PdpGroups getPdpGroups(final String name, final String version) throws PfModelException {
207 public PdpGroups getLatestPdpGroups(final String name) throws PfModelException {
212 public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
213 @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
218 public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
223 public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
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<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException {
256 * Return a ToscaServicetemplate dummy response.
258 * @param fileName the file name containing the dummy response
259 * @return the ToscaServiceTemplate with the dummy response
261 protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
262 StandardCoder standardCoder = new StandardCoder();
263 ToscaServiceTemplate serviceTemplate;
267 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
268 if (serviceTemplate == null) {
269 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
271 } catch (Exception exc) {
272 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
275 return serviceTemplate;