2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.api.main.rest;
26 import io.swagger.annotations.Api;
27 import io.swagger.annotations.ApiOperation;
28 import io.swagger.annotations.ApiParam;
29 import io.swagger.annotations.ApiResponse;
30 import io.swagger.annotations.ApiResponses;
31 import io.swagger.annotations.Authorization;
32 import io.swagger.annotations.BasicAuthDefinition;
33 import io.swagger.annotations.Extension;
34 import io.swagger.annotations.ExtensionProperty;
35 import io.swagger.annotations.Info;
36 import io.swagger.annotations.ResponseHeader;
37 import io.swagger.annotations.SecurityDefinition;
38 import io.swagger.annotations.SwaggerDefinition;
39 import java.util.UUID;
40 import javax.ws.rs.Consumes;
41 import javax.ws.rs.DELETE;
42 import javax.ws.rs.GET;
43 import javax.ws.rs.HeaderParam;
44 import javax.ws.rs.POST;
45 import javax.ws.rs.Path;
46 import javax.ws.rs.PathParam;
47 import javax.ws.rs.Produces;
48 import javax.ws.rs.QueryParam;
49 import javax.ws.rs.core.MediaType;
50 import javax.ws.rs.core.Response;
51 import javax.ws.rs.core.Response.ResponseBuilder;
52 import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
53 import org.onap.policy.api.main.rest.provider.PolicyProvider;
54 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
55 import org.onap.policy.api.main.rest.provider.StatisticsProvider;
56 import org.onap.policy.common.endpoints.report.HealthCheckReport;
57 import org.onap.policy.models.tosca.ToscaPolicy;
58 import org.onap.policy.models.tosca.ToscaPolicyList;
59 import org.onap.policy.models.tosca.ToscaPolicyType;
60 import org.onap.policy.models.tosca.ToscaPolicyTypeList;
63 * Class to provide REST API services.
65 @Path("/policy/api/v1")
66 @Api(value = "Policy Design API")
67 @Produces(MediaType.APPLICATION_JSON)
68 @Consumes(MediaType.APPLICATION_JSON)
69 @SwaggerDefinition(info = @Info(
70 description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
71 + " policy types, policy type implementation and policies which can be recognized"
72 + " and executable by incorporated policy engines. It is an"
73 + " independent component running rest service that takes all policy design API calls"
74 + " from clients and then assign them to different API working functions. Besides"
75 + " that, API is also exposed for clients to retrieve healthcheck status of this API"
76 + " rest service and the statistics report including the counters of API invocation.",
78 title = "Policy Design",
80 @Extension(properties = {
81 @ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
82 @ExtensionProperty(name = "component", value = "Policy Framework")
85 schemes = { SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS },
86 securityDefinition = @SecurityDefinition(basicAuthDefinitions = { @BasicAuthDefinition(key = "basicAuth") }))
87 public class ApiRestController {
90 * Retrieves the healthcheck status of the API component.
92 * @return the Response object containing the results of the API operation
96 @ApiOperation(value = "Perform a system healthcheck",
97 notes = "Returns healthy status of the Policy API component",
98 response = HealthCheckReport.class,
100 @ResponseHeader(name = "X-MinorVersion",
101 description = "Used to request or communicate a MINOR version back from the client"
102 + " to the server, and from the server back to the client",
103 response = String.class),
104 @ResponseHeader(name = "X-PatchVersion",
105 description = "Used only to communicate a PATCH version in a response for"
106 + " troubleshooting purposes only, and will not be provided by"
107 + " the client on request",
108 response = String.class),
109 @ResponseHeader(name = "X-LatestVersion",
110 description = "Used only to communicate an API's latest version",
111 response = String.class),
112 @ResponseHeader(name = "X-ONAP-RequestID",
113 description = "Used to track REST transactions for logging purpose",
114 response = UUID.class)
116 authorizations = @Authorization(value = "basicAuth"),
117 tags = { "HealthCheck", },
119 @Extension(name = "interface info", properties = {
120 @ExtensionProperty(name = "api-version", value = "1.0.0"),
121 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
124 @ApiResponses(value = {
125 @ApiResponse(code = 401, message = "Authentication Error"),
126 @ApiResponse(code = 403, message = "Authorization Error"),
127 @ApiResponse(code = 500, message = "Internal Server Error")
129 public Response getHealthCheck(
130 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
131 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
132 .entity(new HealthCheckProvider().performHealthCheck()).build();
136 * Retrieves the statistics report of the API component.
138 * @return the Response object containing the results of the API operation
142 @ApiOperation(value = "Retrieve current statistics",
143 notes = "Returns current statistics including the counters of API invocation",
144 response = StatisticsReport.class,
146 @ResponseHeader(name = "X-MinorVersion",
147 description = "Used to request or communicate a MINOR version back from the client"
148 + " to the server, and from the server back to the client",
149 response = String.class),
150 @ResponseHeader(name = "X-PatchVersion",
151 description = "Used only to communicate a PATCH version in a response for"
152 + " troubleshooting purposes only, and will not be provided by"
153 + " the client on request",
154 response = String.class),
155 @ResponseHeader(name = "X-LatestVersion",
156 description = "Used only to communicate an API's latest version",
157 response = String.class),
158 @ResponseHeader(name = "X-ONAP-RequestID",
159 description = "Used to track REST transactions for logging purpose",
160 response = UUID.class)
162 authorizations = @Authorization(value = "basicAuth"),
163 tags = { "Statistics", },
165 @Extension(name = "interface info", properties = {
166 @ExtensionProperty(name = "api-version", value = "1.0.0"),
167 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
170 @ApiResponses(value = {
171 @ApiResponse(code = 401, message = "Authentication Error"),
172 @ApiResponse(code = 403, message = "Authorization Error"),
173 @ApiResponse(code = 500, message = "Internal Server Error")
175 public Response getStatistics(
176 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
177 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
178 .entity(new StatisticsProvider().fetchCurrentStatistics()).build();
182 * Retrieves all available policy types.
184 * @return the Response object containing the results of the API operation
187 @Path("/policytypes")
188 @ApiOperation(value = "Retrieve existing policy types",
189 notes = "Returns a list of existing policy types stored in Policy Framework",
190 response = ToscaPolicyTypeList.class,
192 @ResponseHeader(name = "X-MinorVersion",
193 description = "Used to request or communicate a MINOR version back from the client"
194 + " to the server, and from the server back to the client",
195 response = String.class),
196 @ResponseHeader(name = "X-PatchVersion",
197 description = "Used only to communicate a PATCH version in a response for"
198 + " troubleshooting purposes only, and will not be provided by"
199 + " the client on request",
200 response = String.class),
201 @ResponseHeader(name = "X-LatestVersion",
202 description = "Used only to communicate an API's latest version",
203 response = String.class),
204 @ResponseHeader(name = "X-ONAP-RequestID",
205 description = "Used to track REST transactions for logging purpose",
206 response = UUID.class)
208 authorizations = @Authorization(value = "basicAuth"),
209 tags = { "PolicyType", },
211 @Extension(name = "interface info", properties = {
212 @ExtensionProperty(name = "api-version", value = "1.0.0"),
213 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
216 @ApiResponses(value = {
217 @ApiResponse(code = 401, message = "Authentication Error"),
218 @ApiResponse(code = 403, message = "Authorization Error"),
219 @ApiResponse(code = 500, message = "Internal Server Error")
221 public Response getAllPolicyTypes(
222 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
223 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
224 .entity(new PolicyTypeProvider().fetchPolicyTypes(null, null)).build();
228 * Retrieves all versions of a particular policy type.
230 * @param policyTypeId the ID of specified policy type
232 * @return the Response object containing the results of the API operation
235 @Path("/policytypes/{policyTypeId}")
236 @ApiOperation(value = "Retrieve all available versions of a policy type",
237 notes = "Returns a list of all available versions for the specified policy type",
238 response = ToscaPolicyTypeList.class,
240 @ResponseHeader(name = "X-MinorVersion",
241 description = "Used to request or communicate a MINOR version back from the client"
242 + " to the server, and from the server back to the client",
243 response = String.class),
244 @ResponseHeader(name = "X-PatchVersion",
245 description = "Used only to communicate a PATCH version in a response for"
246 + " troubleshooting purposes only, and will not be provided by"
247 + " the client on request",
248 response = String.class),
249 @ResponseHeader(name = "X-LatestVersion",
250 description = "Used only to communicate an API's latest version",
251 response = String.class),
252 @ResponseHeader(name = "X-ONAP-RequestID",
253 description = "Used to track REST transactions for logging purpose",
254 response = UUID.class)
256 authorizations = @Authorization(value = "basicAuth"),
257 tags = { "PolicyType", },
259 @Extension(name = "interface info", properties = {
260 @ExtensionProperty(name = "api-version", value = "1.0.0"),
261 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
264 @ApiResponses(value = {
265 @ApiResponse(code = 401, message = "Authentication Error"),
266 @ApiResponse(code = 403, message = "Authorization Error"),
267 @ApiResponse(code = 404, message = "Resource Not Found"),
268 @ApiResponse(code = 500, message = "Internal Server Error")
270 public Response getAllVersionsOfPolicyType(
271 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
272 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
273 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
274 .entity(new PolicyTypeProvider().fetchPolicyTypes(policyTypeId, null)).build();
278 * Retrieves specified version of a particular policy type.
280 * @param policyTypeId the ID of specified policy type
281 * @param versionId the version of specified policy type
283 * @return the Response object containing the results of the API operation
286 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
287 @ApiOperation(value = "Retrieve one particular version of a policy type",
288 notes = "Returns a particular version for the specified policy type",
289 response = ToscaPolicyTypeList.class,
291 @ResponseHeader(name = "X-MinorVersion",
292 description = "Used to request or communicate a MINOR version back from the client"
293 + " to the server, and from the server back to the client",
294 response = String.class),
295 @ResponseHeader(name = "X-PatchVersion",
296 description = "Used only to communicate a PATCH version in a response for"
297 + " troubleshooting purposes only, and will not be provided by"
298 + " the client on request",
299 response = String.class),
300 @ResponseHeader(name = "X-LatestVersion",
301 description = "Used only to communicate an API's latest version",
302 response = String.class),
303 @ResponseHeader(name = "X-ONAP-RequestID",
304 description = "Used to track REST transactions for logging purpose",
305 response = UUID.class)
307 authorizations = @Authorization(value = "basicAuth"),
308 tags = { "PolicyType", },
310 @Extension(name = "interface info", properties = {
311 @ExtensionProperty(name = "api-version", value = "1.0.0"),
312 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
315 @ApiResponses(value = {
316 @ApiResponse(code = 401, message = "Authentication Error"),
317 @ApiResponse(code = 403, message = "Authorization Error"),
318 @ApiResponse(code = 404, message = "Resource Not Found"),
319 @ApiResponse(code = 500, message = "Internal Server Error")
321 public Response getSpecificVersionOfPolicyType(
322 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
323 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
324 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
325 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
326 .entity(new PolicyTypeProvider().fetchPolicyTypes(policyTypeId, versionId)).build();
330 * Creates a new policy type.
332 * @param body the body of policy type following TOSCA definition
334 * @return the Response object containing the results of the API operation
337 @Path("/policytypes")
338 @ApiOperation(value = "Create a new policy type",
339 notes = "Client should provide TOSCA body of the new policy type",
340 authorizations = @Authorization(value = "basicAuth"),
341 tags = { "PolicyType", },
343 @Extension(name = "interface info", properties = {
344 @ExtensionProperty(name = "api-version", value = "1.0.0"),
345 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
348 @ApiResponses(value = {
349 @ApiResponse(code = 201, message = "Resource successfully created",
351 @ResponseHeader(name = "X-MinorVersion",
352 description = "Used to request or communicate a MINOR version back from the client"
353 + " to the server, and from the server back to the client",
354 response = String.class),
355 @ResponseHeader(name = "X-PatchVersion",
356 description = "Used only to communicate a PATCH version in a response for"
357 + " troubleshooting purposes only, and will not be provided by"
358 + " the client on request",
359 response = String.class),
360 @ResponseHeader(name = "X-LatestVersion",
361 description = "Used only to communicate an API's latest version",
362 response = String.class),
363 @ResponseHeader(name = "X-ONAP-RequestID",
364 description = "Used to track REST transactions for logging purpose",
365 response = UUID.class)
367 @ApiResponse(code = 400, message = "Invalid Body"),
368 @ApiResponse(code = 401, message = "Authentication Error"),
369 @ApiResponse(code = 403, message = "Authorization Error"),
370 @ApiResponse(code = 500, message = "Internal Server Error")
372 public Response createPolicyType(
373 @ApiParam(value = "Entity body of policy type", required = true) ToscaPolicyType body,
374 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
375 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
376 .entity(new PolicyTypeProvider().createPolicyType(body)).build();
380 * Deletes all versions of a particular policy type.
382 * @param policyTypeId the ID of specified policy type
384 * @return the Response object containing the results of the API operation
387 @Path("/policytypes/{policyTypeId}")
388 @ApiOperation(value = "Delete all versions of a policy type",
389 notes = "Rule 1: pre-defined policy types cannot be deleted;"
390 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
391 + "The parameterizing TOSCA policies must be deleted first;",
392 authorizations = @Authorization(value = "basicAuth"),
393 tags = { "PolicyType", },
395 @Extension(name = "interface info", properties = {
396 @ExtensionProperty(name = "api-version", value = "1.0.0"),
397 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
400 @ApiResponses(value = {
401 @ApiResponse(code = 204, message = "Resources successfully deleted, no content returned",
403 @ResponseHeader(name = "X-MinorVersion",
404 description = "Used to request or communicate a MINOR version back from the client"
405 + " to the server, and from the server back to the client",
406 response = String.class),
407 @ResponseHeader(name = "X-PatchVersion",
408 description = "Used only to communicate a PATCH version in a response for"
409 + " troubleshooting purposes only, and will not be provided by"
410 + " the client on request",
411 response = String.class),
412 @ResponseHeader(name = "X-LatestVersion",
413 description = "Used only to communicate an API's latest version",
414 response = String.class),
415 @ResponseHeader(name = "X-ONAP-RequestID",
416 description = "Used to track REST transactions for logging purpose",
417 response = UUID.class)
419 @ApiResponse(code = 401, message = "Authentication Error"),
420 @ApiResponse(code = 403, message = "Authorization Error"),
421 @ApiResponse(code = 404, message = "Resource Not Found"),
422 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
423 @ApiResponse(code = 500, message = "Internal Server Error")
425 public Response deleteAllVersionsOfPolicyType(
426 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
427 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
428 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
429 .entity(new PolicyTypeProvider().deletePolicyTypes(policyTypeId, null)).build();
433 * Deletes specified version of a particular policy type.
435 * @param policyTypeId the ID of specified policy type
436 * @param versionId the version of specified policy type
438 * @return the Response object containing the results of the API operation
441 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
442 @ApiOperation(value = "Delete one version of a policy type",
443 notes = "Rule 1: pre-defined policy types cannot be deleted;"
444 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
445 + "The parameterizing TOSCA policies must be deleted first;",
446 authorizations = @Authorization(value = "basicAuth"),
447 tags = { "PolicyType", },
449 @Extension(name = "interface info", properties = {
450 @ExtensionProperty(name = "api-version", value = "1.0.0"),
451 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
454 @ApiResponses(value = {
455 @ApiResponse(code = 204, message = "Resource successfully deleted, no content returned",
457 @ResponseHeader(name = "X-MinorVersion",
458 description = "Used to request or communicate a MINOR version back from the client"
459 + " to the server, and from the server back to the client",
460 response = String.class),
461 @ResponseHeader(name = "X-PatchVersion",
462 description = "Used only to communicate a PATCH version in a response for"
463 + " troubleshooting purposes only, and will not be provided by"
464 + " the client on request",
465 response = String.class),
466 @ResponseHeader(name = "X-LatestVersion",
467 description = "Used only to communicate an API's latest version",
468 response = String.class),
469 @ResponseHeader(name = "X-ONAP-RequestID",
470 description = "Used to track REST transactions for logging purpose",
471 response = UUID.class)
473 @ApiResponse(code = 401, message = "Authentication Error"),
474 @ApiResponse(code = 403, message = "Authorization Error"),
475 @ApiResponse(code = 404, message = "Resource Not Found"),
476 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
477 @ApiResponse(code = 500, message = "Internal Server Error")
479 public Response deleteSpecificVersionOfPolicyType(
480 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
481 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
482 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
483 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
484 .entity(new PolicyTypeProvider().deletePolicyTypes(policyTypeId, versionId)).build();
488 * Retrieves all versions of a particular policy.
490 * @param policyTypeId the ID of specified policy type
491 * @param policyTypeVersion the version of specified policy type
493 * @return the Response object containing the results of the API operation
496 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
497 @ApiOperation(value = "Retrieve all versions of a policy created for a particular policy type version",
498 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
499 response = ToscaPolicyList.class,
501 @ResponseHeader(name = "X-MinorVersion",
502 description = "Used to request or communicate a MINOR version back from the client"
503 + " to the server, and from the server back to the client",
504 response = String.class),
505 @ResponseHeader(name = "X-PatchVersion",
506 description = "Used only to communicate a PATCH version in a response for"
507 + " troubleshooting purposes only, and will not be provided by"
508 + " the client on request",
509 response = String.class),
510 @ResponseHeader(name = "X-LatestVersion",
511 description = "Used only to communicate an API's latest version",
512 response = String.class),
513 @ResponseHeader(name = "X-ONAP-RequestID",
514 description = "Used to track REST transactions for logging purpose",
515 response = UUID.class)
517 authorizations = @Authorization(value = "basicAuth"),
518 tags = { "Policy", },
520 @Extension(name = "interface info", properties = {
521 @ExtensionProperty(name = "api-version", value = "1.0.0"),
522 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
525 @ApiResponses(value = {
526 @ApiResponse(code = 401, message = "Authentication Error"),
527 @ApiResponse(code = 403, message = "Authorization Error"),
528 @ApiResponse(code = 404, message = "Resource Not Found"),
529 @ApiResponse(code = 500, message = "Internal Server Error")
531 public Response getAllPolicies(
532 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
533 @PathParam("policyTypeVersion")
534 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
535 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
536 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
537 .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, null, null)).build();
541 * Retrieves all versions of a particular policy.
543 * @param policyTypeId the ID of specified policy type
544 * @param policyTypeVersion the version of specified policy type
545 * @param policyId the ID of specified policy
547 * @return the Response object containing the results of the API operation
550 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
551 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
552 notes = "Returns a list of all version details of the specified policy",
553 response = ToscaPolicyList.class,
555 @ResponseHeader(name = "X-MinorVersion",
556 description = "Used to request or communicate a MINOR version back from the client"
557 + " to the server, and from the server back to the client",
558 response = String.class),
559 @ResponseHeader(name = "X-PatchVersion",
560 description = "Used only to communicate a PATCH version in a response for"
561 + " troubleshooting purposes only, and will not be provided by"
562 + " the client on request",
563 response = String.class),
564 @ResponseHeader(name = "X-LatestVersion",
565 description = "Used only to communicate an API's latest version",
566 response = String.class),
567 @ResponseHeader(name = "X-ONAP-RequestID",
568 description = "Used to track REST transactions for logging purpose",
569 response = UUID.class)
571 authorizations = @Authorization(value = "basicAuth"),
572 tags = { "Policy", },
574 @Extension(name = "interface info", properties = {
575 @ExtensionProperty(name = "api-version", value = "1.0.0"),
576 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
579 @ApiResponses(value = {
580 @ApiResponse(code = 401, message = "Authentication Error"),
581 @ApiResponse(code = 403, message = "Authorization Error"),
582 @ApiResponse(code = 404, message = "Resource Not Found"),
583 @ApiResponse(code = 500, message = "Internal Server Error")
585 public Response getAllVersionsOfPolicy(
586 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
587 @PathParam("policyTypeVersion")
588 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
589 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
590 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
591 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
592 .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, policyId, null)).build();
596 * Retrieves the specified version of a particular policy.
598 * @param policyTypeId the ID of specified policy type
599 * @param policyTypeVersion the version of specified policy type
600 * @param policyId the ID of specified policy
601 * @param policyVersion the version of specified policy
603 * @return the Response object containing the results of the API operation
606 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
607 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
608 notes = "Returns a particular version of specified policy created for the specified policy type version",
609 response = ToscaPolicyList.class,
611 @ResponseHeader(name = "X-MinorVersion",
612 description = "Used to request or communicate a MINOR version back from the client"
613 + " to the server, and from the server back to the client",
614 response = String.class),
615 @ResponseHeader(name = "X-PatchVersion",
616 description = "Used only to communicate a PATCH version in a response for"
617 + " troubleshooting purposes only, and will not be provided by"
618 + " the client on request",
619 response = String.class),
620 @ResponseHeader(name = "X-LatestVersion",
621 description = "Used only to communicate an API's latest version",
622 response = String.class),
623 @ResponseHeader(name = "X-ONAP-RequestID",
624 description = "Used to track REST transactions for logging purpose",
625 response = UUID.class)
627 authorizations = @Authorization(value = "basicAuth"),
628 tags = { "Policy", },
630 @Extension(name = "interface info", properties = {
631 @ExtensionProperty(name = "api-version", value = "1.0.0"),
632 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
635 @ApiResponses(value = {
636 @ApiResponse(code = 401, message = "Authentication Error"),
637 @ApiResponse(code = 403, message = "Authorization Error"),
638 @ApiResponse(code = 404, message = "Resource Not Found"),
639 @ApiResponse(code = 500, message = "Internal Server Error")
641 public Response getSpecificVersionOfPolicy(
642 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
643 @PathParam("policyTypeVersion")
644 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
645 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
646 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
647 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
648 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
649 .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion,
650 policyId, policyVersion)).build();
654 * Retrieves either latest or deployed version of a particular policy depending on query parameter.
656 * @param policyTypeId the ID of specified policy type
657 * @param policyTypeVersion the version of specified policy type
658 * @param policyId the ID of specified policy
660 * @return the Response object containing the results of the API operation
663 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions")
664 @ApiOperation(value = "Retrieve either latest or deployed version of a particular policy depending on query param",
665 notes = "Returns either latest or deployed version of specified policy depending on query param",
666 response = ToscaPolicyList.class,
668 @ResponseHeader(name = "X-MinorVersion",
669 description = "Used to request or communicate a MINOR version back from the client"
670 + " to the server, and from the server back to the client",
671 response = String.class),
672 @ResponseHeader(name = "X-PatchVersion",
673 description = "Used only to communicate a PATCH version in a response for"
674 + " troubleshooting purposes only, and will not be provided by"
675 + " the client on request",
676 response = String.class),
677 @ResponseHeader(name = "X-LatestVersion",
678 description = "Used only to communicate an API's latest version",
679 response = String.class),
680 @ResponseHeader(name = "X-ONAP-RequestID",
681 description = "Used to track REST transactions for logging purpose",
682 response = UUID.class)
684 authorizations = @Authorization(value = "basicAuth"),
685 tags = { "Policy", },
687 @Extension(name = "interface info", properties = {
688 @ExtensionProperty(name = "api-version", value = "1.0.0"),
689 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
692 @ApiResponses(value = {
693 @ApiResponse(code = 401, message = "Authentication Error"),
694 @ApiResponse(code = 403, message = "Authorization Error"),
695 @ApiResponse(code = 404, message = "Resource Not Found"),
696 @ApiResponse(code = 500, message = "Internal Server Error")
698 public Response getEitherLatestOrDeployedVersionOfPolicy(
699 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
700 @PathParam("policyTypeVersion")
701 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
702 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
704 @ApiParam(value = "Version that can only be 'latest' or 'deployed'", required = true) String type,
705 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
706 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
707 .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, policyId, type)).build();
711 * Creates a new policy for a particular policy type and version.
713 * @param policyTypeId the ID of specified policy type
714 * @param policyTypeVersion the version of specified policy type
715 * @param body the body of policy following TOSCA definition
717 * @return the Response object containing the results of the API operation
720 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
721 @ApiOperation(value = "Create a new policy for a policy type version",
722 notes = "Client should provide TOSCA body of the new policy",
723 authorizations = @Authorization(value = "basicAuth"),
724 tags = { "Policy", },
726 @Extension(name = "interface info", properties = {
727 @ExtensionProperty(name = "api-version", value = "1.0.0"),
728 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
731 @ApiResponses(value = {
732 @ApiResponse(code = 201, message = "Resource successfully created",
734 @ResponseHeader(name = "X-MinorVersion",
735 description = "Used to request or communicate a MINOR version back from the client"
736 + " to the server, and from the server back to the client",
737 response = String.class),
738 @ResponseHeader(name = "X-PatchVersion",
739 description = "Used only to communicate a PATCH version in a response for"
740 + " troubleshooting purposes only, and will not be provided by"
741 + " the client on request",
742 response = String.class),
743 @ResponseHeader(name = "X-LatestVersion",
744 description = "Used only to communicate an API's latest version",
745 response = String.class),
746 @ResponseHeader(name = "X-ONAP-RequestID",
747 description = "Used to track REST transactions for logging purpose",
748 response = UUID.class)
750 @ApiResponse(code = 400, message = "Invalid Body"),
751 @ApiResponse(code = 401, message = "Authentication Error"),
752 @ApiResponse(code = 403, message = "Authorization Error"),
753 @ApiResponse(code = 404, message = "Resource Not Found"),
754 @ApiResponse(code = 500, message = "Internal Server Error")
756 public Response createPolicy(
757 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
758 @PathParam("policyTypeVersion")
759 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
760 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
761 @ApiParam(value = "Entity body of policy", required = true) ToscaPolicy body) {
762 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
763 .entity(new PolicyProvider().createPolicy(policyTypeId, policyTypeVersion, body)).build();
767 * Deletes all versions of a particular policy.
769 * @param policyTypeId the ID of specified policy type
770 * @param policyTypeVersion the version of specified policy type
771 * @param policyId the ID of specified policy
773 * @return the Response object containing the results of the API operation
776 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
777 @ApiOperation(value = "Delete all versions of a policy",
778 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
779 authorizations = @Authorization(value = "basicAuth"),
780 tags = { "Policy", },
782 @Extension(name = "interface info", properties = {
783 @ExtensionProperty(name = "api-version", value = "1.0.0"),
784 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
787 @ApiResponses(value = {
788 @ApiResponse(code = 204, message = "Resources successfully deleted, no content returned",
790 @ResponseHeader(name = "X-MinorVersion",
791 description = "Used to request or communicate a MINOR version back from the client"
792 + " to the server, and from the server back to the client",
793 response = String.class),
794 @ResponseHeader(name = "X-PatchVersion",
795 description = "Used only to communicate a PATCH version in a response for"
796 + " troubleshooting purposes only, and will not be provided by"
797 + " the client on request",
798 response = String.class),
799 @ResponseHeader(name = "X-LatestVersion",
800 description = "Used only to communicate an API's latest version",
801 response = String.class),
802 @ResponseHeader(name = "X-ONAP-RequestID",
803 description = "Used to track REST transactions for logging purpose",
804 response = UUID.class)
806 @ApiResponse(code = 401, message = "Authentication Error"),
807 @ApiResponse(code = 403, message = "Authorization Error"),
808 @ApiResponse(code = 404, message = "Resource Not Found"),
809 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
810 @ApiResponse(code = 500, message = "Internal Server Error")
812 public Response deleteAllVersionsOfPolicy(
813 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
814 @PathParam("policyTypeVersion")
815 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
816 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
817 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
818 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
819 .entity(new PolicyProvider().deletePolicies(policyTypeId, policyTypeVersion, policyId, null)).build();
823 * Deletes the specified version of a particular policy.
825 * @param policyTypeId the ID of specified policy type
826 * @param policyTypeVersion the version of specified policy type
827 * @param policyId the ID of specified policy
828 * @param policyVersion the version of specified policy
830 * @return the Response object containing the results of the API operation
833 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
834 @ApiOperation(value = "Delete a particular version of a policy",
835 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
836 authorizations = @Authorization(value = "basicAuth"),
837 tags = { "Policy", },
839 @Extension(name = "interface info", properties = {
840 @ExtensionProperty(name = "api-version", value = "1.0.0"),
841 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
844 @ApiResponses(value = {
845 @ApiResponse(code = 204, message = "Resource successfully deleted, no content returned",
847 @ResponseHeader(name = "X-MinorVersion",
848 description = "Used to request or communicate a MINOR version back from the client"
849 + " to the server, and from the server back to the client",
850 response = String.class),
851 @ResponseHeader(name = "X-PatchVersion",
852 description = "Used only to communicate a PATCH version in a response for"
853 + " troubleshooting purposes only, and will not be provided by"
854 + " the client on request",
855 response = String.class),
856 @ResponseHeader(name = "X-LatestVersion",
857 description = "Used only to communicate an API's latest version",
858 response = String.class),
859 @ResponseHeader(name = "X-ONAP-RequestID",
860 description = "Used to track REST transactions for logging purpose",
861 response = UUID.class)
863 @ApiResponse(code = 401, message = "Authentication Error"),
864 @ApiResponse(code = 403, message = "Authorization Error"),
865 @ApiResponse(code = 404, message = "Resource Not Found"),
866 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
867 @ApiResponse(code = 500, message = "Internal Server Error")
869 public Response deleteSpecificVersionOfPolicy(
870 @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
871 @PathParam("policyTypeVersion")
872 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
873 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
874 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
875 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
876 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
877 .entity(new PolicyProvider().deletePolicies(policyTypeId, policyTypeVersion,
878 policyId, policyVersion)).build();
881 private ResponseBuilder addVersionControlHeaders(ResponseBuilder rb) {
882 return rb.header("X-MinorVersion", "0").header("X-PatchVersion", "0").header("X-LatestVersion", "1.0.0");
885 private ResponseBuilder addLoggingHeaders(ResponseBuilder rb, UUID requestId) {
886 if (requestId == null) {
887 // Generate a random uuid if client does not embed requestId in rest request
888 return rb.header("X-ONAP-RequestID", UUID.randomUUID());
890 return rb.header("X-ONAP-RequestID", requestId);