2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
\r
6 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
20 * SPDX-License-Identifier: Apache-2.0
\r
21 * ============LICENSE_END=========================================================
\r
24 package org.onap.policy.api.main.rest;
\r
26 import io.swagger.annotations.Api;
\r
27 import io.swagger.annotations.ApiOperation;
\r
28 import io.swagger.annotations.ApiParam;
\r
29 import io.swagger.annotations.ApiResponse;
\r
30 import io.swagger.annotations.ApiResponses;
\r
31 import io.swagger.annotations.Authorization;
\r
32 import io.swagger.annotations.BasicAuthDefinition;
\r
33 import io.swagger.annotations.Extension;
\r
34 import io.swagger.annotations.ExtensionProperty;
\r
35 import io.swagger.annotations.Info;
\r
36 import io.swagger.annotations.ResponseHeader;
\r
37 import io.swagger.annotations.SecurityDefinition;
\r
38 import io.swagger.annotations.SwaggerDefinition;
\r
39 import java.util.List;
\r
40 import java.util.Map;
\r
41 import java.util.UUID;
\r
42 import javax.ws.rs.Consumes;
\r
43 import javax.ws.rs.DELETE;
\r
44 import javax.ws.rs.GET;
\r
45 import javax.ws.rs.HeaderParam;
\r
46 import javax.ws.rs.POST;
\r
47 import javax.ws.rs.Path;
\r
48 import javax.ws.rs.PathParam;
\r
49 import javax.ws.rs.Produces;
\r
50 import javax.ws.rs.core.Response;
\r
51 import org.apache.commons.lang3.tuple.Pair;
\r
52 import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
\r
53 import org.onap.policy.api.main.rest.provider.PolicyProvider;
\r
54 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
\r
55 import org.onap.policy.api.main.rest.provider.StatisticsProvider;
\r
56 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
\r
57 import org.onap.policy.common.endpoints.report.HealthCheckReport;
\r
58 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
\r
59 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
\r
60 import org.onap.policy.models.base.PfModelException;
\r
61 import org.onap.policy.models.base.PfModelRuntimeException;
\r
62 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
\r
63 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
64 import org.slf4j.Logger;
\r
65 import org.slf4j.LoggerFactory;
\r
68 * Class to provide REST API services.
\r
70 * @author Chenfei Gao (cgao@research.att.com)
\r
72 @Path("/policy/api/v1")
\r
73 @Api(value = "Policy Design API")
\r
74 @Produces({"application/json", "application/yaml"})
\r
75 @Consumes({"application/json", "application/yaml"})
\r
76 @SwaggerDefinition(info = @Info(
\r
77 description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
\r
78 + " policy types, policy type implementation and policies which can be recognized"
\r
79 + " and executable by incorporated policy engines. It is an"
\r
80 + " independent component running rest service that takes all policy design API calls"
\r
81 + " from clients and then assign them to different API working functions. Besides"
\r
82 + " that, API is also exposed for clients to retrieve healthcheck status of this API"
\r
83 + " rest service and the statistics report including the counters of API invocation.",
\r
85 title = "Policy Design",
\r
87 @Extension(properties = {
\r
88 @ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
\r
89 @ExtensionProperty(name = "component", value = "Policy Framework")
\r
92 schemes = { SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS },
\r
93 securityDefinition = @SecurityDefinition(basicAuthDefinitions = { @BasicAuthDefinition(key = "basicAuth") }))
\r
94 public class ApiRestController extends CommonRestController {
\r
96 private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);
\r
99 * Retrieves the healthcheck status of the API component.
\r
101 * @return the Response object containing the results of the API operation
\r
104 @Path("/healthcheck")
\r
105 @ApiOperation(value = "Perform a system healthcheck",
\r
106 notes = "Returns healthy status of the Policy API component",
\r
107 response = HealthCheckReport.class,
\r
108 responseHeaders = {
\r
109 @ResponseHeader(name = "X-MinorVersion",
\r
110 description = "Used to request or communicate a MINOR version back from the client"
\r
111 + " to the server, and from the server back to the client",
\r
112 response = String.class),
\r
113 @ResponseHeader(name = "X-PatchVersion",
\r
114 description = "Used only to communicate a PATCH version in a response for"
\r
115 + " troubleshooting purposes only, and will not be provided by"
\r
116 + " the client on request",
\r
117 response = String.class),
\r
118 @ResponseHeader(name = "X-LatestVersion",
\r
119 description = "Used only to communicate an API's latest version",
\r
120 response = String.class),
\r
121 @ResponseHeader(name = "X-ONAP-RequestID",
\r
122 description = "Used to track REST transactions for logging purpose",
\r
123 response = UUID.class)
\r
125 authorizations = @Authorization(value = "basicAuth"),
\r
126 tags = { "HealthCheck", },
\r
128 @Extension(name = "interface info", properties = {
\r
129 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
130 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
133 @ApiResponses(value = {
\r
134 @ApiResponse(code = 401, message = "Authentication Error"),
\r
135 @ApiResponse(code = 403, message = "Authorization Error"),
\r
136 @ApiResponse(code = 500, message = "Internal Server Error")
\r
138 public Response getHealthCheck(
\r
139 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
141 updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
\r
142 return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck());
\r
146 * Retrieves the statistics report of the API component.
\r
148 * @return the Response object containing the results of the API operation
\r
151 @Path("/statistics")
\r
152 @ApiOperation(value = "Retrieve current statistics",
\r
153 notes = "Returns current statistics including the counters of API invocation",
\r
154 response = StatisticsReport.class,
\r
155 responseHeaders = {
\r
156 @ResponseHeader(name = "X-MinorVersion",
\r
157 description = "Used to request or communicate a MINOR version back from the client"
\r
158 + " to the server, and from the server back to the client",
\r
159 response = String.class),
\r
160 @ResponseHeader(name = "X-PatchVersion",
\r
161 description = "Used only to communicate a PATCH version in a response for"
\r
162 + " troubleshooting purposes only, and will not be provided by"
\r
163 + " the client on request",
\r
164 response = String.class),
\r
165 @ResponseHeader(name = "X-LatestVersion",
\r
166 description = "Used only to communicate an API's latest version",
\r
167 response = String.class),
\r
168 @ResponseHeader(name = "X-ONAP-RequestID",
\r
169 description = "Used to track REST transactions for logging purpose",
\r
170 response = UUID.class)
\r
172 authorizations = @Authorization(value = "basicAuth"),
\r
173 tags = { "Statistics", },
\r
175 @Extension(name = "interface info", properties = {
\r
176 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
177 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
180 @ApiResponses(value = {
\r
181 @ApiResponse(code = 401, message = "Authentication Error"),
\r
182 @ApiResponse(code = 403, message = "Authorization Error"),
\r
183 @ApiResponse(code = 500, message = "Internal Server Error")
\r
185 public Response getStatistics(
\r
186 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
188 updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
\r
190 return makeOkResponse(requestId, new StatisticsProvider().fetchCurrentStatistics());
\r
194 * Retrieves all available policy types.
\r
196 * @return the Response object containing the results of the API operation
\r
199 @Path("/policytypes")
\r
200 @ApiOperation(value = "Retrieve existing policy types",
\r
201 notes = "Returns a list of existing policy types stored in Policy Framework",
\r
202 response = ToscaServiceTemplate.class,
\r
203 responseHeaders = {
\r
204 @ResponseHeader(name = "X-MinorVersion",
\r
205 description = "Used to request or communicate a MINOR version back from the client"
\r
206 + " to the server, and from the server back to the client",
\r
207 response = String.class),
\r
208 @ResponseHeader(name = "X-PatchVersion",
\r
209 description = "Used only to communicate a PATCH version in a response for"
\r
210 + " troubleshooting purposes only, and will not be provided by"
\r
211 + " the client on request",
\r
212 response = String.class),
\r
213 @ResponseHeader(name = "X-LatestVersion",
\r
214 description = "Used only to communicate an API's latest version",
\r
215 response = String.class),
\r
216 @ResponseHeader(name = "X-ONAP-RequestID",
\r
217 description = "Used to track REST transactions for logging purpose",
\r
218 response = UUID.class)
\r
220 authorizations = @Authorization(value = "basicAuth"),
\r
221 tags = { "PolicyType", },
\r
223 @Extension(name = "interface info", properties = {
\r
224 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
225 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
228 @ApiResponses(value = {
\r
229 @ApiResponse(code = 401, message = "Authentication Error"),
\r
230 @ApiResponse(code = 403, message = "Authorization Error"),
\r
231 @ApiResponse(code = 500, message = "Internal Server Error")
\r
233 public Response getAllPolicyTypes(
\r
234 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
236 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
237 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);
\r
238 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
239 return makeOkResponse(requestId, serviceTemplate);
\r
240 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
241 LOGGER.error("GET /policytypes", pfme);
\r
242 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
243 return makeErrorResponse(requestId, pfme);
\r
248 * Retrieves all versions of a particular policy type.
\r
250 * @param policyTypeId the ID of specified policy type
\r
252 * @return the Response object containing the results of the API operation
\r
255 @Path("/policytypes/{policyTypeId}")
\r
256 @ApiOperation(value = "Retrieve all available versions of a policy type",
\r
257 notes = "Returns a list of all available versions for the specified policy type",
\r
258 response = ToscaServiceTemplate.class,
\r
259 responseHeaders = {
\r
260 @ResponseHeader(name = "X-MinorVersion",
\r
261 description = "Used to request or communicate a MINOR version back from the client"
\r
262 + " to the server, and from the server back to the client",
\r
263 response = String.class),
\r
264 @ResponseHeader(name = "X-PatchVersion",
\r
265 description = "Used only to communicate a PATCH version in a response for"
\r
266 + " troubleshooting purposes only, and will not be provided by"
\r
267 + " the client on request",
\r
268 response = String.class),
\r
269 @ResponseHeader(name = "X-LatestVersion",
\r
270 description = "Used only to communicate an API's latest version",
\r
271 response = String.class),
\r
272 @ResponseHeader(name = "X-ONAP-RequestID",
\r
273 description = "Used to track REST transactions for logging purpose",
\r
274 response = UUID.class)
\r
276 authorizations = @Authorization(value = "basicAuth"),
\r
277 tags = { "PolicyType", },
\r
279 @Extension(name = "interface info", properties = {
\r
280 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
281 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
284 @ApiResponses(value = {
\r
285 @ApiResponse(code = 401, message = "Authentication Error"),
\r
286 @ApiResponse(code = 403, message = "Authorization Error"),
\r
287 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
288 @ApiResponse(code = 500, message = "Internal Server Error")
\r
290 public Response getAllVersionsOfPolicyType(
\r
291 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
292 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
294 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
295 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);
\r
296 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
297 return makeOkResponse(requestId, serviceTemplate);
\r
298 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
299 LOGGER.error("GET /policytypes/{}", policyTypeId, pfme);
\r
300 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
301 return makeErrorResponse(requestId, pfme);
\r
306 * Retrieves specified version of a particular policy type.
\r
308 * @param policyTypeId the ID of specified policy type
\r
309 * @param versionId the version of specified policy type
\r
311 * @return the Response object containing the results of the API operation
\r
314 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
315 @ApiOperation(value = "Retrieve one particular version of a policy type",
\r
316 notes = "Returns a particular version for the specified policy type",
\r
317 response = ToscaServiceTemplate.class,
\r
318 responseHeaders = {
\r
319 @ResponseHeader(name = "X-MinorVersion",
\r
320 description = "Used to request or communicate a MINOR version back from the client"
\r
321 + " to the server, and from the server back to the client",
\r
322 response = String.class),
\r
323 @ResponseHeader(name = "X-PatchVersion",
\r
324 description = "Used only to communicate a PATCH version in a response for"
\r
325 + " troubleshooting purposes only, and will not be provided by"
\r
326 + " the client on request",
\r
327 response = String.class),
\r
328 @ResponseHeader(name = "X-LatestVersion",
\r
329 description = "Used only to communicate an API's latest version",
\r
330 response = String.class),
\r
331 @ResponseHeader(name = "X-ONAP-RequestID",
\r
332 description = "Used to track REST transactions for logging purpose",
\r
333 response = UUID.class)
\r
335 authorizations = @Authorization(value = "basicAuth"),
\r
336 tags = { "PolicyType", },
\r
338 @Extension(name = "interface info", properties = {
\r
339 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
340 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
343 @ApiResponses(value = {
\r
344 @ApiResponse(code = 401, message = "Authentication Error"),
\r
345 @ApiResponse(code = 403, message = "Authorization Error"),
\r
346 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
347 @ApiResponse(code = 500, message = "Internal Server Error")
\r
349 public Response getSpecificVersionOfPolicyType(
\r
350 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
351 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
352 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
354 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
355 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);
\r
356 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
357 return makeOkResponse(requestId, serviceTemplate);
\r
358 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
359 LOGGER.error("GET /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
\r
360 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
361 return makeErrorResponse(requestId, pfme);
\r
366 * Retrieves latest version of a particular policy type.
\r
368 * @param policyTypeId the ID of specified policy type
\r
370 * @return the Response object containing the results of the API operation
\r
373 @Path("/policytypes/{policyTypeId}/versions/latest")
\r
374 @ApiOperation(value = "Retrieve latest version of a policy type",
\r
375 notes = "Returns latest version for the specified policy type",
\r
376 response = ToscaServiceTemplate.class,
\r
377 responseHeaders = {
\r
378 @ResponseHeader(name = "X-MinorVersion",
\r
379 description = "Used to request or communicate a MINOR version back from the client"
\r
380 + " to the server, and from the server back to the client",
\r
381 response = String.class),
\r
382 @ResponseHeader(name = "X-PatchVersion",
\r
383 description = "Used only to communicate a PATCH version in a response for"
\r
384 + " troubleshooting purposes only, and will not be provided by"
\r
385 + " the client on request",
\r
386 response = String.class),
\r
387 @ResponseHeader(name = "X-LatestVersion",
\r
388 description = "Used only to communicate an API's latest version",
\r
389 response = String.class),
\r
390 @ResponseHeader(name = "X-ONAP-RequestID",
\r
391 description = "Used to track REST transactions for logging purpose",
\r
392 response = UUID.class)
\r
394 authorizations = @Authorization(value = "basicAuth"),
\r
395 tags = { "PolicyType", },
\r
397 @Extension(name = "interface info", properties = {
\r
398 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
399 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
402 @ApiResponses(value = {
\r
403 @ApiResponse(code = 401, message = "Authentication Error"),
\r
404 @ApiResponse(code = 403, message = "Authorization Error"),
\r
405 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
406 @ApiResponse(code = 500, message = "Internal Server Error")
\r
408 public Response getLatestVersionOfPolicyType(
\r
409 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
410 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
412 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
413 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
\r
414 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
415 return makeOkResponse(requestId, serviceTemplate);
\r
416 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
417 LOGGER.error("GET /policytypes/{}/versions/latest", policyTypeId, pfme);
\r
418 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
419 return makeErrorResponse(requestId, pfme);
\r
424 * Creates a new policy type.
\r
426 * @param body the body of policy type following TOSCA definition
\r
428 * @return the Response object containing the results of the API operation
\r
431 @Path("/policytypes")
\r
432 @ApiOperation(value = "Create a new policy type",
\r
433 notes = "Client should provide TOSCA body of the new policy type",
\r
434 authorizations = @Authorization(value = "basicAuth"),
\r
435 tags = { "PolicyType", },
\r
436 response = ToscaServiceTemplate.class,
\r
437 responseHeaders = {
\r
438 @ResponseHeader(name = "X-MinorVersion",
\r
439 description = "Used to request or communicate a MINOR version back from the client"
\r
440 + " to the server, and from the server back to the client",
\r
441 response = String.class),
\r
442 @ResponseHeader(name = "X-PatchVersion",
\r
443 description = "Used only to communicate a PATCH version in a response for"
\r
444 + " troubleshooting purposes only, and will not be provided by"
\r
445 + " the client on request",
\r
446 response = String.class),
\r
447 @ResponseHeader(name = "X-LatestVersion",
\r
448 description = "Used only to communicate an API's latest version",
\r
449 response = String.class),
\r
450 @ResponseHeader(name = "X-ONAP-RequestID",
\r
451 description = "Used to track REST transactions for logging purpose",
\r
452 response = UUID.class)
\r
455 @Extension(name = "interface info", properties = {
\r
456 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
457 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
460 @ApiResponses(value = {
\r
461 @ApiResponse(code = 400, message = "Invalid Body"),
\r
462 @ApiResponse(code = 401, message = "Authentication Error"),
\r
463 @ApiResponse(code = 403, message = "Authorization Error"),
\r
464 @ApiResponse(code = 500, message = "Internal Server Error")
\r
466 public Response createPolicyType(
\r
467 @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
\r
468 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
470 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
471 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
\r
474 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
475 ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);
\r
476 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);
\r
477 return makeOkResponse(requestId, serviceTemplate);
\r
478 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
479 LOGGER.error("POST /policytypes", pfme);
\r
480 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.POST);
\r
481 return makeErrorResponse(requestId, pfme);
\r
486 * Deletes specified version of a particular policy type.
\r
488 * @param policyTypeId the ID of specified policy type
\r
489 * @param versionId the version of specified policy type
\r
491 * @return the Response object containing the results of the API operation
\r
494 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
495 @ApiOperation(value = "Delete one version of a policy type",
\r
496 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
497 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
498 + "The parameterizing TOSCA policies must be deleted first;",
\r
499 authorizations = @Authorization(value = "basicAuth"),
\r
500 tags = { "PolicyType", },
\r
501 response = ToscaServiceTemplate.class,
\r
502 responseHeaders = {
\r
503 @ResponseHeader(name = "X-MinorVersion",
\r
504 description = "Used to request or communicate a MINOR version back from the client"
\r
505 + " to the server, and from the server back to the client",
\r
506 response = String.class),
\r
507 @ResponseHeader(name = "X-PatchVersion",
\r
508 description = "Used only to communicate a PATCH version in a response for"
\r
509 + " troubleshooting purposes only, and will not be provided by"
\r
510 + " the client on request",
\r
511 response = String.class),
\r
512 @ResponseHeader(name = "X-LatestVersion",
\r
513 description = "Used only to communicate an API's latest version",
\r
514 response = String.class),
\r
515 @ResponseHeader(name = "X-ONAP-RequestID",
\r
516 description = "Used to track REST transactions for logging purpose",
\r
517 response = UUID.class)
\r
520 @Extension(name = "interface info", properties = {
\r
521 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
522 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
525 @ApiResponses(value = {
\r
526 @ApiResponse(code = 401, message = "Authentication Error"),
\r
527 @ApiResponse(code = 403, message = "Authorization Error"),
\r
528 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
529 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
530 @ApiResponse(code = 500, message = "Internal Server Error")
\r
532 public Response deleteSpecificVersionOfPolicyType(
\r
533 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
534 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
535 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
537 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
538 ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);
\r
539 return makeOkResponse(requestId, serviceTemplate);
\r
540 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
541 LOGGER.error("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
\r
542 return makeErrorResponse(requestId, pfme);
\r
547 * Retrieves all versions of a particular policy.
\r
549 * @param policyTypeId the ID of specified policy type
\r
550 * @param policyTypeVersion the version of specified policy type
\r
552 * @return the Response object containing the results of the API operation
\r
555 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
556 @ApiOperation(value = "Retrieve all versions of a policy created for a particular policy type version",
\r
557 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
\r
558 response = ToscaServiceTemplate.class,
\r
559 responseHeaders = {
\r
560 @ResponseHeader(name = "X-MinorVersion",
\r
561 description = "Used to request or communicate a MINOR version back from the client"
\r
562 + " to the server, and from the server back to the client",
\r
563 response = String.class),
\r
564 @ResponseHeader(name = "X-PatchVersion",
\r
565 description = "Used only to communicate a PATCH version in a response for"
\r
566 + " troubleshooting purposes only, and will not be provided by"
\r
567 + " the client on request",
\r
568 response = String.class),
\r
569 @ResponseHeader(name = "X-LatestVersion",
\r
570 description = "Used only to communicate an API's latest version",
\r
571 response = String.class),
\r
572 @ResponseHeader(name = "X-ONAP-RequestID",
\r
573 description = "Used to track REST transactions for logging purpose",
\r
574 response = UUID.class)
\r
576 authorizations = @Authorization(value = "basicAuth"),
\r
577 tags = { "Policy", },
\r
579 @Extension(name = "interface info", properties = {
\r
580 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
581 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
584 @ApiResponses(value = {
\r
585 @ApiResponse(code = 401, message = "Authentication Error"),
\r
586 @ApiResponse(code = 403, message = "Authorization Error"),
\r
587 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
588 @ApiResponse(code = 500, message = "Internal Server Error")
\r
590 public Response getAllPolicies(
\r
591 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
592 @PathParam("policyTypeVersion")
\r
593 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
594 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
596 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
597 ToscaServiceTemplate serviceTemplate =
\r
598 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null);
\r
599 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
600 return makeOkResponse(requestId, serviceTemplate);
\r
601 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
602 LOGGER.error("GET /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
\r
603 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
604 return makeErrorResponse(requestId, pfme);
\r
609 * Retrieves all versions of a particular policy.
\r
611 * @param policyTypeId the ID of specified policy type
\r
612 * @param policyTypeVersion the version of specified policy type
\r
613 * @param policyId the ID of specified policy
\r
615 * @return the Response object containing the results of the API operation
\r
618 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
619 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
\r
620 notes = "Returns a list of all version details of the specified policy",
\r
621 response = ToscaServiceTemplate.class,
\r
622 responseHeaders = {
\r
623 @ResponseHeader(name = "X-MinorVersion",
\r
624 description = "Used to request or communicate a MINOR version back from the client"
\r
625 + " to the server, and from the server back to the client",
\r
626 response = String.class),
\r
627 @ResponseHeader(name = "X-PatchVersion",
\r
628 description = "Used only to communicate a PATCH version in a response for"
\r
629 + " troubleshooting purposes only, and will not be provided by"
\r
630 + " the client on request",
\r
631 response = String.class),
\r
632 @ResponseHeader(name = "X-LatestVersion",
\r
633 description = "Used only to communicate an API's latest version",
\r
634 response = String.class),
\r
635 @ResponseHeader(name = "X-ONAP-RequestID",
\r
636 description = "Used to track REST transactions for logging purpose",
\r
637 response = UUID.class)
\r
639 authorizations = @Authorization(value = "basicAuth"),
\r
640 tags = { "Policy", },
\r
642 @Extension(name = "interface info", properties = {
\r
643 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
644 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
647 @ApiResponses(value = {
\r
648 @ApiResponse(code = 401, message = "Authentication Error"),
\r
649 @ApiResponse(code = 403, message = "Authorization Error"),
\r
650 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
651 @ApiResponse(code = 500, message = "Internal Server Error")
\r
653 public Response getAllVersionsOfPolicy(
\r
654 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
655 @PathParam("policyTypeVersion")
\r
656 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
657 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
658 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
660 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
661 ToscaServiceTemplate serviceTemplate = policyProvider
\r
662 .fetchPolicies(policyTypeId, policyTypeVersion, policyId, null);
\r
663 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
664 return makeOkResponse(requestId, serviceTemplate);
\r
665 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
666 LOGGER.error("/policytypes/{}/versions/{}/policies/{}", policyTypeId, policyTypeVersion, policyId,
\r
668 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
669 return makeErrorResponse(requestId, pfme);
\r
674 * Retrieves the specified version of a particular policy.
\r
676 * @param policyTypeId the ID of specified policy type
\r
677 * @param policyTypeVersion the version of specified policy type
\r
678 * @param policyId the ID of specified policy
\r
679 * @param policyVersion the version of specified policy
\r
681 * @return the Response object containing the results of the API operation
\r
684 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
685 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
\r
686 notes = "Returns a particular version of specified policy created for the specified policy type version",
\r
687 response = ToscaServiceTemplate.class,
\r
688 responseHeaders = {
\r
689 @ResponseHeader(name = "X-MinorVersion",
\r
690 description = "Used to request or communicate a MINOR version back from the client"
\r
691 + " to the server, and from the server back to the client",
\r
692 response = String.class),
\r
693 @ResponseHeader(name = "X-PatchVersion",
\r
694 description = "Used only to communicate a PATCH version in a response for"
\r
695 + " troubleshooting purposes only, and will not be provided by"
\r
696 + " the client on request",
\r
697 response = String.class),
\r
698 @ResponseHeader(name = "X-LatestVersion",
\r
699 description = "Used only to communicate an API's latest version",
\r
700 response = String.class),
\r
701 @ResponseHeader(name = "X-ONAP-RequestID",
\r
702 description = "Used to track REST transactions for logging purpose",
\r
703 response = UUID.class)
\r
705 authorizations = @Authorization(value = "basicAuth"),
\r
706 tags = { "Policy", },
\r
708 @Extension(name = "interface info", properties = {
\r
709 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
710 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
713 @ApiResponses(value = {
\r
714 @ApiResponse(code = 401, message = "Authentication Error"),
\r
715 @ApiResponse(code = 403, message = "Authorization Error"),
\r
716 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
717 @ApiResponse(code = 500, message = "Internal Server Error")
\r
719 public Response getSpecificVersionOfPolicy(
\r
720 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
721 @PathParam("policyTypeVersion")
\r
722 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
723 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
724 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
725 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
727 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
728 ToscaServiceTemplate serviceTemplate = policyProvider
\r
729 .fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
730 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
731 return makeOkResponse(requestId, serviceTemplate);
\r
732 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
733 LOGGER.error("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId,
\r
734 policyTypeVersion, policyId, policyVersion, pfme);
\r
735 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
736 return makeErrorResponse(requestId, pfme);
\r
741 * Retrieves the latest version of a particular policy.
\r
743 * @param policyTypeId the ID of specified policy type
\r
744 * @param policyTypeVersion the version of specified policy type
\r
745 * @param policyId the ID of specified policy
\r
747 * @return the Response object containing the results of the API operation
\r
750 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
\r
751 @ApiOperation(value = "Retrieve the latest version of a particular policy",
\r
752 notes = "Returns the latest version of specified policy",
\r
753 response = ToscaServiceTemplate.class,
\r
754 responseHeaders = {
\r
755 @ResponseHeader(name = "X-MinorVersion",
\r
756 description = "Used to request or communicate a MINOR version back from the client"
\r
757 + " to the server, and from the server back to the client",
\r
758 response = String.class),
\r
759 @ResponseHeader(name = "X-PatchVersion",
\r
760 description = "Used only to communicate a PATCH version in a response for"
\r
761 + " troubleshooting purposes only, and will not be provided by"
\r
762 + " the client on request",
\r
763 response = String.class),
\r
764 @ResponseHeader(name = "X-LatestVersion",
\r
765 description = "Used only to communicate an API's latest version",
\r
766 response = String.class),
\r
767 @ResponseHeader(name = "X-ONAP-RequestID",
\r
768 description = "Used to track REST transactions for logging purpose",
\r
769 response = UUID.class)
\r
771 authorizations = @Authorization(value = "basicAuth"),
\r
772 tags = { "Policy", },
\r
774 @Extension(name = "interface info", properties = {
\r
775 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
776 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
779 @ApiResponses(value = {
\r
780 @ApiResponse(code = 401, message = "Authentication Error"),
\r
781 @ApiResponse(code = 403, message = "Authorization Error"),
\r
782 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
783 @ApiResponse(code = 500, message = "Internal Server Error")
\r
785 public Response getLatestVersionOfPolicy(
\r
786 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
787 @PathParam("policyTypeVersion")
\r
788 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
789 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
790 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
792 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
793 ToscaServiceTemplate serviceTemplate =
\r
794 policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId);
\r
795 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
796 return makeOkResponse(requestId, serviceTemplate);
\r
797 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
798 LOGGER.error("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId,
\r
799 policyTypeVersion, policyId, pfme);
\r
800 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
801 return makeErrorResponse(requestId, pfme);
\r
806 * Retrieves deployed versions of a particular policy in PDP groups.
\r
808 * @param policyTypeId the ID of specified policy type
\r
809 * @param policyTypeVersion the version of specified policy type
\r
810 * @param policyId the ID of specified policy
\r
812 * @return the Response object containing the results of the API operation
\r
815 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/deployed")
\r
816 @ApiOperation(value = "Retrieve deployed versions of a particular policy in pdp groups",
\r
817 notes = "Returns deployed versions of specified policy in pdp groups",
\r
818 response = ToscaPolicy.class, responseContainer = "List",
\r
819 responseHeaders = {
\r
820 @ResponseHeader(name = "X-MinorVersion",
\r
821 description = "Used to request or communicate a MINOR version back from the client"
\r
822 + " to the server, and from the server back to the client",
\r
823 response = String.class),
\r
824 @ResponseHeader(name = "X-PatchVersion",
\r
825 description = "Used only to communicate a PATCH version in a response for"
\r
826 + " troubleshooting purposes only, and will not be provided by"
\r
827 + " the client on request",
\r
828 response = String.class),
\r
829 @ResponseHeader(name = "X-LatestVersion",
\r
830 description = "Used only to communicate an API's latest version",
\r
831 response = String.class),
\r
832 @ResponseHeader(name = "X-ONAP-RequestID",
\r
833 description = "Used to track REST transactions for logging purpose",
\r
834 response = UUID.class)
\r
836 authorizations = @Authorization(value = "basicAuth"),
\r
837 tags = { "Policy", },
\r
839 @Extension(name = "interface info", properties = {
\r
840 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
841 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
844 @ApiResponses(value = {
\r
845 @ApiResponse(code = 401, message = "Authentication Error"),
\r
846 @ApiResponse(code = 403, message = "Authorization Error"),
\r
847 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
848 @ApiResponse(code = 500, message = "Internal Server Error")
\r
850 public Response getDeployedVersionsOfPolicy(
\r
851 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
852 @PathParam("policyTypeVersion")
\r
853 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
854 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
855 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
857 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
858 Map<Pair<String, String>, List<ToscaPolicy>> deployedPolicies = policyProvider
\r
859 .fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);
\r
860 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
861 return makeOkResponse(requestId, deployedPolicies);
\r
862 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
863 LOGGER.error("GET /policytypes/{}/versions/{}/policies/{}/versions/deployed", policyTypeId,
\r
864 policyTypeVersion, policyId, pfme);
\r
865 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
866 return makeErrorResponse(requestId, pfme);
\r
871 * Creates a new policy for a particular policy type and version.
\r
873 * @param policyTypeId the ID of specified policy type
\r
874 * @param policyTypeVersion the version of specified policy type
\r
875 * @param body the body of policy following TOSCA definition
\r
877 * @return the Response object containing the results of the API operation
\r
880 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
881 @ApiOperation(value = "Create a new policy for a policy type version",
\r
882 notes = "Client should provide TOSCA body of the new policy",
\r
883 authorizations = @Authorization(value = "basicAuth"),
\r
884 tags = { "Policy", },
\r
885 response = ToscaServiceTemplate.class,
\r
886 responseHeaders = {
\r
887 @ResponseHeader(name = "X-MinorVersion",
\r
888 description = "Used to request or communicate a MINOR version back from the client"
\r
889 + " to the server, and from the server back to the client",
\r
890 response = String.class),
\r
891 @ResponseHeader(name = "X-PatchVersion",
\r
892 description = "Used only to communicate a PATCH version in a response for"
\r
893 + " troubleshooting purposes only, and will not be provided by"
\r
894 + " the client on request",
\r
895 response = String.class),
\r
896 @ResponseHeader(name = "X-LatestVersion",
\r
897 description = "Used only to communicate an API's latest version",
\r
898 response = String.class),
\r
899 @ResponseHeader(name = "X-ONAP-RequestID",
\r
900 description = "Used to track REST transactions for logging purpose",
\r
901 response = UUID.class)
\r
904 @Extension(name = "interface info", properties = {
\r
905 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
906 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
909 @ApiResponses(value = {
\r
910 @ApiResponse(code = 400, message = "Invalid Body"),
\r
911 @ApiResponse(code = 401, message = "Authentication Error"),
\r
912 @ApiResponse(code = 403, message = "Authorization Error"),
\r
913 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
914 @ApiResponse(code = 500, message = "Internal Server Error")
\r
916 public Response createPolicy(
\r
917 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
918 @PathParam("policyTypeVersion")
\r
919 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
920 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
921 @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
923 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
924 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
\r
925 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies",
\r
929 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
930 ToscaServiceTemplate serviceTemplate = policyProvider
\r
931 .createPolicy(policyTypeId, policyTypeVersion, body);
\r
932 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
\r
933 return makeOkResponse(requestId, serviceTemplate);
\r
934 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
935 LOGGER.error("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
\r
936 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
\r
937 return makeErrorResponse(requestId, pfme);
\r
942 * Deletes the specified version of a particular policy.
\r
944 * @param policyTypeId the ID of specified policy type
\r
945 * @param policyTypeVersion the version of specified policy type
\r
946 * @param policyId the ID of specified policy
\r
947 * @param policyVersion the version of specified policy
\r
949 * @return the Response object containing the results of the API operation
\r
952 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
953 @ApiOperation(value = "Delete a particular version of a policy",
\r
954 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
955 authorizations = @Authorization(value = "basicAuth"),
\r
956 tags = { "Policy", },
\r
957 response = ToscaServiceTemplate.class,
\r
958 responseHeaders = {
\r
959 @ResponseHeader(name = "X-MinorVersion",
\r
960 description = "Used to request or communicate a MINOR version back from the client"
\r
961 + " to the server, and from the server back to the client",
\r
962 response = String.class),
\r
963 @ResponseHeader(name = "X-PatchVersion",
\r
964 description = "Used only to communicate a PATCH version in a response for"
\r
965 + " troubleshooting purposes only, and will not be provided by"
\r
966 + " the client on request",
\r
967 response = String.class),
\r
968 @ResponseHeader(name = "X-LatestVersion",
\r
969 description = "Used only to communicate an API's latest version",
\r
970 response = String.class),
\r
971 @ResponseHeader(name = "X-ONAP-RequestID",
\r
972 description = "Used to track REST transactions for logging purpose",
\r
973 response = UUID.class)
\r
976 @Extension(name = "interface info", properties = {
\r
977 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
978 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
981 @ApiResponses(value = {
\r
982 @ApiResponse(code = 401, message = "Authentication Error"),
\r
983 @ApiResponse(code = 403, message = "Authorization Error"),
\r
984 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
985 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
986 @ApiResponse(code = 500, message = "Internal Server Error")
\r
988 public Response deleteSpecificVersionOfPolicy(
\r
989 @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
\r
990 @PathParam("policyTypeVersion")
\r
991 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
992 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
993 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
994 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
996 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
997 ToscaServiceTemplate serviceTemplate = policyProvider
\r
998 .deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
999 return makeOkResponse(requestId, serviceTemplate);
\r
1000 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
1001 LOGGER.error("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId,
\r
1002 policyTypeVersion, policyId, policyVersion, pfme);
\r
1003 return makeErrorResponse(requestId, pfme);
\r
1007 private enum Target {
\r
1008 POLICY, POLICY_TYPE, OTHER
\r
1011 private enum Result {
\r
1015 private enum HttpMethod {
\r
1019 private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {
\r
1021 ApiStatisticsManager.updateTotalApiCallCount();
\r
1025 updatePolicyStats(result, http);
\r
1028 updatePolicyTypeStats(result, http);
\r
1031 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1036 private void updatePolicyStats(Result result, HttpMethod http) {
\r
1037 if (result == Result.SUCCESS) {
\r
1038 if (http == HttpMethod.GET) {
\r
1039 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1040 ApiStatisticsManager.updateTotalPolicyGetCount();
\r
1041 ApiStatisticsManager.updatePolicyGetSuccessCount();
\r
1042 } else if (http == HttpMethod.POST) {
\r
1043 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1044 ApiStatisticsManager.updateTotalPolicyPostCount();
\r
1045 ApiStatisticsManager.updatePolicyPostSuccessCount();
\r
1048 if (http == HttpMethod.GET) {
\r
1049 ApiStatisticsManager.updateApiCallFailureCount();
\r
1050 ApiStatisticsManager.updateTotalPolicyGetCount();
\r
1051 ApiStatisticsManager.updatePolicyGetFailureCount();
\r
1053 ApiStatisticsManager.updateApiCallFailureCount();
\r
1054 ApiStatisticsManager.updateTotalPolicyPostCount();
\r
1055 ApiStatisticsManager.updatePolicyPostFailureCount();
\r
1060 private void updatePolicyTypeStats(Result result, HttpMethod http) {
\r
1061 if (result == Result.SUCCESS) {
\r
1062 if (http == HttpMethod.GET) {
\r
1063 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1064 ApiStatisticsManager.updateTotalPolicyTypeGetCount();
\r
1065 ApiStatisticsManager.updatePolicyTypeGetSuccessCount();
\r
1066 } else if (http == HttpMethod.POST) {
\r
1067 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1068 ApiStatisticsManager.updatePolicyTypePostSuccessCount();
\r
1069 ApiStatisticsManager.updatePolicyTypePostSuccessCount();
\r
1072 if (http == HttpMethod.GET) {
\r
1073 ApiStatisticsManager.updateApiCallFailureCount();
\r
1074 ApiStatisticsManager.updateTotalPolicyTypeGetCount();
\r
1075 ApiStatisticsManager.updatePolicyTypeGetFailureCount();
\r
1077 ApiStatisticsManager.updateApiCallFailureCount();
\r
1078 ApiStatisticsManager.updateTotalPolicyTypePostCount();
\r
1079 ApiStatisticsManager.updatePolicyTypePostFailureCount();
\r