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.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.QueryParam;
\r
49 import javax.ws.rs.core.Response;
\r
50 import javax.ws.rs.core.Response.ResponseBuilder;
\r
51 import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
\r
52 import org.onap.policy.api.main.rest.provider.PolicyProvider;
\r
53 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
\r
54 import org.onap.policy.api.main.rest.provider.StatisticsProvider;
\r
55 import org.onap.policy.common.endpoints.report.HealthCheckReport;
\r
56 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
\r
59 * Class to provide REST API services.
\r
61 * @author Chenfei Gao (cgao@research.att.com)
\r
63 @Path("/policy/api/v1")
\r
64 @Api(value = "Policy Design API")
\r
65 @Produces({"application/json", "application/yaml"})
\r
66 @Consumes({"application/json", "application/yaml"})
\r
67 @SwaggerDefinition(info = @Info(
\r
68 description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
\r
69 + " policy types, policy type implementation and policies which can be recognized"
\r
70 + " and executable by incorporated policy engines. It is an"
\r
71 + " independent component running rest service that takes all policy design API calls"
\r
72 + " from clients and then assign them to different API working functions. Besides"
\r
73 + " that, API is also exposed for clients to retrieve healthcheck status of this API"
\r
74 + " rest service and the statistics report including the counters of API invocation.",
\r
76 title = "Policy Design",
\r
78 @Extension(properties = {
\r
79 @ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
\r
80 @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 {
\r
88 * Retrieves the healthcheck status of the API component.
\r
90 * @return the Response object containing the results of the API operation
\r
93 @Path("/healthcheck")
\r
94 @ApiOperation(value = "Perform a system healthcheck",
\r
95 notes = "Returns healthy status of the Policy API component",
\r
96 response = HealthCheckReport.class,
\r
98 @ResponseHeader(name = "X-MinorVersion",
\r
99 description = "Used to request or communicate a MINOR version back from the client"
\r
100 + " to the server, and from the server back to the client",
\r
101 response = String.class),
\r
102 @ResponseHeader(name = "X-PatchVersion",
\r
103 description = "Used only to communicate a PATCH version in a response for"
\r
104 + " troubleshooting purposes only, and will not be provided by"
\r
105 + " the client on request",
\r
106 response = String.class),
\r
107 @ResponseHeader(name = "X-LatestVersion",
\r
108 description = "Used only to communicate an API's latest version",
\r
109 response = String.class),
\r
110 @ResponseHeader(name = "X-ONAP-RequestID",
\r
111 description = "Used to track REST transactions for logging purpose",
\r
112 response = UUID.class)
\r
114 authorizations = @Authorization(value = "basicAuth"),
\r
115 tags = { "HealthCheck", },
\r
117 @Extension(name = "interface info", properties = {
\r
118 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
119 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
122 @ApiResponses(value = {
\r
123 @ApiResponse(code = 401, message = "Authentication Error"),
\r
124 @ApiResponse(code = 403, message = "Authorization Error"),
\r
125 @ApiResponse(code = 500, message = "Internal Server Error")
\r
127 public Response getHealthCheck(
\r
128 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
129 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
130 .entity(new HealthCheckProvider().performHealthCheck()).build();
\r
134 * Retrieves the statistics report of the API component.
\r
136 * @return the Response object containing the results of the API operation
\r
139 @Path("/statistics")
\r
140 @ApiOperation(value = "Retrieve current statistics",
\r
141 notes = "Returns current statistics including the counters of API invocation",
\r
142 response = StatisticsReport.class,
\r
143 responseHeaders = {
\r
144 @ResponseHeader(name = "X-MinorVersion",
\r
145 description = "Used to request or communicate a MINOR version back from the client"
\r
146 + " to the server, and from the server back to the client",
\r
147 response = String.class),
\r
148 @ResponseHeader(name = "X-PatchVersion",
\r
149 description = "Used only to communicate a PATCH version in a response for"
\r
150 + " troubleshooting purposes only, and will not be provided by"
\r
151 + " the client on request",
\r
152 response = String.class),
\r
153 @ResponseHeader(name = "X-LatestVersion",
\r
154 description = "Used only to communicate an API's latest version",
\r
155 response = String.class),
\r
156 @ResponseHeader(name = "X-ONAP-RequestID",
\r
157 description = "Used to track REST transactions for logging purpose",
\r
158 response = UUID.class)
\r
160 authorizations = @Authorization(value = "basicAuth"),
\r
161 tags = { "Statistics", },
\r
163 @Extension(name = "interface info", properties = {
\r
164 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
165 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
168 @ApiResponses(value = {
\r
169 @ApiResponse(code = 401, message = "Authentication Error"),
\r
170 @ApiResponse(code = 403, message = "Authorization Error"),
\r
171 @ApiResponse(code = 500, message = "Internal Server Error")
\r
173 public Response getStatistics(
\r
174 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
175 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
176 .entity(new StatisticsProvider().fetchCurrentStatistics()).build();
\r
180 * Retrieves all available policy types.
\r
182 * @return the Response object containing the results of the API operation
\r
185 @Path("/policytypes")
\r
186 @ApiOperation(value = "Retrieve existing policy types",
\r
187 notes = "Returns a list of existing policy types stored in Policy Framework",
\r
188 response = ToscaServiceTemplate.class,
\r
189 responseHeaders = {
\r
190 @ResponseHeader(name = "X-MinorVersion",
\r
191 description = "Used to request or communicate a MINOR version back from the client"
\r
192 + " to the server, and from the server back to the client",
\r
193 response = String.class),
\r
194 @ResponseHeader(name = "X-PatchVersion",
\r
195 description = "Used only to communicate a PATCH version in a response for"
\r
196 + " troubleshooting purposes only, and will not be provided by"
\r
197 + " the client on request",
\r
198 response = String.class),
\r
199 @ResponseHeader(name = "X-LatestVersion",
\r
200 description = "Used only to communicate an API's latest version",
\r
201 response = String.class),
\r
202 @ResponseHeader(name = "X-ONAP-RequestID",
\r
203 description = "Used to track REST transactions for logging purpose",
\r
204 response = UUID.class)
\r
206 authorizations = @Authorization(value = "basicAuth"),
\r
207 tags = { "PolicyType", },
\r
209 @Extension(name = "interface info", properties = {
\r
210 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
211 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
214 @ApiResponses(value = {
\r
215 @ApiResponse(code = 401, message = "Authentication Error"),
\r
216 @ApiResponse(code = 403, message = "Authorization Error"),
\r
217 @ApiResponse(code = 500, message = "Internal Server Error")
\r
219 public Response getAllPolicyTypes(
\r
220 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
221 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
222 .entity(new PolicyTypeProvider().fetchPolicyTypes(null, null)).build();
\r
226 * Retrieves all versions of a particular policy type.
\r
228 * @param policyTypeId the ID of specified policy type
\r
230 * @return the Response object containing the results of the API operation
\r
233 @Path("/policytypes/{policyTypeId}")
\r
234 @ApiOperation(value = "Retrieve all available versions of a policy type",
\r
235 notes = "Returns a list of all available versions for the specified policy type",
\r
236 response = ToscaServiceTemplate.class,
\r
237 responseHeaders = {
\r
238 @ResponseHeader(name = "X-MinorVersion",
\r
239 description = "Used to request or communicate a MINOR version back from the client"
\r
240 + " to the server, and from the server back to the client",
\r
241 response = String.class),
\r
242 @ResponseHeader(name = "X-PatchVersion",
\r
243 description = "Used only to communicate a PATCH version in a response for"
\r
244 + " troubleshooting purposes only, and will not be provided by"
\r
245 + " the client on request",
\r
246 response = String.class),
\r
247 @ResponseHeader(name = "X-LatestVersion",
\r
248 description = "Used only to communicate an API's latest version",
\r
249 response = String.class),
\r
250 @ResponseHeader(name = "X-ONAP-RequestID",
\r
251 description = "Used to track REST transactions for logging purpose",
\r
252 response = UUID.class)
\r
254 authorizations = @Authorization(value = "basicAuth"),
\r
255 tags = { "PolicyType", },
\r
257 @Extension(name = "interface info", properties = {
\r
258 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
259 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
262 @ApiResponses(value = {
\r
263 @ApiResponse(code = 401, message = "Authentication Error"),
\r
264 @ApiResponse(code = 403, message = "Authorization Error"),
\r
265 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
266 @ApiResponse(code = 500, message = "Internal Server Error")
\r
268 public Response getAllVersionsOfPolicyType(
\r
269 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
270 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
271 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
272 .entity(new PolicyTypeProvider().fetchPolicyTypes(policyTypeId, null)).build();
\r
276 * Retrieves specified version of a particular policy type.
\r
278 * @param policyTypeId the ID of specified policy type
\r
279 * @param versionId the version of specified policy type
\r
281 * @return the Response object containing the results of the API operation
\r
284 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
285 @ApiOperation(value = "Retrieve one particular version of a policy type",
\r
286 notes = "Returns a particular version for the specified policy type",
\r
287 response = ToscaServiceTemplate.class,
\r
288 responseHeaders = {
\r
289 @ResponseHeader(name = "X-MinorVersion",
\r
290 description = "Used to request or communicate a MINOR version back from the client"
\r
291 + " to the server, and from the server back to the client",
\r
292 response = String.class),
\r
293 @ResponseHeader(name = "X-PatchVersion",
\r
294 description = "Used only to communicate a PATCH version in a response for"
\r
295 + " troubleshooting purposes only, and will not be provided by"
\r
296 + " the client on request",
\r
297 response = String.class),
\r
298 @ResponseHeader(name = "X-LatestVersion",
\r
299 description = "Used only to communicate an API's latest version",
\r
300 response = String.class),
\r
301 @ResponseHeader(name = "X-ONAP-RequestID",
\r
302 description = "Used to track REST transactions for logging purpose",
\r
303 response = UUID.class)
\r
305 authorizations = @Authorization(value = "basicAuth"),
\r
306 tags = { "PolicyType", },
\r
308 @Extension(name = "interface info", properties = {
\r
309 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
310 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
313 @ApiResponses(value = {
\r
314 @ApiResponse(code = 401, message = "Authentication Error"),
\r
315 @ApiResponse(code = 403, message = "Authorization Error"),
\r
316 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
317 @ApiResponse(code = 500, message = "Internal Server Error")
\r
319 public Response getSpecificVersionOfPolicyType(
\r
320 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
321 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
322 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
323 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
324 .entity(new PolicyTypeProvider().fetchPolicyTypes(policyTypeId, versionId)).build();
\r
328 * Creates a new policy type.
\r
330 * @param body the body of policy type following TOSCA definition
\r
332 * @return the Response object containing the results of the API operation
\r
335 @Path("/policytypes")
\r
336 @ApiOperation(value = "Create a new policy type",
\r
337 notes = "Client should provide TOSCA body of the new policy type",
\r
338 authorizations = @Authorization(value = "basicAuth"),
\r
339 tags = { "PolicyType", },
\r
340 response = ToscaServiceTemplate.class,
\r
341 responseHeaders = {
\r
342 @ResponseHeader(name = "X-MinorVersion",
\r
343 description = "Used to request or communicate a MINOR version back from the client"
\r
344 + " to the server, and from the server back to the client",
\r
345 response = String.class),
\r
346 @ResponseHeader(name = "X-PatchVersion",
\r
347 description = "Used only to communicate a PATCH version in a response for"
\r
348 + " troubleshooting purposes only, and will not be provided by"
\r
349 + " the client on request",
\r
350 response = String.class),
\r
351 @ResponseHeader(name = "X-LatestVersion",
\r
352 description = "Used only to communicate an API's latest version",
\r
353 response = String.class),
\r
354 @ResponseHeader(name = "X-ONAP-RequestID",
\r
355 description = "Used to track REST transactions for logging purpose",
\r
356 response = UUID.class)
\r
359 @Extension(name = "interface info", properties = {
\r
360 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
361 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
364 @ApiResponses(value = {
\r
365 @ApiResponse(code = 400, message = "Invalid Body"),
\r
366 @ApiResponse(code = 401, message = "Authentication Error"),
\r
367 @ApiResponse(code = 403, message = "Authorization Error"),
\r
368 @ApiResponse(code = 500, message = "Internal Server Error")
\r
370 public Response createPolicyType(
\r
371 @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
\r
372 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
373 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
374 .entity(new PolicyTypeProvider().createPolicyType(body)).build();
\r
378 * Deletes all versions of a particular policy type.
\r
380 * @param policyTypeId the ID of specified policy type
\r
382 * @return the Response object containing the results of the API operation
\r
385 @Path("/policytypes/{policyTypeId}")
\r
386 @ApiOperation(value = "Delete all versions of a policy type",
\r
387 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
388 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
389 + "The parameterizing TOSCA policies must be deleted first;",
\r
390 authorizations = @Authorization(value = "basicAuth"),
\r
391 tags = { "PolicyType", },
\r
393 @Extension(name = "interface info", properties = {
\r
394 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
395 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
398 @ApiResponses(value = {
\r
399 @ApiResponse(code = 204, message = "Resources successfully deleted, no content returned",
\r
400 responseHeaders = {
\r
401 @ResponseHeader(name = "X-MinorVersion",
\r
402 description = "Used to request or communicate a MINOR version back from the client"
\r
403 + " to the server, and from the server back to the client",
\r
404 response = String.class),
\r
405 @ResponseHeader(name = "X-PatchVersion",
\r
406 description = "Used only to communicate a PATCH version in a response for"
\r
407 + " troubleshooting purposes only, and will not be provided by"
\r
408 + " the client on request",
\r
409 response = String.class),
\r
410 @ResponseHeader(name = "X-LatestVersion",
\r
411 description = "Used only to communicate an API's latest version",
\r
412 response = String.class),
\r
413 @ResponseHeader(name = "X-ONAP-RequestID",
\r
414 description = "Used to track REST transactions for logging purpose",
\r
415 response = UUID.class)
\r
417 @ApiResponse(code = 401, message = "Authentication Error"),
\r
418 @ApiResponse(code = 403, message = "Authorization Error"),
\r
419 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
420 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
421 @ApiResponse(code = 500, message = "Internal Server Error")
\r
423 public Response deleteAllVersionsOfPolicyType(
\r
424 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
425 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
426 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
427 .entity(new PolicyTypeProvider().deletePolicyTypes(policyTypeId, null)).build();
\r
431 * Deletes specified version of a particular policy type.
\r
433 * @param policyTypeId the ID of specified policy type
\r
434 * @param versionId the version of specified policy type
\r
436 * @return the Response object containing the results of the API operation
\r
439 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
440 @ApiOperation(value = "Delete one version of a policy type",
\r
441 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
442 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
443 + "The parameterizing TOSCA policies must be deleted first;",
\r
444 authorizations = @Authorization(value = "basicAuth"),
\r
445 tags = { "PolicyType", },
\r
447 @Extension(name = "interface info", properties = {
\r
448 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
449 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
452 @ApiResponses(value = {
\r
453 @ApiResponse(code = 204, message = "Resource successfully deleted, no content returned",
\r
454 responseHeaders = {
\r
455 @ResponseHeader(name = "X-MinorVersion",
\r
456 description = "Used to request or communicate a MINOR version back from the client"
\r
457 + " to the server, and from the server back to the client",
\r
458 response = String.class),
\r
459 @ResponseHeader(name = "X-PatchVersion",
\r
460 description = "Used only to communicate a PATCH version in a response for"
\r
461 + " troubleshooting purposes only, and will not be provided by"
\r
462 + " the client on request",
\r
463 response = String.class),
\r
464 @ResponseHeader(name = "X-LatestVersion",
\r
465 description = "Used only to communicate an API's latest version",
\r
466 response = String.class),
\r
467 @ResponseHeader(name = "X-ONAP-RequestID",
\r
468 description = "Used to track REST transactions for logging purpose",
\r
469 response = UUID.class)
\r
471 @ApiResponse(code = 401, message = "Authentication Error"),
\r
472 @ApiResponse(code = 403, message = "Authorization Error"),
\r
473 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
474 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
475 @ApiResponse(code = 500, message = "Internal Server Error")
\r
477 public Response deleteSpecificVersionOfPolicyType(
\r
478 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
479 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
480 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
481 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
482 .entity(new PolicyTypeProvider().deletePolicyTypes(policyTypeId, versionId)).build();
\r
486 * Retrieves all versions of a particular policy.
\r
488 * @param policyTypeId the ID of specified policy type
\r
489 * @param policyTypeVersion 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/{policyTypeVersion}/policies")
\r
495 @ApiOperation(value = "Retrieve all versions of a policy created for a particular policy type version",
\r
496 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
\r
497 response = ToscaServiceTemplate.class,
\r
498 responseHeaders = {
\r
499 @ResponseHeader(name = "X-MinorVersion",
\r
500 description = "Used to request or communicate a MINOR version back from the client"
\r
501 + " to the server, and from the server back to the client",
\r
502 response = String.class),
\r
503 @ResponseHeader(name = "X-PatchVersion",
\r
504 description = "Used only to communicate a PATCH version in a response for"
\r
505 + " troubleshooting purposes only, and will not be provided by"
\r
506 + " the client on request",
\r
507 response = String.class),
\r
508 @ResponseHeader(name = "X-LatestVersion",
\r
509 description = "Used only to communicate an API's latest version",
\r
510 response = String.class),
\r
511 @ResponseHeader(name = "X-ONAP-RequestID",
\r
512 description = "Used to track REST transactions for logging purpose",
\r
513 response = UUID.class)
\r
515 authorizations = @Authorization(value = "basicAuth"),
\r
516 tags = { "Policy", },
\r
518 @Extension(name = "interface info", properties = {
\r
519 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
520 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
523 @ApiResponses(value = {
\r
524 @ApiResponse(code = 401, message = "Authentication Error"),
\r
525 @ApiResponse(code = 403, message = "Authorization Error"),
\r
526 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
527 @ApiResponse(code = 500, message = "Internal Server Error")
\r
529 public Response getAllPolicies(
\r
530 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
531 @PathParam("policyTypeVersion")
\r
532 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
533 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
534 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
535 .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, null, null)).build();
\r
539 * Retrieves all versions of a particular policy.
\r
541 * @param policyTypeId the ID of specified policy type
\r
542 * @param policyTypeVersion the version of specified policy type
\r
543 * @param policyId the ID of specified policy
\r
545 * @return the Response object containing the results of the API operation
\r
548 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
549 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
\r
550 notes = "Returns a list of all version details of the specified policy",
\r
551 response = ToscaServiceTemplate.class,
\r
552 responseHeaders = {
\r
553 @ResponseHeader(name = "X-MinorVersion",
\r
554 description = "Used to request or communicate a MINOR version back from the client"
\r
555 + " to the server, and from the server back to the client",
\r
556 response = String.class),
\r
557 @ResponseHeader(name = "X-PatchVersion",
\r
558 description = "Used only to communicate a PATCH version in a response for"
\r
559 + " troubleshooting purposes only, and will not be provided by"
\r
560 + " the client on request",
\r
561 response = String.class),
\r
562 @ResponseHeader(name = "X-LatestVersion",
\r
563 description = "Used only to communicate an API's latest version",
\r
564 response = String.class),
\r
565 @ResponseHeader(name = "X-ONAP-RequestID",
\r
566 description = "Used to track REST transactions for logging purpose",
\r
567 response = UUID.class)
\r
569 authorizations = @Authorization(value = "basicAuth"),
\r
570 tags = { "Policy", },
\r
572 @Extension(name = "interface info", properties = {
\r
573 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
574 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
577 @ApiResponses(value = {
\r
578 @ApiResponse(code = 401, message = "Authentication Error"),
\r
579 @ApiResponse(code = 403, message = "Authorization Error"),
\r
580 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
581 @ApiResponse(code = 500, message = "Internal Server Error")
\r
583 public Response getAllVersionsOfPolicy(
\r
584 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
585 @PathParam("policyTypeVersion")
\r
586 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
587 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
588 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
589 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
590 .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, policyId, null)).build();
\r
594 * Retrieves the specified version of a particular policy.
\r
596 * @param policyTypeId the ID of specified policy type
\r
597 * @param policyTypeVersion the version of specified policy type
\r
598 * @param policyId the ID of specified policy
\r
599 * @param policyVersion the version of specified policy
\r
601 * @return the Response object containing the results of the API operation
\r
604 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
605 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
\r
606 notes = "Returns a particular version of specified policy created for the specified policy type version",
\r
607 response = ToscaServiceTemplate.class,
\r
608 responseHeaders = {
\r
609 @ResponseHeader(name = "X-MinorVersion",
\r
610 description = "Used to request or communicate a MINOR version back from the client"
\r
611 + " to the server, and from the server back to the client",
\r
612 response = String.class),
\r
613 @ResponseHeader(name = "X-PatchVersion",
\r
614 description = "Used only to communicate a PATCH version in a response for"
\r
615 + " troubleshooting purposes only, and will not be provided by"
\r
616 + " the client on request",
\r
617 response = String.class),
\r
618 @ResponseHeader(name = "X-LatestVersion",
\r
619 description = "Used only to communicate an API's latest version",
\r
620 response = String.class),
\r
621 @ResponseHeader(name = "X-ONAP-RequestID",
\r
622 description = "Used to track REST transactions for logging purpose",
\r
623 response = UUID.class)
\r
625 authorizations = @Authorization(value = "basicAuth"),
\r
626 tags = { "Policy", },
\r
628 @Extension(name = "interface info", properties = {
\r
629 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
630 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
633 @ApiResponses(value = {
\r
634 @ApiResponse(code = 401, message = "Authentication Error"),
\r
635 @ApiResponse(code = 403, message = "Authorization Error"),
\r
636 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
637 @ApiResponse(code = 500, message = "Internal Server Error")
\r
639 public Response getSpecificVersionOfPolicy(
\r
640 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
641 @PathParam("policyTypeVersion")
\r
642 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
643 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
644 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
645 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
646 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
647 .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion,
\r
648 policyId, policyVersion)).build();
\r
652 * Retrieves either latest or deployed version of a particular policy depending on query parameter.
\r
654 * @param policyTypeId the ID of specified policy type
\r
655 * @param policyTypeVersion the version of specified policy type
\r
656 * @param policyId the ID of specified policy
\r
658 * @return the Response object containing the results of the API operation
\r
661 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions")
\r
662 @ApiOperation(value = "Retrieve either latest or deployed version of a particular policy depending on query param",
\r
663 notes = "Returns either latest or deployed version of specified policy depending on query param",
\r
664 response = ToscaServiceTemplate.class,
\r
665 responseHeaders = {
\r
666 @ResponseHeader(name = "X-MinorVersion",
\r
667 description = "Used to request or communicate a MINOR version back from the client"
\r
668 + " to the server, and from the server back to the client",
\r
669 response = String.class),
\r
670 @ResponseHeader(name = "X-PatchVersion",
\r
671 description = "Used only to communicate a PATCH version in a response for"
\r
672 + " troubleshooting purposes only, and will not be provided by"
\r
673 + " the client on request",
\r
674 response = String.class),
\r
675 @ResponseHeader(name = "X-LatestVersion",
\r
676 description = "Used only to communicate an API's latest version",
\r
677 response = String.class),
\r
678 @ResponseHeader(name = "X-ONAP-RequestID",
\r
679 description = "Used to track REST transactions for logging purpose",
\r
680 response = UUID.class)
\r
682 authorizations = @Authorization(value = "basicAuth"),
\r
683 tags = { "Policy", },
\r
685 @Extension(name = "interface info", properties = {
\r
686 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
687 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
690 @ApiResponses(value = {
\r
691 @ApiResponse(code = 401, message = "Authentication Error"),
\r
692 @ApiResponse(code = 403, message = "Authorization Error"),
\r
693 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
694 @ApiResponse(code = 500, message = "Internal Server Error")
\r
696 public Response getEitherLatestOrDeployedVersionOfPolicy(
\r
697 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
698 @PathParam("policyTypeVersion")
\r
699 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
700 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
701 @QueryParam("type")
\r
702 @ApiParam(value = "Version that can only be 'latest' or 'deployed'", required = true) String type,
\r
703 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
704 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
705 .entity(new PolicyProvider().fetchPolicies(policyTypeId, policyTypeVersion, policyId, type)).build();
\r
709 * Creates a new policy for a particular policy type and version.
\r
711 * @param policyTypeId the ID of specified policy type
\r
712 * @param policyTypeVersion the version of specified policy type
\r
713 * @param body the body of policy following TOSCA definition
\r
715 * @return the Response object containing the results of the API operation
\r
718 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
719 @ApiOperation(value = "Create a new policy for a policy type version",
\r
720 notes = "Client should provide TOSCA body of the new policy",
\r
721 authorizations = @Authorization(value = "basicAuth"),
\r
722 tags = { "Policy", },
\r
723 response = ToscaServiceTemplate.class,
\r
724 responseHeaders = {
\r
725 @ResponseHeader(name = "X-MinorVersion",
\r
726 description = "Used to request or communicate a MINOR version back from the client"
\r
727 + " to the server, and from the server back to the client",
\r
728 response = String.class),
\r
729 @ResponseHeader(name = "X-PatchVersion",
\r
730 description = "Used only to communicate a PATCH version in a response for"
\r
731 + " troubleshooting purposes only, and will not be provided by"
\r
732 + " the client on request",
\r
733 response = String.class),
\r
734 @ResponseHeader(name = "X-LatestVersion",
\r
735 description = "Used only to communicate an API's latest version",
\r
736 response = String.class),
\r
737 @ResponseHeader(name = "X-ONAP-RequestID",
\r
738 description = "Used to track REST transactions for logging purpose",
\r
739 response = UUID.class)
\r
742 @Extension(name = "interface info", properties = {
\r
743 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
744 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
747 @ApiResponses(value = {
\r
748 @ApiResponse(code = 400, message = "Invalid Body"),
\r
749 @ApiResponse(code = 401, message = "Authentication Error"),
\r
750 @ApiResponse(code = 403, message = "Authorization Error"),
\r
751 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
752 @ApiResponse(code = 500, message = "Internal Server Error")
\r
754 public Response createPolicy(
\r
755 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
756 @PathParam("policyTypeVersion")
\r
757 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
758 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
\r
759 @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
760 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
761 .entity(new PolicyProvider().createPolicy(policyTypeId, policyTypeVersion, body)).build();
\r
765 * Deletes all versions of a particular policy.
\r
767 * @param policyTypeId the ID of specified policy type
\r
768 * @param policyTypeVersion the version of specified policy type
\r
769 * @param policyId the ID of specified policy
\r
771 * @return the Response object containing the results of the API operation
\r
774 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
775 @ApiOperation(value = "Delete all versions of a policy",
\r
776 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
777 authorizations = @Authorization(value = "basicAuth"),
\r
778 tags = { "Policy", },
\r
780 @Extension(name = "interface info", properties = {
\r
781 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
782 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
785 @ApiResponses(value = {
\r
786 @ApiResponse(code = 204, message = "Resources successfully deleted, no content returned",
\r
787 responseHeaders = {
\r
788 @ResponseHeader(name = "X-MinorVersion",
\r
789 description = "Used to request or communicate a MINOR version back from the client"
\r
790 + " to the server, and from the server back to the client",
\r
791 response = String.class),
\r
792 @ResponseHeader(name = "X-PatchVersion",
\r
793 description = "Used only to communicate a PATCH version in a response for"
\r
794 + " troubleshooting purposes only, and will not be provided by"
\r
795 + " the client on request",
\r
796 response = String.class),
\r
797 @ResponseHeader(name = "X-LatestVersion",
\r
798 description = "Used only to communicate an API's latest version",
\r
799 response = String.class),
\r
800 @ResponseHeader(name = "X-ONAP-RequestID",
\r
801 description = "Used to track REST transactions for logging purpose",
\r
802 response = UUID.class)
\r
804 @ApiResponse(code = 401, message = "Authentication Error"),
\r
805 @ApiResponse(code = 403, message = "Authorization Error"),
\r
806 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
807 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
808 @ApiResponse(code = 500, message = "Internal Server Error")
\r
810 public Response deleteAllVersionsOfPolicy(
\r
811 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
812 @PathParam("policyTypeVersion")
\r
813 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
814 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
815 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
816 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
817 .entity(new PolicyProvider().deletePolicies(policyTypeId, policyTypeVersion, policyId, null)).build();
\r
821 * Deletes the specified version of a particular policy.
\r
823 * @param policyTypeId the ID of specified policy type
\r
824 * @param policyTypeVersion the version of specified policy type
\r
825 * @param policyId the ID of specified policy
\r
826 * @param policyVersion the version of specified policy
\r
828 * @return the Response object containing the results of the API operation
\r
831 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
832 @ApiOperation(value = "Delete a particular version of a policy",
\r
833 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
834 authorizations = @Authorization(value = "basicAuth"),
\r
835 tags = { "Policy", },
\r
837 @Extension(name = "interface info", properties = {
\r
838 @ExtensionProperty(name = "api-version", value = "1.0.0"),
\r
839 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
\r
842 @ApiResponses(value = {
\r
843 @ApiResponse(code = 204, message = "Resource successfully deleted, no content returned",
\r
844 responseHeaders = {
\r
845 @ResponseHeader(name = "X-MinorVersion",
\r
846 description = "Used to request or communicate a MINOR version back from the client"
\r
847 + " to the server, and from the server back to the client",
\r
848 response = String.class),
\r
849 @ResponseHeader(name = "X-PatchVersion",
\r
850 description = "Used only to communicate a PATCH version in a response for"
\r
851 + " troubleshooting purposes only, and will not be provided by"
\r
852 + " the client on request",
\r
853 response = String.class),
\r
854 @ResponseHeader(name = "X-LatestVersion",
\r
855 description = "Used only to communicate an API's latest version",
\r
856 response = String.class),
\r
857 @ResponseHeader(name = "X-ONAP-RequestID",
\r
858 description = "Used to track REST transactions for logging purpose",
\r
859 response = UUID.class)
\r
861 @ApiResponse(code = 401, message = "Authentication Error"),
\r
862 @ApiResponse(code = 403, message = "Authorization Error"),
\r
863 @ApiResponse(code = 404, message = "Resource Not Found"),
\r
864 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
\r
865 @ApiResponse(code = 500, message = "Internal Server Error")
\r
867 public Response deleteSpecificVersionOfPolicy(
\r
868 @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
\r
869 @PathParam("policyTypeVersion")
\r
870 @ApiParam(value = "Version of policy type", required = true) String policyTypeVersion,
\r
871 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
872 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
873 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
\r
874 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
\r
875 .entity(new PolicyProvider().deletePolicies(policyTypeId, policyTypeVersion,
\r
876 policyId, policyVersion)).build();
\r
879 private ResponseBuilder addVersionControlHeaders(ResponseBuilder rb) {
\r
880 return rb.header("X-MinorVersion", "0").header("X-PatchVersion", "0").header("X-LatestVersion", "1.0.0");
\r
883 private ResponseBuilder addLoggingHeaders(ResponseBuilder rb, UUID requestId) {
\r
884 if (requestId == null) {
\r
885 // Generate a random uuid if client does not embed requestId in rest request
\r
886 return rb.header("X-ONAP-RequestID", UUID.randomUUID());
\r
888 return rb.header("X-ONAP-RequestID", requestId);
\r