2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
\r
6 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
\r
7 * Modifications Copyright (C) 2020 Nordix Foundation.
\r
8 * ================================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
21 * SPDX-License-Identifier: Apache-2.0
\r
22 * ============LICENSE_END=========================================================
\r
25 package org.onap.policy.api.main.rest;
\r
27 import io.swagger.annotations.Api;
\r
28 import io.swagger.annotations.ApiOperation;
\r
29 import io.swagger.annotations.ApiParam;
\r
30 import io.swagger.annotations.ApiResponse;
\r
31 import io.swagger.annotations.ApiResponses;
\r
32 import io.swagger.annotations.Authorization;
\r
33 import io.swagger.annotations.BasicAuthDefinition;
\r
34 import io.swagger.annotations.Extension;
\r
35 import io.swagger.annotations.ExtensionProperty;
\r
36 import io.swagger.annotations.Info;
\r
37 import io.swagger.annotations.ResponseHeader;
\r
38 import io.swagger.annotations.SecurityDefinition;
\r
39 import io.swagger.annotations.SwaggerDefinition;
\r
41 import java.util.UUID;
\r
43 import javax.ws.rs.Consumes;
\r
44 import javax.ws.rs.DELETE;
\r
45 import javax.ws.rs.DefaultValue;
\r
46 import javax.ws.rs.GET;
\r
47 import javax.ws.rs.HeaderParam;
\r
48 import javax.ws.rs.POST;
\r
49 import javax.ws.rs.Path;
\r
50 import javax.ws.rs.PathParam;
\r
51 import javax.ws.rs.Produces;
\r
52 import javax.ws.rs.QueryParam;
\r
53 import javax.ws.rs.core.Response;
\r
55 import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
\r
56 import org.onap.policy.api.main.rest.provider.PolicyProvider;
\r
57 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
\r
58 import org.onap.policy.api.main.rest.provider.StatisticsProvider;
\r
59 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
\r
60 import org.onap.policy.common.endpoints.report.HealthCheckReport;
\r
61 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
\r
62 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
\r
63 import org.onap.policy.models.base.PfModelException;
\r
64 import org.onap.policy.models.base.PfModelRuntimeException;
\r
65 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
66 import org.slf4j.Logger;
\r
67 import org.slf4j.LoggerFactory;
\r
70 * Class to provide REST API services.
\r
72 * @author Chenfei Gao (cgao@research.att.com)
\r
74 @Path("/policy/api/v1")
\r
75 @Api(value = "Policy Design API")
\r
76 @Produces({"application/json", "application/yaml"})
\r
77 @Consumes({"application/json", "application/yaml"})
\r
80 description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
\r
81 + " policy types, policy type implementation and policies which can be recognized"
\r
82 + " and executable by incorporated policy engines. It is an"
\r
83 + " independent component running rest service that takes all policy design API calls"
\r
84 + " from clients and then assign them to different API working functions. Besides"
\r
85 + " that, API is also exposed for clients to retrieve healthcheck status of this API"
\r
86 + " rest service and the statistics report including the counters of API invocation.",
\r
87 version = "1.0.0", title = "Policy Design",
\r
88 extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
\r
89 @ExtensionProperty(name = "component", value = "Policy Framework")})}),
\r
90 schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
\r
91 securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
\r
92 public class ApiRestController extends CommonRestController {
\r
94 private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);
\r
97 * Retrieves the healthcheck status of the API component.
\r
99 * @return the Response object containing the results of the API operation
\r
102 @Path("/healthcheck")
\r
103 @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",
\r
104 response = HealthCheckReport.class,
\r
105 responseHeaders = {
\r
106 @ResponseHeader(name = "X-MinorVersion",
\r
107 description = "Used to request or communicate a MINOR version back from the client"
\r
108 + " to the server, and from the server back to the client",
\r
109 response = String.class),
\r
110 @ResponseHeader(name = "X-PatchVersion",
\r
111 description = "Used only to communicate a PATCH version in a response for"
\r
112 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
113 response = String.class),
\r
114 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
115 response = String.class),
\r
116 @ResponseHeader(name = "X-ONAP-RequestID",
\r
117 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
118 authorizations = @Authorization(value = "basicAuth"), tags = {"HealthCheck",},
\r
120 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
121 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
122 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
123 @ApiResponse(code = 403, message = "Authorization Error"),
\r
124 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
126 getHealthCheck(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
128 updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
\r
129 return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck());
\r
133 * Retrieves the statistics report of the API component.
\r
135 * @return the Response object containing the results of the API operation
\r
138 @Path("/statistics")
\r
139 @ApiOperation(value = "Retrieve current statistics",
\r
140 notes = "Returns current statistics including the counters of API invocation",
\r
141 response = StatisticsReport.class,
\r
142 responseHeaders = {
\r
143 @ResponseHeader(name = "X-MinorVersion",
\r
144 description = "Used to request or communicate a MINOR version back from the client"
\r
145 + " to the server, and from the server back to the client",
\r
146 response = String.class),
\r
147 @ResponseHeader(name = "X-PatchVersion",
\r
148 description = "Used only to communicate a PATCH version in a response for"
\r
149 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
150 response = String.class),
\r
151 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
152 response = String.class),
\r
153 @ResponseHeader(name = "X-ONAP-RequestID",
\r
154 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
155 authorizations = @Authorization(value = "basicAuth"), tags = {"Statistics",},
\r
157 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
158 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
159 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
160 @ApiResponse(code = 403, message = "Authorization Error"),
\r
161 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
163 getStatistics(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
165 updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
\r
167 return makeOkResponse(requestId, new StatisticsProvider().fetchCurrentStatistics());
\r
171 * Retrieves all available policy types.
\r
173 * @return the Response object containing the results of the API operation
\r
176 @Path("/policytypes")
\r
177 @ApiOperation(value = "Retrieve existing policy types",
\r
178 notes = "Returns a list of existing policy types stored in Policy Framework",
\r
179 response = ToscaServiceTemplate.class,
\r
180 responseHeaders = {
\r
181 @ResponseHeader(name = "X-MinorVersion",
\r
182 description = "Used to request or communicate a MINOR version back from the client"
\r
183 + " to the server, and from the server back to the client",
\r
184 response = String.class),
\r
185 @ResponseHeader(name = "X-PatchVersion",
\r
186 description = "Used only to communicate a PATCH version in a response for"
\r
187 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
188 response = String.class),
\r
189 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
190 response = String.class),
\r
191 @ResponseHeader(name = "X-ONAP-RequestID",
\r
192 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
193 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
195 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
196 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
197 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
198 @ApiResponse(code = 403, message = "Authorization Error"),
\r
199 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
201 getAllPolicyTypes(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
203 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
204 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);
\r
205 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
206 return makeOkResponse(requestId, serviceTemplate);
\r
207 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
208 LOGGER.debug("GET /policytypes", pfme);
\r
209 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
210 return makeErrorResponse(requestId, pfme);
\r
215 * Retrieves all versions of a particular policy type.
\r
217 * @param policyTypeId the ID of specified policy type
\r
219 * @return the Response object containing the results of the API operation
\r
222 @Path("/policytypes/{policyTypeId}")
\r
223 @ApiOperation(value = "Retrieve all available versions of a policy type",
\r
224 notes = "Returns a list of all available versions for the specified policy type",
\r
225 response = ToscaServiceTemplate.class,
\r
226 responseHeaders = {
\r
227 @ResponseHeader(name = "X-MinorVersion",
\r
228 description = "Used to request or communicate a MINOR version back from the client"
\r
229 + " to the server, and from the server back to the client",
\r
230 response = String.class),
\r
231 @ResponseHeader(name = "X-PatchVersion",
\r
232 description = "Used only to communicate a PATCH version in a response for"
\r
233 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
234 response = String.class),
\r
235 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
236 response = String.class),
\r
237 @ResponseHeader(name = "X-ONAP-RequestID",
\r
238 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
239 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
241 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
242 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
243 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
244 @ApiResponse(code = 403, message = "Authorization Error"),
\r
245 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
246 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
247 public Response getAllVersionsOfPolicyType(
\r
248 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
249 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
251 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
252 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);
\r
253 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
254 return makeOkResponse(requestId, serviceTemplate);
\r
255 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
256 LOGGER.debug("GET /policytypes/{}", policyTypeId, pfme);
\r
257 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
258 return makeErrorResponse(requestId, pfme);
\r
263 * Retrieves specified version of a particular policy type.
\r
265 * @param policyTypeId the ID of specified policy type
\r
266 * @param versionId the version of specified policy type
\r
268 * @return the Response object containing the results of the API operation
\r
271 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
272 @ApiOperation(value = "Retrieve one particular version of a policy type",
\r
273 notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
\r
274 responseHeaders = {
\r
275 @ResponseHeader(name = "X-MinorVersion",
\r
276 description = "Used to request or communicate a MINOR version back from the client"
\r
277 + " to the server, and from the server back to the client",
\r
278 response = String.class),
\r
279 @ResponseHeader(name = "X-PatchVersion",
\r
280 description = "Used only to communicate a PATCH version in a response for"
\r
281 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
282 response = String.class),
\r
283 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
284 response = String.class),
\r
285 @ResponseHeader(name = "X-ONAP-RequestID",
\r
286 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
287 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
289 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
290 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
291 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
292 @ApiResponse(code = 403, message = "Authorization Error"),
\r
293 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
294 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
295 public Response getSpecificVersionOfPolicyType(
\r
296 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
297 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
298 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
300 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
301 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);
\r
302 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
303 return makeOkResponse(requestId, serviceTemplate);
\r
304 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
305 LOGGER.debug("GET /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
\r
306 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
307 return makeErrorResponse(requestId, pfme);
\r
312 * Retrieves latest version of a particular policy type.
\r
314 * @param policyTypeId the ID of specified policy type
\r
316 * @return the Response object containing the results of the API operation
\r
319 @Path("/policytypes/{policyTypeId}/versions/latest")
\r
320 @ApiOperation(value = "Retrieve latest version of a policy type",
\r
321 notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
\r
322 responseHeaders = {
\r
323 @ResponseHeader(name = "X-MinorVersion",
\r
324 description = "Used to request or communicate a MINOR version back from the client"
\r
325 + " to the server, and from the server back to the client",
\r
326 response = String.class),
\r
327 @ResponseHeader(name = "X-PatchVersion",
\r
328 description = "Used only to communicate a PATCH version in a response for"
\r
329 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
330 response = String.class),
\r
331 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
332 response = String.class),
\r
333 @ResponseHeader(name = "X-ONAP-RequestID",
\r
334 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
335 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
337 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
338 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
339 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
340 @ApiResponse(code = 403, message = "Authorization Error"),
\r
341 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
342 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
343 public Response getLatestVersionOfPolicyType(
\r
344 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
345 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
347 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
348 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
\r
349 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
350 return makeOkResponse(requestId, serviceTemplate);
\r
351 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
352 LOGGER.debug("GET /policytypes/{}/versions/latest", policyTypeId, pfme);
\r
353 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
354 return makeErrorResponse(requestId, pfme);
\r
359 * Creates a new policy type.
\r
361 * @param body the body of policy type following TOSCA definition
\r
363 * @return the Response object containing the results of the API operation
\r
366 @Path("/policytypes")
\r
367 @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",
\r
368 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
369 response = ToscaServiceTemplate.class,
\r
370 responseHeaders = {
\r
371 @ResponseHeader(name = "X-MinorVersion",
\r
372 description = "Used to request or communicate a MINOR version back from the client"
\r
373 + " to the server, and from the server back to the client",
\r
374 response = String.class),
\r
375 @ResponseHeader(name = "X-PatchVersion",
\r
376 description = "Used only to communicate a PATCH version in a response for"
\r
377 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
378 response = String.class),
\r
379 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
380 response = String.class),
\r
381 @ResponseHeader(name = "X-ONAP-RequestID",
\r
382 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
384 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
385 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
386 @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
\r
387 @ApiResponse(code = 401, message = "Authentication Error"),
\r
388 @ApiResponse(code = 403, message = "Authorization Error"),
\r
389 @ApiResponse(code = 406, message = "Not Acceptable Payload"),
\r
390 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
391 public Response createPolicyType(
\r
392 @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
\r
393 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
395 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
396 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
\r
399 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
400 ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);
\r
401 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);
\r
402 return makeOkResponse(requestId, serviceTemplate);
\r
403 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
404 LOGGER.debug("POST /policytypes", pfme);
\r
405 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.POST);
\r
406 return makeErrorResponse(requestId, pfme);
\r
411 * Deletes specified version of a particular policy type.
\r
413 * @param policyTypeId the ID of specified policy type
\r
414 * @param versionId the version of specified policy type
\r
416 * @return the Response object containing the results of the API operation
\r
419 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
420 @ApiOperation(value = "Delete one version of a policy type",
\r
421 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
422 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
423 + "The parameterizing TOSCA policies must be deleted first;",
\r
424 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
425 response = ToscaServiceTemplate.class,
\r
426 responseHeaders = {
\r
427 @ResponseHeader(name = "X-MinorVersion",
\r
428 description = "Used to request or communicate a MINOR version back from the client"
\r
429 + " to the server, and from the server back to the client",
\r
430 response = String.class),
\r
431 @ResponseHeader(name = "X-PatchVersion",
\r
432 description = "Used only to communicate a PATCH version in a response for"
\r
433 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
434 response = String.class),
\r
435 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
436 response = String.class),
\r
437 @ResponseHeader(name = "X-ONAP-RequestID",
\r
438 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
440 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
441 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
442 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
443 @ApiResponse(code = 403, message = "Authorization Error"),
\r
444 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
445 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
446 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
447 public Response deleteSpecificVersionOfPolicyType(
\r
448 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
449 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
450 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
452 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
453 ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);
\r
454 return makeOkResponse(requestId, serviceTemplate);
\r
455 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
456 LOGGER.debug("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
\r
457 return makeErrorResponse(requestId, pfme);
\r
462 * Retrieves all versions of a particular policy.
\r
464 * @param policyTypeId the ID of specified policy type
\r
465 * @param policyTypeVersion the version of specified policy type
\r
467 * @return the Response object containing the results of the API operation
\r
471 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
473 value = "Retrieve all versions of a policy created for a particular policy type version",
\r
474 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
\r
475 response = ToscaServiceTemplate.class,
\r
476 responseHeaders = {
\r
477 @ResponseHeader(name = "X-MinorVersion",
\r
478 description = "Used to request or communicate a MINOR version back from the client"
\r
479 + " to the server, and from the server back to the client",
\r
480 response = String.class),
\r
481 @ResponseHeader(name = "X-PatchVersion",
\r
482 description = "Used only to communicate a PATCH version in a response for"
\r
483 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
484 response = String.class),
\r
485 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
486 response = String.class),
\r
487 @ResponseHeader(name = "X-ONAP-RequestID",
\r
488 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
489 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy,"},
\r
491 @Extension(name = "interface info", properties = {
\r
492 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
493 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
497 @ApiResponses(value = {
\r
498 @ApiResponse(code = 401, message = "Authentication Error"),
\r
499 @ApiResponse(code = 403, message = "Authorization Error"),
\r
500 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
501 @ApiResponse(code = 500, message = "Internal Server Error")
\r
503 public Response getAllPolicies(
\r
504 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
505 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
506 required = true) String policyTypeVersion,
\r
507 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
508 @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
509 + " REFERENCED for fully referenced policies") PolicyFetchMode mode
\r
512 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
513 ToscaServiceTemplate serviceTemplate =
\r
514 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
\r
515 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
516 return makeOkResponse(requestId, serviceTemplate);
\r
517 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
518 LOGGER.debug("GET /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
\r
519 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
520 return makeErrorResponse(requestId, pfme);
\r
526 * Retrieves all versions of a particular policy.
\r
528 * @param policyTypeId the ID of specified policy type
\r
529 * @param policyTypeVersion the version of specified policy type
\r
530 * @param policyId the ID of specified policy
\r
532 * @return the Response object containing the results of the API operation
\r
536 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
537 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
\r
538 notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class,
\r
539 responseHeaders = {
\r
540 @ResponseHeader(name = "X-MinorVersion",
\r
541 description = "Used to request or communicate a MINOR version back from the client"
\r
542 + " to the server, and from the server back to the client",
\r
543 response = String.class),
\r
544 @ResponseHeader(name = "X-PatchVersion",
\r
545 description = "Used only to communicate a PATCH version in a response for"
\r
546 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
547 response = String.class),
\r
548 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
549 response = String.class),
\r
550 @ResponseHeader(name = "X-ONAP-RequestID",
\r
551 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
552 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
554 @Extension(name = "interface info", properties = {
\r
555 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
556 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
560 @ApiResponses(value = {
\r
561 @ApiResponse(code = 401, message = "Authentication Error"),
\r
562 @ApiResponse(code = 403, message = "Authorization Error"),
\r
563 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
564 @ApiResponse(code = 500, message = "Internal Server Error")
\r
566 public Response getAllVersionsOfPolicy(
\r
567 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
568 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
569 required = true) String policyTypeVersion,
\r
570 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
571 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
572 @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
573 + " REFERENCED for fully referenced policies") PolicyFetchMode mode
\r
575 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
576 ToscaServiceTemplate serviceTemplate =
\r
577 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
\r
578 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
579 return makeOkResponse(requestId, serviceTemplate);
\r
580 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
581 LOGGER.debug("/policytypes/{}/versions/{}/policies/{}", policyTypeId, policyTypeVersion, policyId, pfme);
\r
582 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
583 return makeErrorResponse(requestId, pfme);
\r
589 * Retrieves the specified version of a particular policy.
\r
591 * @param policyTypeId the ID of specified policy type
\r
592 * @param policyTypeVersion the version of specified policy type
\r
593 * @param policyId the ID of specified policy
\r
594 * @param policyVersion the version of specified policy
\r
596 * @return the Response object containing the results of the API operation
\r
600 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
601 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
\r
602 notes = "Returns a particular version of specified policy created for the specified policy type version",
\r
603 response = ToscaServiceTemplate.class,
\r
604 responseHeaders = {
\r
605 @ResponseHeader(name = "X-MinorVersion",
\r
606 description = "Used to request or communicate a MINOR version back from the client"
\r
607 + " to the server, and from the server back to the client",
\r
608 response = String.class),
\r
609 @ResponseHeader(name = "X-PatchVersion",
\r
610 description = "Used only to communicate a PATCH version in a response for"
\r
611 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
612 response = String.class),
\r
613 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
614 response = String.class),
\r
615 @ResponseHeader(name = "X-ONAP-RequestID",
\r
616 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
617 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
619 @Extension(name = "interface info", properties = {
\r
620 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
621 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
625 @ApiResponses(value = {
\r
626 @ApiResponse(code = 401, message = "Authentication Error"),
\r
627 @ApiResponse(code = 403, message = "Authorization Error"),
\r
628 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
629 @ApiResponse(code = 500, message = "Internal Server Error")
\r
631 public Response getSpecificVersionOfPolicy(
\r
632 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
633 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
634 required = true) String policyTypeVersion,
\r
635 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
636 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
637 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
638 @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
639 + " REFERENCED for fully referenced policies") PolicyFetchMode mode
\r
641 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
642 ToscaServiceTemplate serviceTemplate =
\r
643 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
\r
644 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
645 return makeOkResponse(requestId, serviceTemplate);
\r
646 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
647 LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
\r
648 policyId, policyVersion, pfme);
\r
649 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
650 return makeErrorResponse(requestId, pfme);
\r
656 * Retrieves the latest version of a particular policy.
\r
658 * @param policyTypeId the ID of specified policy type
\r
659 * @param policyTypeVersion the version of specified policy type
\r
660 * @param policyId the ID of specified policy
\r
662 * @return the Response object containing the results of the API operation
\r
665 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
\r
666 @ApiOperation(value = "Retrieve the latest version of a particular policy",
\r
667 notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
\r
668 responseHeaders = {
\r
669 @ResponseHeader(name = "X-MinorVersion",
\r
670 description = "Used to request or communicate a MINOR version back from the client"
\r
671 + " to the server, and from the server back to the client",
\r
672 response = String.class),
\r
673 @ResponseHeader(name = "X-PatchVersion",
\r
674 description = "Used only to communicate a PATCH version in a response for"
\r
675 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
676 response = String.class),
\r
677 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
678 response = String.class),
\r
679 @ResponseHeader(name = "X-ONAP-RequestID",
\r
680 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
681 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
683 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
684 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
685 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
686 @ApiResponse(code = 403, message = "Authorization Error"),
\r
687 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
688 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
689 public Response getLatestVersionOfPolicy(
\r
690 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
691 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
692 required = true) String policyTypeVersion,
\r
693 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
694 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
695 @QueryParam("mode") @ApiParam("Fetch mode for policies, TERSE for bare policies (default), "
\r
696 + "REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
698 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
699 ToscaServiceTemplate serviceTemplate =
\r
700 policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
\r
701 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
702 return makeOkResponse(requestId, serviceTemplate);
\r
703 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
704 LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId, policyTypeVersion,
\r
706 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
707 return makeErrorResponse(requestId, pfme);
\r
712 * Creates a new policy for a particular policy type and version.
\r
714 * @param policyTypeId the ID of specified policy type
\r
715 * @param policyTypeVersion the version of specified policy type
\r
716 * @param body the body of policy following TOSCA definition
\r
718 * @return the Response object containing the results of the API operation
\r
721 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
722 @ApiOperation(value = "Create a new policy for a policy type version",
\r
723 notes = "Client should provide TOSCA body of the new policy",
\r
724 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,
\r
725 responseHeaders = {
\r
726 @ResponseHeader(name = "X-MinorVersion",
\r
727 description = "Used to request or communicate a MINOR version back from the client"
\r
728 + " to the server, and from the server back to the client",
\r
729 response = String.class),
\r
730 @ResponseHeader(name = "X-PatchVersion",
\r
731 description = "Used only to communicate a PATCH version in a response for"
\r
732 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
733 response = String.class),
\r
734 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
735 response = String.class),
\r
736 @ResponseHeader(name = "X-ONAP-RequestID",
\r
737 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
739 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
740 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
741 @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
\r
742 @ApiResponse(code = 401, message = "Authentication Error"),
\r
743 @ApiResponse(code = 403, message = "Authorization Error"),
\r
744 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
745 @ApiResponse(code = 406, message = "Not Acceptable Payload"),
\r
746 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
747 public Response createPolicy(
\r
748 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
749 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
750 required = true) String policyTypeVersion,
\r
751 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
752 @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
754 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
755 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
\r
756 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
\r
759 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
760 ToscaServiceTemplate serviceTemplate = policyProvider.createPolicy(policyTypeId, policyTypeVersion, body);
\r
761 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
\r
762 return makeOkResponse(requestId, serviceTemplate);
\r
763 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
764 LOGGER.debug("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
\r
765 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
\r
766 return makeErrorResponse(requestId, pfme);
\r
771 * Creates one or more new policies in one call.
\r
773 * @param body the body of policy following TOSCA definition
\r
775 * @return the Response object containing the results of the API operation
\r
779 @ApiOperation(value = "Create one or more new policies",
\r
780 notes = "Client should provide TOSCA body of the new polic(ies)",
\r
781 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,
\r
782 responseHeaders = {
\r
783 @ResponseHeader(name = "X-MinorVersion",
\r
784 description = "Used to request or communicate a MINOR version back from the client"
\r
785 + " to the server, and from the server back to the client",
\r
786 response = String.class),
\r
787 @ResponseHeader(name = "X-PatchVersion",
\r
788 description = "Used only to communicate a PATCH version in a response for"
\r
789 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
790 response = String.class),
\r
791 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
792 response = String.class),
\r
793 @ResponseHeader(name = "X-ONAP-RequestID",
\r
794 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
796 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
797 @ExtensionProperty(name = "last-mod-release", value = "El Alto")})})
\r
798 @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
\r
799 @ApiResponse(code = 401, message = "Authentication Error"),
\r
800 @ApiResponse(code = 403, message = "Authorization Error"),
\r
801 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
802 @ApiResponse(code = 406, message = "Not Acceptable Payload"),
\r
803 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
804 public Response createPolicies(
\r
805 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
806 @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
808 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
809 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));
\r
812 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
813 ToscaServiceTemplate serviceTemplate = policyProvider.createPolicies(body);
\r
814 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
\r
815 return makeOkResponse(requestId, serviceTemplate);
\r
816 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
817 LOGGER.debug("POST /policies", pfme);
\r
818 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
\r
819 return makeErrorResponse(requestId, pfme);
\r
824 * Deletes the specified version of a particular policy.
\r
826 * @param policyTypeId the ID of specified policy type
\r
827 * @param policyTypeVersion the version of specified policy type
\r
828 * @param policyId the ID of specified policy
\r
829 * @param policyVersion the version of specified policy
\r
831 * @return the Response object containing the results of the API operation
\r
834 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
835 @ApiOperation(value = "Delete a particular version of a policy",
\r
836 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
837 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",}, response = ToscaServiceTemplate.class,
\r
838 responseHeaders = {
\r
839 @ResponseHeader(name = "X-MinorVersion",
\r
840 description = "Used to request or communicate a MINOR version back from the client"
\r
841 + " to the server, and from the server back to the client",
\r
842 response = String.class),
\r
843 @ResponseHeader(name = "X-PatchVersion",
\r
844 description = "Used only to communicate a PATCH version in a response for"
\r
845 + " troubleshooting purposes only, and will not be provided by" + " the client on request",
\r
846 response = String.class),
\r
847 @ResponseHeader(name = "X-LatestVersion", description = "Used only to communicate an API's latest version",
\r
848 response = String.class),
\r
849 @ResponseHeader(name = "X-ONAP-RequestID",
\r
850 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
852 @Extension(name = "interface info", properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
853 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
854 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
855 @ApiResponse(code = 403, message = "Authorization Error"),
\r
856 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
857 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
858 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
859 public Response deleteSpecificVersionOfPolicy(
\r
860 @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
\r
861 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
862 required = true) String policyTypeVersion,
\r
863 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
864 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
865 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
867 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
868 ToscaServiceTemplate serviceTemplate =
\r
869 policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
870 return makeOkResponse(requestId, serviceTemplate);
\r
871 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
872 LOGGER.debug("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
\r
873 policyId, policyVersion, pfme);
\r
874 return makeErrorResponse(requestId, pfme);
\r
878 private enum Target {
\r
884 private enum Result {
\r
889 private enum HttpMethod {
\r
894 private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {
\r
896 ApiStatisticsManager.updateTotalApiCallCount();
\r
900 updatePolicyStats(result, http);
\r
903 updatePolicyTypeStats(result, http);
\r
906 ApiStatisticsManager.updateApiCallSuccessCount();
\r
911 private void updatePolicyStats(Result result, HttpMethod http) {
\r
912 if (result == Result.SUCCESS) {
\r
913 if (http == HttpMethod.GET) {
\r
914 ApiStatisticsManager.updateApiCallSuccessCount();
\r
915 ApiStatisticsManager.updateTotalPolicyGetCount();
\r
916 ApiStatisticsManager.updatePolicyGetSuccessCount();
\r
917 } else if (http == HttpMethod.POST) {
\r
918 ApiStatisticsManager.updateApiCallSuccessCount();
\r
919 ApiStatisticsManager.updateTotalPolicyPostCount();
\r
920 ApiStatisticsManager.updatePolicyPostSuccessCount();
\r
923 if (http == HttpMethod.GET) {
\r
924 ApiStatisticsManager.updateApiCallFailureCount();
\r
925 ApiStatisticsManager.updateTotalPolicyGetCount();
\r
926 ApiStatisticsManager.updatePolicyGetFailureCount();
\r
928 ApiStatisticsManager.updateApiCallFailureCount();
\r
929 ApiStatisticsManager.updateTotalPolicyPostCount();
\r
930 ApiStatisticsManager.updatePolicyPostFailureCount();
\r
935 private void updatePolicyTypeStats(Result result, HttpMethod http) {
\r
936 if (result == Result.SUCCESS) {
\r
937 if (http == HttpMethod.GET) {
\r
938 ApiStatisticsManager.updateApiCallSuccessCount();
\r
939 ApiStatisticsManager.updateTotalPolicyTypeGetCount();
\r
940 ApiStatisticsManager.updatePolicyTypeGetSuccessCount();
\r
941 } else if (http == HttpMethod.POST) {
\r
942 ApiStatisticsManager.updateApiCallSuccessCount();
\r
943 ApiStatisticsManager.updatePolicyTypePostSuccessCount();
\r
944 ApiStatisticsManager.updatePolicyTypePostSuccessCount();
\r
947 if (http == HttpMethod.GET) {
\r
948 ApiStatisticsManager.updateApiCallFailureCount();
\r
949 ApiStatisticsManager.updateTotalPolicyTypeGetCount();
\r
950 ApiStatisticsManager.updatePolicyTypeGetFailureCount();
\r
952 ApiStatisticsManager.updateApiCallFailureCount();
\r
953 ApiStatisticsManager.updateTotalPolicyTypePostCount();
\r
954 ApiStatisticsManager.updatePolicyTypePostFailureCount();
\r