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 * ================================================================================
\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.UUID;
\r
40 import javax.ws.rs.Consumes;
\r
41 import javax.ws.rs.DELETE;
\r
42 import javax.ws.rs.GET;
\r
43 import javax.ws.rs.HeaderParam;
\r
44 import javax.ws.rs.POST;
\r
45 import javax.ws.rs.Path;
\r
46 import javax.ws.rs.PathParam;
\r
47 import javax.ws.rs.Produces;
\r
48 import javax.ws.rs.core.Response;
\r
49 import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
\r
50 import org.onap.policy.api.main.rest.provider.PolicyProvider;
\r
51 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
\r
52 import org.onap.policy.api.main.rest.provider.StatisticsProvider;
\r
53 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
\r
54 import org.onap.policy.common.endpoints.report.HealthCheckReport;
\r
55 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
\r
56 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
\r
57 import org.onap.policy.models.base.PfModelException;
\r
58 import org.onap.policy.models.base.PfModelRuntimeException;
\r
59 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
60 import org.slf4j.Logger;
\r
61 import org.slf4j.LoggerFactory;
\r
64 * Class to provide REST API services.
\r
66 * @author Chenfei Gao (cgao@research.att.com)
\r
68 @Path("/policy/api/v1")
\r
69 @Api(value = "Policy Design API")
\r
70 @Produces({"application/json", "application/yaml"})
\r
71 @Consumes({"application/json", "application/yaml"})
\r
72 @SwaggerDefinition(info = @Info(
\r
73 description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
\r
74 + " policy types, policy type implementation and policies which can be recognized"
\r
75 + " and executable by incorporated policy engines. It is an"
\r
76 + " independent component running rest service that takes all policy design API calls"
\r
77 + " from clients and then assign them to different API working functions. Besides"
\r
78 + " that, API is also exposed for clients to retrieve healthcheck status of this API"
\r
79 + " rest service and the statistics report including the counters of API invocation.",
\r
80 version = "1.0.0", title = "Policy Design",
\r
81 extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
\r
82 @ExtensionProperty(name = "component", value = "Policy Framework")})}),
\r
83 schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
\r
84 securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
\r
85 public class ApiRestController extends CommonRestController {
\r
87 private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);
\r
90 * Retrieves the healthcheck status of the API component.
\r
92 * @return the Response object containing the results of the API operation
\r
95 @Path("/healthcheck")
\r
96 @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",
\r
97 response = HealthCheckReport.class,
\r
99 @ResponseHeader(name = "X-MinorVersion",
\r
100 description = "Used to request or communicate a MINOR version back from the client"
\r
101 + " to the server, and from the server back to the client",
\r
102 response = String.class),
\r
103 @ResponseHeader(name = "X-PatchVersion",
\r
104 description = "Used only to communicate a PATCH version in a response for"
\r
105 + " troubleshooting purposes only, and will not be provided by"
\r
106 + " the client on request",
\r
107 response = String.class),
\r
108 @ResponseHeader(name = "X-LatestVersion",
\r
109 description = "Used only to communicate an API's latest version", response = String.class),
\r
110 @ResponseHeader(name = "X-ONAP-RequestID",
\r
111 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
112 authorizations = @Authorization(value = "basicAuth"), tags = {"HealthCheck",},
\r
113 extensions = {@Extension(name = "interface info",
\r
114 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
115 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
116 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
117 @ApiResponse(code = 403, message = "Authorization Error"),
\r
118 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
119 public Response getHealthCheck(
\r
120 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
122 updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
\r
123 return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck());
\r
127 * Retrieves the statistics report of the API component.
\r
129 * @return the Response object containing the results of the API operation
\r
132 @Path("/statistics")
\r
133 @ApiOperation(value = "Retrieve current statistics",
\r
134 notes = "Returns current statistics including the counters of API invocation",
\r
135 response = StatisticsReport.class,
\r
136 responseHeaders = {
\r
137 @ResponseHeader(name = "X-MinorVersion",
\r
138 description = "Used to request or communicate a MINOR version back from the client"
\r
139 + " to the server, and from the server back to the client",
\r
140 response = String.class),
\r
141 @ResponseHeader(name = "X-PatchVersion",
\r
142 description = "Used only to communicate a PATCH version in a response for"
\r
143 + " troubleshooting purposes only, and will not be provided by"
\r
144 + " the client on request",
\r
145 response = String.class),
\r
146 @ResponseHeader(name = "X-LatestVersion",
\r
147 description = "Used only to communicate an API's latest version", response = String.class),
\r
148 @ResponseHeader(name = "X-ONAP-RequestID",
\r
149 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
150 authorizations = @Authorization(value = "basicAuth"), tags = {"Statistics",},
\r
151 extensions = {@Extension(name = "interface info",
\r
152 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
153 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
154 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
155 @ApiResponse(code = 403, message = "Authorization Error"),
\r
156 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
158 getStatistics(@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
160 updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
\r
162 return makeOkResponse(requestId, new StatisticsProvider().fetchCurrentStatistics());
\r
166 * Retrieves all available policy types.
\r
168 * @return the Response object containing the results of the API operation
\r
171 @Path("/policytypes")
\r
172 @ApiOperation(value = "Retrieve existing policy types",
\r
173 notes = "Returns a list of existing policy types stored in Policy Framework",
\r
174 response = ToscaServiceTemplate.class,
\r
175 responseHeaders = {
\r
176 @ResponseHeader(name = "X-MinorVersion",
\r
177 description = "Used to request or communicate a MINOR version back from the client"
\r
178 + " to the server, and from the server back to the client",
\r
179 response = String.class),
\r
180 @ResponseHeader(name = "X-PatchVersion",
\r
181 description = "Used only to communicate a PATCH version in a response for"
\r
182 + " troubleshooting purposes only, and will not be provided by"
\r
183 + " the client on request",
\r
184 response = String.class),
\r
185 @ResponseHeader(name = "X-LatestVersion",
\r
186 description = "Used only to communicate an API's latest version", response = String.class),
\r
187 @ResponseHeader(name = "X-ONAP-RequestID",
\r
188 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
189 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
190 extensions = {@Extension(name = "interface info",
\r
191 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
192 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
193 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
194 @ApiResponse(code = 403, message = "Authorization Error"),
\r
195 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
196 public Response getAllPolicyTypes(
\r
197 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
199 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
200 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);
\r
201 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
202 return makeOkResponse(requestId, serviceTemplate);
\r
203 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
204 LOGGER.debug("GET /policytypes", pfme);
\r
205 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
206 return makeErrorResponse(requestId, pfme);
\r
211 * Retrieves all versions of a particular policy type.
\r
213 * @param policyTypeId the ID of specified policy type
\r
215 * @return the Response object containing the results of the API operation
\r
218 @Path("/policytypes/{policyTypeId}")
\r
219 @ApiOperation(value = "Retrieve all available versions of a policy type",
\r
220 notes = "Returns a list of all available versions for the specified policy type",
\r
221 response = ToscaServiceTemplate.class,
\r
222 responseHeaders = {
\r
223 @ResponseHeader(name = "X-MinorVersion",
\r
224 description = "Used to request or communicate a MINOR version back from the client"
\r
225 + " to the server, and from the server back to the client",
\r
226 response = String.class),
\r
227 @ResponseHeader(name = "X-PatchVersion",
\r
228 description = "Used only to communicate a PATCH version in a response for"
\r
229 + " troubleshooting purposes only, and will not be provided by"
\r
230 + " the client on request",
\r
231 response = String.class),
\r
232 @ResponseHeader(name = "X-LatestVersion",
\r
233 description = "Used only to communicate an API's latest version", response = String.class),
\r
234 @ResponseHeader(name = "X-ONAP-RequestID",
\r
235 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
236 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
237 extensions = {@Extension(name = "interface info",
\r
238 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
239 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
240 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
241 @ApiResponse(code = 403, message = "Authorization Error"),
\r
242 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
243 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
244 public Response getAllVersionsOfPolicyType(
\r
245 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
246 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
248 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
249 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);
\r
250 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
251 return makeOkResponse(requestId, serviceTemplate);
\r
252 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
253 LOGGER.debug("GET /policytypes/{}", policyTypeId, pfme);
\r
254 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
255 return makeErrorResponse(requestId, pfme);
\r
260 * Retrieves specified version of a particular policy type.
\r
262 * @param policyTypeId the ID of specified policy type
\r
263 * @param versionId the version of specified policy type
\r
265 * @return the Response object containing the results of the API operation
\r
268 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
269 @ApiOperation(value = "Retrieve one particular version of a policy type",
\r
270 notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
\r
271 responseHeaders = {
\r
272 @ResponseHeader(name = "X-MinorVersion",
\r
273 description = "Used to request or communicate a MINOR version back from the client"
\r
274 + " to the server, and from the server back to the client",
\r
275 response = String.class),
\r
276 @ResponseHeader(name = "X-PatchVersion",
\r
277 description = "Used only to communicate a PATCH version in a response for"
\r
278 + " troubleshooting purposes only, and will not be provided by"
\r
279 + " the client on request",
\r
280 response = String.class),
\r
281 @ResponseHeader(name = "X-LatestVersion",
\r
282 description = "Used only to communicate an API's latest version", response = String.class),
\r
283 @ResponseHeader(name = "X-ONAP-RequestID",
\r
284 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
285 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
286 extensions = {@Extension(name = "interface info",
\r
287 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
288 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
289 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
290 @ApiResponse(code = 403, message = "Authorization Error"),
\r
291 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
292 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
293 public Response getSpecificVersionOfPolicyType(
\r
294 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
295 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
296 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
298 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
299 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);
\r
300 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
301 return makeOkResponse(requestId, serviceTemplate);
\r
302 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
303 LOGGER.debug("GET /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
\r
304 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
305 return makeErrorResponse(requestId, pfme);
\r
310 * Retrieves latest version of a particular policy type.
\r
312 * @param policyTypeId the ID of specified policy type
\r
314 * @return the Response object containing the results of the API operation
\r
317 @Path("/policytypes/{policyTypeId}/versions/latest")
\r
318 @ApiOperation(value = "Retrieve latest version of a policy type",
\r
319 notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
\r
320 responseHeaders = {
\r
321 @ResponseHeader(name = "X-MinorVersion",
\r
322 description = "Used to request or communicate a MINOR version back from the client"
\r
323 + " to the server, and from the server back to the client",
\r
324 response = String.class),
\r
325 @ResponseHeader(name = "X-PatchVersion",
\r
326 description = "Used only to communicate a PATCH version in a response for"
\r
327 + " troubleshooting purposes only, and will not be provided by"
\r
328 + " the client on request",
\r
329 response = String.class),
\r
330 @ResponseHeader(name = "X-LatestVersion",
\r
331 description = "Used only to communicate an API's latest version", response = String.class),
\r
332 @ResponseHeader(name = "X-ONAP-RequestID",
\r
333 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
334 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
335 extensions = {@Extension(name = "interface info",
\r
336 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
337 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
338 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
339 @ApiResponse(code = 403, message = "Authorization Error"),
\r
340 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
341 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
342 public Response getLatestVersionOfPolicyType(
\r
343 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
344 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
346 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
347 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
\r
348 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
349 return makeOkResponse(requestId, serviceTemplate);
\r
350 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
351 LOGGER.debug("GET /policytypes/{}/versions/latest", policyTypeId, pfme);
\r
352 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
353 return makeErrorResponse(requestId, pfme);
\r
358 * Creates a new policy type.
\r
360 * @param body the body of policy type following TOSCA definition
\r
362 * @return the Response object containing the results of the API operation
\r
365 @Path("/policytypes")
\r
366 @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",
\r
367 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
368 response = ToscaServiceTemplate.class,
\r
369 responseHeaders = {
\r
370 @ResponseHeader(name = "X-MinorVersion",
\r
371 description = "Used to request or communicate a MINOR version back from the client"
\r
372 + " to the server, and from the server back to the client",
\r
373 response = String.class),
\r
374 @ResponseHeader(name = "X-PatchVersion",
\r
375 description = "Used only to communicate a PATCH version in a response for"
\r
376 + " troubleshooting purposes only, and will not be provided by"
\r
377 + " the client on request",
\r
378 response = String.class),
\r
379 @ResponseHeader(name = "X-LatestVersion",
\r
380 description = "Used only to communicate an API's latest version",
\r
381 response = String.class),
\r
382 @ResponseHeader(name = "X-ONAP-RequestID",
\r
383 description = "Used to track REST transactions for logging purpose",
\r
384 response = UUID.class)
\r
387 @Extension(name = "interface info", properties = {
\r
388 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
389 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
392 @ApiResponses(value = {
\r
393 @ApiResponse(code = 400, message = "Invalid Body"),
\r
394 @ApiResponse(code = 401, message = "Authentication Error"),
\r
395 @ApiResponse(code = 403, message = "Authorization Error"),
\r
396 @ApiResponse(code = 406, message = "Not Acceptable Payload"),
\r
397 @ApiResponse(code = 500, message = "Internal Server Error")
\r
399 public Response createPolicyType(
\r
400 @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
\r
401 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
403 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
404 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
\r
407 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
408 ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);
\r
409 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);
\r
410 return makeOkResponse(requestId, serviceTemplate);
\r
411 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
412 LOGGER.debug("POST /policytypes", pfme);
\r
413 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.POST);
\r
414 return makeErrorResponse(requestId, pfme);
\r
419 * Deletes specified version of a particular policy type.
\r
421 * @param policyTypeId the ID of specified policy type
\r
422 * @param versionId the version of specified policy type
\r
424 * @return the Response object containing the results of the API operation
\r
427 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
428 @ApiOperation(value = "Delete one version of a policy type",
\r
429 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
430 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
431 + "The parameterizing TOSCA policies must be deleted first;",
\r
432 authorizations = @Authorization(value = "basicAuth"), tags = {"PolicyType",},
\r
433 response = ToscaServiceTemplate.class,
\r
434 responseHeaders = {
\r
435 @ResponseHeader(name = "X-MinorVersion",
\r
436 description = "Used to request or communicate a MINOR version back from the client"
\r
437 + " to the server, and from the server back to the client",
\r
438 response = String.class),
\r
439 @ResponseHeader(name = "X-PatchVersion",
\r
440 description = "Used only to communicate a PATCH version in a response for"
\r
441 + " troubleshooting purposes only, and will not be provided by"
\r
442 + " the client on request",
\r
443 response = String.class),
\r
444 @ResponseHeader(name = "X-LatestVersion",
\r
445 description = "Used only to communicate an API's latest version", response = String.class),
\r
446 @ResponseHeader(name = "X-ONAP-RequestID",
\r
447 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
448 extensions = {@Extension(name = "interface info",
\r
449 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
450 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
451 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
452 @ApiResponse(code = 403, message = "Authorization Error"),
\r
453 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
454 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
455 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
456 public Response deleteSpecificVersionOfPolicyType(
\r
457 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
458 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
459 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
461 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
462 ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);
\r
463 return makeOkResponse(requestId, serviceTemplate);
\r
464 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
465 LOGGER.debug("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
\r
466 return makeErrorResponse(requestId, pfme);
\r
471 * Retrieves all versions of a particular policy.
\r
473 * @param policyTypeId the ID of specified policy type
\r
474 * @param policyTypeVersion the version of specified policy type
\r
476 * @return the Response object containing the results of the API operation
\r
479 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
480 @ApiOperation(value = "Retrieve all versions of a policy created for a particular policy type version",
\r
481 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
\r
482 response = ToscaServiceTemplate.class,
\r
483 responseHeaders = {
\r
484 @ResponseHeader(name = "X-MinorVersion",
\r
485 description = "Used to request or communicate a MINOR version back from the client"
\r
486 + " to the server, and from the server back to the client",
\r
487 response = String.class),
\r
488 @ResponseHeader(name = "X-PatchVersion",
\r
489 description = "Used only to communicate a PATCH version in a response for"
\r
490 + " troubleshooting purposes only, and will not be provided by"
\r
491 + " the client on request",
\r
492 response = String.class),
\r
493 @ResponseHeader(name = "X-LatestVersion",
\r
494 description = "Used only to communicate an API's latest version", response = String.class),
\r
495 @ResponseHeader(name = "X-ONAP-RequestID",
\r
496 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
497 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
498 extensions = {@Extension(name = "interface info",
\r
499 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
500 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
501 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
502 @ApiResponse(code = 403, message = "Authorization Error"),
\r
503 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
504 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
505 public Response getAllPolicies(
\r
506 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
507 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
508 required = true) String policyTypeVersion,
\r
509 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
511 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
512 ToscaServiceTemplate serviceTemplate =
\r
513 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null);
\r
514 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
515 return makeOkResponse(requestId, serviceTemplate);
\r
516 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
517 LOGGER.debug("GET /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
\r
518 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
519 return makeErrorResponse(requestId, pfme);
\r
524 * Retrieves all versions of a particular policy.
\r
526 * @param policyTypeId the ID of specified policy type
\r
527 * @param policyTypeVersion the version of specified policy type
\r
528 * @param policyId the ID of specified policy
\r
530 * @return the Response object containing the results of the API operation
\r
533 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
534 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
\r
535 notes = "Returns a list of all version details of the specified policy",
\r
536 response = ToscaServiceTemplate.class,
\r
537 responseHeaders = {
\r
538 @ResponseHeader(name = "X-MinorVersion",
\r
539 description = "Used to request or communicate a MINOR version back from the client"
\r
540 + " to the server, and from the server back to the client",
\r
541 response = String.class),
\r
542 @ResponseHeader(name = "X-PatchVersion",
\r
543 description = "Used only to communicate a PATCH version in a response for"
\r
544 + " troubleshooting purposes only, and will not be provided by"
\r
545 + " the client on request",
\r
546 response = String.class),
\r
547 @ResponseHeader(name = "X-LatestVersion",
\r
548 description = "Used only to communicate an API's latest version", response = String.class),
\r
549 @ResponseHeader(name = "X-ONAP-RequestID",
\r
550 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
551 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
552 extensions = {@Extension(name = "interface info",
\r
553 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
554 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
555 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
556 @ApiResponse(code = 403, message = "Authorization Error"),
\r
557 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
558 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
559 public Response getAllVersionsOfPolicy(
\r
560 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
561 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
562 required = true) String policyTypeVersion,
\r
563 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
564 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
566 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
567 ToscaServiceTemplate serviceTemplate =
\r
568 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null);
\r
569 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
570 return makeOkResponse(requestId, serviceTemplate);
\r
571 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
572 LOGGER.debug("/policytypes/{}/versions/{}/policies/{}", policyTypeId, policyTypeVersion, policyId, pfme);
\r
573 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
574 return makeErrorResponse(requestId, pfme);
\r
579 * Retrieves the specified version of a particular policy.
\r
581 * @param policyTypeId the ID of specified policy type
\r
582 * @param policyTypeVersion the version of specified policy type
\r
583 * @param policyId the ID of specified policy
\r
584 * @param policyVersion the version of specified policy
\r
586 * @return the Response object containing the results of the API operation
\r
589 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
590 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
\r
591 notes = "Returns a particular version of specified policy created for the specified policy type version",
\r
592 response = ToscaServiceTemplate.class,
\r
593 responseHeaders = {
\r
594 @ResponseHeader(name = "X-MinorVersion",
\r
595 description = "Used to request or communicate a MINOR version back from the client"
\r
596 + " to the server, and from the server back to the client",
\r
597 response = String.class),
\r
598 @ResponseHeader(name = "X-PatchVersion",
\r
599 description = "Used only to communicate a PATCH version in a response for"
\r
600 + " troubleshooting purposes only, and will not be provided by"
\r
601 + " the client on request",
\r
602 response = String.class),
\r
603 @ResponseHeader(name = "X-LatestVersion",
\r
604 description = "Used only to communicate an API's latest version", response = String.class),
\r
605 @ResponseHeader(name = "X-ONAP-RequestID",
\r
606 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
607 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
608 extensions = {@Extension(name = "interface info",
\r
609 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
610 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
611 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
612 @ApiResponse(code = 403, message = "Authorization Error"),
\r
613 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
614 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
615 public Response getSpecificVersionOfPolicy(
\r
616 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
617 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
618 required = true) String policyTypeVersion,
\r
619 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
620 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
621 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
623 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
624 ToscaServiceTemplate serviceTemplate =
\r
625 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
626 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
627 return makeOkResponse(requestId, serviceTemplate);
\r
628 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
629 LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
\r
630 policyId, policyVersion, pfme);
\r
631 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
632 return makeErrorResponse(requestId, pfme);
\r
637 * Retrieves the latest version of a particular policy.
\r
639 * @param policyTypeId the ID of specified policy type
\r
640 * @param policyTypeVersion the version of specified policy type
\r
641 * @param policyId the ID of specified policy
\r
643 * @return the Response object containing the results of the API operation
\r
646 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
\r
647 @ApiOperation(value = "Retrieve the latest version of a particular policy",
\r
648 notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
\r
649 responseHeaders = {
\r
650 @ResponseHeader(name = "X-MinorVersion",
\r
651 description = "Used to request or communicate a MINOR version back from the client"
\r
652 + " to the server, and from the server back to the client",
\r
653 response = String.class),
\r
654 @ResponseHeader(name = "X-PatchVersion",
\r
655 description = "Used only to communicate a PATCH version in a response for"
\r
656 + " troubleshooting purposes only, and will not be provided by"
\r
657 + " the client on request",
\r
658 response = String.class),
\r
659 @ResponseHeader(name = "X-LatestVersion",
\r
660 description = "Used only to communicate an API's latest version", response = String.class),
\r
661 @ResponseHeader(name = "X-ONAP-RequestID",
\r
662 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
663 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
664 extensions = {@Extension(name = "interface info",
\r
665 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
666 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
667 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
668 @ApiResponse(code = 403, message = "Authorization Error"),
\r
669 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
670 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
671 public Response getLatestVersionOfPolicy(
\r
672 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
673 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
674 required = true) String policyTypeVersion,
\r
675 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
676 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
678 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
679 ToscaServiceTemplate serviceTemplate =
\r
680 policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId);
\r
681 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
682 return makeOkResponse(requestId, serviceTemplate);
\r
683 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
684 LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId, policyTypeVersion,
\r
686 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
687 return makeErrorResponse(requestId, pfme);
\r
692 * Creates a new policy for a particular policy type and version.
\r
694 * @param policyTypeId the ID of specified policy type
\r
695 * @param policyTypeVersion the version of specified policy type
\r
696 * @param body the body of policy following TOSCA definition
\r
698 * @return the Response object containing the results of the API operation
\r
701 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
702 @ApiOperation(value = "Create a new policy for a policy type version",
\r
703 notes = "Client should provide TOSCA body of the new policy",
\r
704 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
705 response = ToscaServiceTemplate.class,
\r
706 responseHeaders = {
\r
707 @ResponseHeader(name = "X-MinorVersion",
\r
708 description = "Used to request or communicate a MINOR version back from the client"
\r
709 + " to the server, and from the server back to the client",
\r
710 response = String.class),
\r
711 @ResponseHeader(name = "X-PatchVersion",
\r
712 description = "Used only to communicate a PATCH version in a response for"
\r
713 + " troubleshooting purposes only, and will not be provided by"
\r
714 + " the client on request",
\r
715 response = String.class),
\r
716 @ResponseHeader(name = "X-LatestVersion",
\r
717 description = "Used only to communicate an API's latest version",
\r
718 response = String.class),
\r
719 @ResponseHeader(name = "X-ONAP-RequestID",
\r
720 description = "Used to track REST transactions for logging purpose",
\r
721 response = UUID.class)
\r
724 @Extension(name = "interface info", properties = {
\r
725 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
726 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
729 @ApiResponses(value = {
\r
730 @ApiResponse(code = 400, message = "Invalid Body"),
\r
731 @ApiResponse(code = 401, message = "Authentication Error"),
\r
732 @ApiResponse(code = 403, message = "Authorization Error"),
\r
733 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
734 @ApiResponse(code = 406, message = "Not Acceptable Payload"),
\r
735 @ApiResponse(code = 500, message = "Internal Server Error")
\r
737 public Response createPolicy(
\r
738 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
739 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
740 required = true) String policyTypeVersion,
\r
741 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
742 @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
744 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
745 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
\r
746 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
\r
749 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
750 ToscaServiceTemplate serviceTemplate = policyProvider.createPolicy(policyTypeId, policyTypeVersion, body);
\r
751 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
\r
752 return makeOkResponse(requestId, serviceTemplate);
\r
753 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
754 LOGGER.debug("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
\r
755 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
\r
756 return makeErrorResponse(requestId, pfme);
\r
761 * Creates one or more new policies in one call.
\r
763 * @param body the body of policy following TOSCA definition
\r
765 * @return the Response object containing the results of the API operation
\r
769 @ApiOperation(value = "Create one or more new policies",
\r
770 notes = "Client should provide TOSCA body of the new polic(ies)",
\r
771 authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},
\r
772 response = ToscaServiceTemplate.class,
\r
773 responseHeaders = {
\r
774 @ResponseHeader(name = "X-MinorVersion",
\r
775 description = "Used to request or communicate a MINOR version back from the client"
\r
776 + " to the server, and from the server back to the client",
\r
777 response = String.class),
\r
778 @ResponseHeader(name = "X-PatchVersion",
\r
779 description = "Used only to communicate a PATCH version in a response for"
\r
780 + " troubleshooting purposes only, and will not be provided by"
\r
781 + " the client on request",
\r
782 response = String.class),
\r
783 @ResponseHeader(name = "X-LatestVersion",
\r
784 description = "Used only to communicate an API's latest version",
\r
785 response = String.class),
\r
786 @ResponseHeader(name = "X-ONAP-RequestID",
\r
787 description = "Used to track REST transactions for logging purpose",
\r
788 response = UUID.class)
\r
791 @Extension(name = "interface info", properties = {
\r
792 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
793 @ExtensionProperty(name = "last-mod-release", value = "El Alto")
\r
796 @ApiResponses(value = {
\r
797 @ApiResponse(code = 400, message = "Invalid Body"),
\r
798 @ApiResponse(code = 401, message = "Authentication Error"),
\r
799 @ApiResponse(code = 403, message = "Authorization Error"),
\r
800 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
801 @ApiResponse(code = 406, message = "Not Acceptable Payload"),
\r
802 @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",},
\r
838 response = ToscaServiceTemplate.class,
\r
839 responseHeaders = {
\r
840 @ResponseHeader(name = "X-MinorVersion",
\r
841 description = "Used to request or communicate a MINOR version back from the client"
\r
842 + " to the server, and from the server back to the client",
\r
843 response = String.class),
\r
844 @ResponseHeader(name = "X-PatchVersion",
\r
845 description = "Used only to communicate a PATCH version in a response for"
\r
846 + " troubleshooting purposes only, and will not be provided by"
\r
847 + " the client on request",
\r
848 response = String.class),
\r
849 @ResponseHeader(name = "X-LatestVersion",
\r
850 description = "Used only to communicate an API's latest version", response = String.class),
\r
851 @ResponseHeader(name = "X-ONAP-RequestID",
\r
852 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
\r
853 extensions = {@Extension(name = "interface info",
\r
854 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
855 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
\r
856 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
\r
857 @ApiResponse(code = 403, message = "Authorization Error"),
\r
858 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
859 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
860 @ApiResponse(code = 500, message = "Internal Server Error")})
\r
861 public Response deleteSpecificVersionOfPolicy(
\r
862 @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
\r
863 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
864 required = true) String policyTypeVersion,
\r
865 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
866 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
867 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
869 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
870 ToscaServiceTemplate serviceTemplate =
\r
871 policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
872 return makeOkResponse(requestId, serviceTemplate);
\r
873 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
874 LOGGER.debug("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
\r
875 policyId, policyVersion, pfme);
\r
876 return makeErrorResponse(requestId, pfme);
\r
880 private enum Target {
\r
886 private enum Result {
\r
891 private enum HttpMethod {
\r
896 private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {
\r
898 ApiStatisticsManager.updateTotalApiCallCount();
\r
902 updatePolicyStats(result, http);
\r
905 updatePolicyTypeStats(result, http);
\r
908 ApiStatisticsManager.updateApiCallSuccessCount();
\r
913 private void updatePolicyStats(Result result, HttpMethod http) {
\r
914 if (result == Result.SUCCESS) {
\r
915 if (http == HttpMethod.GET) {
\r
916 ApiStatisticsManager.updateApiCallSuccessCount();
\r
917 ApiStatisticsManager.updateTotalPolicyGetCount();
\r
918 ApiStatisticsManager.updatePolicyGetSuccessCount();
\r
919 } else if (http == HttpMethod.POST) {
\r
920 ApiStatisticsManager.updateApiCallSuccessCount();
\r
921 ApiStatisticsManager.updateTotalPolicyPostCount();
\r
922 ApiStatisticsManager.updatePolicyPostSuccessCount();
\r
925 if (http == HttpMethod.GET) {
\r
926 ApiStatisticsManager.updateApiCallFailureCount();
\r
927 ApiStatisticsManager.updateTotalPolicyGetCount();
\r
928 ApiStatisticsManager.updatePolicyGetFailureCount();
\r
930 ApiStatisticsManager.updateApiCallFailureCount();
\r
931 ApiStatisticsManager.updateTotalPolicyPostCount();
\r
932 ApiStatisticsManager.updatePolicyPostFailureCount();
\r
937 private void updatePolicyTypeStats(Result result, HttpMethod http) {
\r
938 if (result == Result.SUCCESS) {
\r
939 if (http == HttpMethod.GET) {
\r
940 ApiStatisticsManager.updateApiCallSuccessCount();
\r
941 ApiStatisticsManager.updateTotalPolicyTypeGetCount();
\r
942 ApiStatisticsManager.updatePolicyTypeGetSuccessCount();
\r
943 } else if (http == HttpMethod.POST) {
\r
944 ApiStatisticsManager.updateApiCallSuccessCount();
\r
945 ApiStatisticsManager.updatePolicyTypePostSuccessCount();
\r
946 ApiStatisticsManager.updatePolicyTypePostSuccessCount();
\r
949 if (http == HttpMethod.GET) {
\r
950 ApiStatisticsManager.updateApiCallFailureCount();
\r
951 ApiStatisticsManager.updateTotalPolicyTypeGetCount();
\r
952 ApiStatisticsManager.updatePolicyTypeGetFailureCount();
\r
954 ApiStatisticsManager.updateApiCallFailureCount();
\r
955 ApiStatisticsManager.updateTotalPolicyTypePostCount();
\r
956 ApiStatisticsManager.updatePolicyTypePostFailureCount();
\r