2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.api.main.rest;
25 import io.swagger.annotations.Api;
26 import io.swagger.annotations.ApiOperation;
27 import io.swagger.annotations.ApiParam;
28 import io.swagger.annotations.ApiResponse;
29 import io.swagger.annotations.ApiResponses;
30 import io.swagger.annotations.Authorization;
31 import io.swagger.annotations.Extension;
32 import io.swagger.annotations.ExtensionProperty;
33 import io.swagger.annotations.ResponseHeader;
35 import java.util.UUID;
36 import javax.ws.rs.Consumes;
37 import javax.ws.rs.DELETE;
38 import javax.ws.rs.GET;
39 import javax.ws.rs.HeaderParam;
40 import javax.ws.rs.POST;
41 import javax.ws.rs.Path;
42 import javax.ws.rs.PathParam;
43 import javax.ws.rs.Produces;
44 import javax.ws.rs.core.Response;
45 import javax.ws.rs.core.Response.ResponseBuilder;
46 import org.onap.policy.api.main.rest.provider.LegacyGuardPolicyProvider;
47 import org.onap.policy.api.main.rest.provider.LegacyOperationalPolicyProvider;
48 import org.onap.policy.models.base.PfModelException;
49 import org.onap.policy.models.base.PfModelRuntimeException;
50 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
51 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
52 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
55 * Class to provide legacy REST API services.
57 * @author Chenfei Gao (cgao@research.att.com)
59 @Path("/policy/api/v1")
60 @Api(value = "Legacy Policy Design API")
61 @Produces({"application/json; vnd.onap.guard", "application/json; vnd.onap.operational"})
62 @Consumes({"application/json; vnd.onap.guard", "application/json; vnd.onap.operational"})
63 public class LegacyApiRestController {
66 * Retrieves all versions of guard policies.
68 * @return the Response object containing the results of the API operation
71 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies")
72 @Produces("application/json; vnd.onap.guard")
73 @ApiOperation(value = "Retrieve all versions of guard policies",
74 notes = "Returns a list of all versions of guard policies",
75 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
77 @ResponseHeader(name = "X-MinorVersion",
78 description = "Used to request or communicate a MINOR version back from the client"
79 + " to the server, and from the server back to the client",
80 response = String.class),
81 @ResponseHeader(name = "X-PatchVersion",
82 description = "Used only to communicate a PATCH version in a response for"
83 + " troubleshooting purposes only, and will not be provided by"
84 + " the client on request",
85 response = String.class),
86 @ResponseHeader(name = "X-LatestVersion",
87 description = "Used only to communicate an API's latest version",
88 response = String.class),
89 @ResponseHeader(name = "X-ONAP-RequestID",
90 description = "Used to track REST transactions for logging purpose",
91 response = UUID.class)
93 authorizations = @Authorization(value = "basicAuth"),
94 tags = { "Legacy Guard Policy", },
96 @Extension(name = "interface info", properties = {
97 @ExtensionProperty(name = "api-version", value = "1.0.0"),
98 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
101 @ApiResponses(value = {
102 @ApiResponse(code = 401, message = "Authentication Error"),
103 @ApiResponse(code = 403, message = "Authorization Error"),
104 @ApiResponse(code = 500, message = "Internal Server Error")
106 public Response getAllGuardPolicies(
107 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
110 Map<String, LegacyGuardPolicyOutput> policies = new LegacyGuardPolicyProvider()
111 .fetchGuardPolicies(null, null);
112 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
113 .entity(policies).build();
114 } catch (PfModelException | PfModelRuntimeException pfme) {
115 return addLoggingHeaders(addVersionControlHeaders(
116 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
117 .entity(pfme.getErrorResponse()).build();
122 * Retrieves all versions of a particular guard policy.
124 * @param policyId the ID of specified guard policy
126 * @return the Response object containing the results of the API operation
129 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}")
130 @Produces("application/json; vnd.onap.guard")
131 @ApiOperation(value = "Retrieve all versions of a particular guard policy",
132 notes = "Returns a list of all versions of the specified guard policy",
133 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
135 @ResponseHeader(name = "X-MinorVersion",
136 description = "Used to request or communicate a MINOR version back from the client"
137 + " to the server, and from the server back to the client",
138 response = String.class),
139 @ResponseHeader(name = "X-PatchVersion",
140 description = "Used only to communicate a PATCH version in a response for"
141 + " troubleshooting purposes only, and will not be provided by"
142 + " the client on request",
143 response = String.class),
144 @ResponseHeader(name = "X-LatestVersion",
145 description = "Used only to communicate an API's latest version",
146 response = String.class),
147 @ResponseHeader(name = "X-ONAP-RequestID",
148 description = "Used to track REST transactions for logging purpose",
149 response = UUID.class)
151 authorizations = @Authorization(value = "basicAuth"),
152 tags = { "Legacy Guard Policy", },
154 @Extension(name = "interface info", properties = {
155 @ExtensionProperty(name = "api-version", value = "1.0.0"),
156 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
159 @ApiResponses(value = {
160 @ApiResponse(code = 401, message = "Authentication Error"),
161 @ApiResponse(code = 403, message = "Authorization Error"),
162 @ApiResponse(code = 404, message = "Resource Not Found"),
163 @ApiResponse(code = 500, message = "Internal Server Error")
165 public Response getAllVersionsOfGuardPolicy(
166 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
167 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
170 Map<String, LegacyGuardPolicyOutput> policies = new LegacyGuardPolicyProvider()
171 .fetchGuardPolicies(policyId, null);
172 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
173 .entity(policies).build();
174 } catch (PfModelException | PfModelRuntimeException pfme) {
175 return addLoggingHeaders(addVersionControlHeaders(
176 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
177 .entity(pfme.getErrorResponse()).build();
182 * Retrieves the specified version of a particular guard policy.
184 * @param policyId the ID of specified policy
185 * @param policyVersion the version of specified policy
187 * @return the Response object containing the results of the API operation
190 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
191 @Produces("application/json; vnd.onap.guard")
192 @ApiOperation(value = "Retrieve one version of a particular guard policy",
193 notes = "Returns a particular version of a specified guard policy",
194 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
196 @ResponseHeader(name = "X-MinorVersion",
197 description = "Used to request or communicate a MINOR version back from the client"
198 + " to the server, and from the server back to the client",
199 response = String.class),
200 @ResponseHeader(name = "X-PatchVersion",
201 description = "Used only to communicate a PATCH version in a response for"
202 + " troubleshooting purposes only, and will not be provided by"
203 + " the client on request",
204 response = String.class),
205 @ResponseHeader(name = "X-LatestVersion",
206 description = "Used only to communicate an API's latest version",
207 response = String.class),
208 @ResponseHeader(name = "X-ONAP-RequestID",
209 description = "Used to track REST transactions for logging purpose",
210 response = UUID.class)
212 authorizations = @Authorization(value = "basicAuth"),
213 tags = { "Legacy Guard Policy", },
215 @Extension(name = "interface info", properties = {
216 @ExtensionProperty(name = "api-version", value = "1.0.0"),
217 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
220 @ApiResponses(value = {
221 @ApiResponse(code = 401, message = "Authentication Error"),
222 @ApiResponse(code = 403, message = "Authorization Error"),
223 @ApiResponse(code = 404, message = "Resource Not Found"),
224 @ApiResponse(code = 500, message = "Internal Server Error")
226 public Response getSpecificVersionOfGuardPolicy(
227 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
228 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
229 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
232 Map<String, LegacyGuardPolicyOutput> policies = new LegacyGuardPolicyProvider()
233 .fetchGuardPolicies(policyId, policyVersion);
234 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
235 .entity(policies).build();
236 } catch (PfModelException | PfModelRuntimeException pfme) {
237 return addLoggingHeaders(addVersionControlHeaders(
238 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
239 .entity(pfme.getErrorResponse()).build();
244 * Creates a new guard policy.
246 * @param body the body of policy
248 * @return the Response object containing the results of the API operation
251 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies")
252 @Consumes("application/json; vnd.onap.guard")
253 @Produces("application/json; vnd.onap.guard")
254 @ApiOperation(value = "Create a new guard policy",
255 notes = "Client should provide entity body of the new guard policy",
256 authorizations = @Authorization(value = "basicAuth"),
257 tags = { "Legacy Guard Policy", },
258 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
260 @ResponseHeader(name = "X-MinorVersion",
261 description = "Used to request or communicate a MINOR version back from the client"
262 + " to the server, and from the server back to the client",
263 response = String.class),
264 @ResponseHeader(name = "X-PatchVersion",
265 description = "Used only to communicate a PATCH version in a response for"
266 + " troubleshooting purposes only, and will not be provided by"
267 + " the client on request",
268 response = String.class),
269 @ResponseHeader(name = "X-LatestVersion",
270 description = "Used only to communicate an API's latest version",
271 response = String.class),
272 @ResponseHeader(name = "X-ONAP-RequestID",
273 description = "Used to track REST transactions for logging purpose",
274 response = UUID.class)
277 @Extension(name = "interface info", properties = {
278 @ExtensionProperty(name = "api-version", value = "1.0.0"),
279 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
282 @ApiResponses(value = {
283 @ApiResponse(code = 400, message = "Invalid Body"),
284 @ApiResponse(code = 401, message = "Authentication Error"),
285 @ApiResponse(code = 403, message = "Authorization Error"),
286 @ApiResponse(code = 500, message = "Internal Server Error")
288 public Response createGuardPolicy(
289 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
290 @ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicyInput body) {
293 Map<String, LegacyGuardPolicyOutput> policy = new LegacyGuardPolicyProvider().createGuardPolicy(body);
294 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
295 .entity(policy).build();
296 } catch (PfModelException | PfModelRuntimeException pfme) {
297 return addLoggingHeaders(addVersionControlHeaders(
298 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
299 .entity(pfme.getErrorResponse()).build();
304 * Deletes the specified version of a particular guard policy.
306 * @param policyId the ID of specified policy
307 * @param policyVersion the version of specified policy
309 * @return the Response object containing the results of the API operation
312 @Path("/policytypes/onap.policy.controlloop.guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
313 @Produces("application/json; vnd.onap.guard")
314 @ApiOperation(value = "Delete a particular version of a guard policy",
315 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
316 authorizations = @Authorization(value = "basicAuth"),
317 tags = { "Legacy Guard Policy", },
318 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
320 @ResponseHeader(name = "X-MinorVersion",
321 description = "Used to request or communicate a MINOR version back from the client"
322 + " to the server, and from the server back to the client",
323 response = String.class),
324 @ResponseHeader(name = "X-PatchVersion",
325 description = "Used only to communicate a PATCH version in a response for"
326 + " troubleshooting purposes only, and will not be provided by"
327 + " the client on request",
328 response = String.class),
329 @ResponseHeader(name = "X-LatestVersion",
330 description = "Used only to communicate an API's latest version",
331 response = String.class),
332 @ResponseHeader(name = "X-ONAP-RequestID",
333 description = "Used to track REST transactions for logging purpose",
334 response = UUID.class)
337 @Extension(name = "interface info", properties = {
338 @ExtensionProperty(name = "api-version", value = "1.0.0"),
339 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
342 @ApiResponses(value = {
343 @ApiResponse(code = 401, message = "Authentication Error"),
344 @ApiResponse(code = 403, message = "Authorization Error"),
345 @ApiResponse(code = 404, message = "Resource Not Found"),
346 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
347 @ApiResponse(code = 500, message = "Internal Server Error")
349 public Response deleteSpecificVersionOfGuardPolicy(
350 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
351 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
352 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
355 Map<String, LegacyGuardPolicyOutput> policies = new LegacyGuardPolicyProvider()
356 .deleteGuardPolicies(policyId, policyVersion);
357 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
358 .entity(policies).build();
359 } catch (PfModelException | PfModelRuntimeException pfme) {
360 return addLoggingHeaders(addVersionControlHeaders(
361 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
362 .entity(pfme.getErrorResponse()).build();
367 * Retrieves all versions of operational policies.
369 * @return the Response object containing the results of the API operation
372 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies")
373 @Produces("application/json; vnd.onap.operational")
374 @ApiOperation(value = "Retrieve all versions of operational policies",
375 notes = "Returns a list of all versions of operational policies",
376 response = LegacyOperationalPolicy.class,
378 @ResponseHeader(name = "X-MinorVersion",
379 description = "Used to request or communicate a MINOR version back from the client"
380 + " to the server, and from the server back to the client",
381 response = String.class),
382 @ResponseHeader(name = "X-PatchVersion",
383 description = "Used only to communicate a PATCH version in a response for"
384 + " troubleshooting purposes only, and will not be provided by"
385 + " the client on request",
386 response = String.class),
387 @ResponseHeader(name = "X-LatestVersion",
388 description = "Used only to communicate an API's latest version",
389 response = String.class),
390 @ResponseHeader(name = "X-ONAP-RequestID",
391 description = "Used to track REST transactions for logging purpose",
392 response = UUID.class)
394 authorizations = @Authorization(value = "basicAuth"),
395 tags = { "Legacy Operational Policy", },
397 @Extension(name = "interface info", properties = {
398 @ExtensionProperty(name = "api-version", value = "1.0.0"),
399 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
402 @ApiResponses(value = {
403 @ApiResponse(code = 401, message = "Authentication Error"),
404 @ApiResponse(code = 403, message = "Authorization Error"),
405 @ApiResponse(code = 500, message = "Internal Server Error")
407 public Response getAllOperationalPolicies(
408 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
411 LegacyOperationalPolicy policy = new LegacyOperationalPolicyProvider()
412 .fetchOperationalPolicies(null, null);
413 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
414 .entity(policy).build();
415 } catch (PfModelException | PfModelRuntimeException pfme) {
416 return addLoggingHeaders(addVersionControlHeaders(
417 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
418 .entity(pfme.getErrorResponse()).build();
423 * Retrieves all versions of a particular operational policy.
425 * @param policyId the ID of specified operational policy
427 * @return the Response object containing the results of the API operation
430 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies/{policyId}")
431 @Produces("application/json; vnd.onap.operational")
432 @ApiOperation(value = "Retrieve all versions of a particular operational policy",
433 notes = "Returns a list of all versions of the specified operational policy",
434 response = LegacyOperationalPolicy.class,
436 @ResponseHeader(name = "X-MinorVersion",
437 description = "Used to request or communicate a MINOR version back from the client"
438 + " to the server, and from the server back to the client",
439 response = String.class),
440 @ResponseHeader(name = "X-PatchVersion",
441 description = "Used only to communicate a PATCH version in a response for"
442 + " troubleshooting purposes only, and will not be provided by"
443 + " the client on request",
444 response = String.class),
445 @ResponseHeader(name = "X-LatestVersion",
446 description = "Used only to communicate an API's latest version",
447 response = String.class),
448 @ResponseHeader(name = "X-ONAP-RequestID",
449 description = "Used to track REST transactions for logging purpose",
450 response = UUID.class)
452 authorizations = @Authorization(value = "basicAuth"),
453 tags = { "Legacy Operational Policy", },
455 @Extension(name = "interface info", properties = {
456 @ExtensionProperty(name = "api-version", value = "1.0.0"),
457 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
460 @ApiResponses(value = {
461 @ApiResponse(code = 401, message = "Authentication Error"),
462 @ApiResponse(code = 403, message = "Authorization Error"),
463 @ApiResponse(code = 404, message = "Resource Not Found"),
464 @ApiResponse(code = 500, message = "Internal Server Error")
466 public Response getAllVersionsOfOperationalPolicy(
467 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
468 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
471 LegacyOperationalPolicy policy = new LegacyOperationalPolicyProvider()
472 .fetchOperationalPolicies(policyId, null);
473 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
474 .entity(policy).build();
475 } catch (PfModelException | PfModelRuntimeException pfme) {
476 return addLoggingHeaders(addVersionControlHeaders(
477 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
478 .entity(pfme.getErrorResponse()).build();
483 * Retrieves the specified version of a particular operational policy.
485 * @param policyId the ID of specified policy
486 * @param policyVersion the version of specified policy
488 * @return the Response object containing the results of the API operation
491 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/"
492 + "policies/{policyId}/versions/{policyVersion}")
493 @Produces("application/json; vnd.onap.operational")
494 @ApiOperation(value = "Retrieve one version of a particular operational policy",
495 notes = "Returns a particular version of a specified operational policy",
496 response = LegacyOperationalPolicy.class,
498 @ResponseHeader(name = "X-MinorVersion",
499 description = "Used to request or communicate a MINOR version back from the client"
500 + " to the server, and from the server back to the client",
501 response = String.class),
502 @ResponseHeader(name = "X-PatchVersion",
503 description = "Used only to communicate a PATCH version in a response for"
504 + " troubleshooting purposes only, and will not be provided by"
505 + " the client on request",
506 response = String.class),
507 @ResponseHeader(name = "X-LatestVersion",
508 description = "Used only to communicate an API's latest version",
509 response = String.class),
510 @ResponseHeader(name = "X-ONAP-RequestID",
511 description = "Used to track REST transactions for logging purpose",
512 response = UUID.class)
514 authorizations = @Authorization(value = "basicAuth"),
515 tags = { "Legacy Operational Policy", },
517 @Extension(name = "interface info", properties = {
518 @ExtensionProperty(name = "api-version", value = "1.0.0"),
519 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
522 @ApiResponses(value = {
523 @ApiResponse(code = 401, message = "Authentication Error"),
524 @ApiResponse(code = 403, message = "Authorization Error"),
525 @ApiResponse(code = 404, message = "Resource Not Found"),
526 @ApiResponse(code = 500, message = "Internal Server Error")
528 public Response getSpecificVersionOfOperationalPolicy(
529 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
530 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
531 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
534 LegacyOperationalPolicy policy = new LegacyOperationalPolicyProvider()
535 .fetchOperationalPolicies(policyId, policyVersion);
536 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
537 .entity(policy).build();
538 } catch (PfModelException | PfModelRuntimeException pfme) {
539 return addLoggingHeaders(addVersionControlHeaders(
540 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
541 .entity(pfme.getErrorResponse()).build();
546 * Creates a new operational policy.
548 * @param body the body of policy
550 * @return the Response object containing the results of the API operation
553 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/policies")
554 @Consumes("application/json; vnd.onap.operational")
555 @Produces("application/json; vnd.onap.operational")
556 @ApiOperation(value = "Create a new operational policy",
557 notes = "Client should provide entity body of the new operational policy",
558 authorizations = @Authorization(value = "basicAuth"),
559 tags = { "Legacy Operational Policy", },
560 response = LegacyOperationalPolicy.class,
562 @ResponseHeader(name = "X-MinorVersion",
563 description = "Used to request or communicate a MINOR version back from the client"
564 + " to the server, and from the server back to the client",
565 response = String.class),
566 @ResponseHeader(name = "X-PatchVersion",
567 description = "Used only to communicate a PATCH version in a response for"
568 + " troubleshooting purposes only, and will not be provided by"
569 + " the client on request",
570 response = String.class),
571 @ResponseHeader(name = "X-LatestVersion",
572 description = "Used only to communicate an API's latest version",
573 response = String.class),
574 @ResponseHeader(name = "X-ONAP-RequestID",
575 description = "Used to track REST transactions for logging purpose",
576 response = UUID.class)
579 @Extension(name = "interface info", properties = {
580 @ExtensionProperty(name = "api-version", value = "1.0.0"),
581 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
584 @ApiResponses(value = {
585 @ApiResponse(code = 400, message = "Invalid Body"),
586 @ApiResponse(code = 401, message = "Authentication Error"),
587 @ApiResponse(code = 403, message = "Authorization Error"),
588 @ApiResponse(code = 500, message = "Internal Server Error")
590 public Response createOperationalPolicy(
591 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
592 @ApiParam(value = "Entity body of policy", required = true) LegacyOperationalPolicy body) {
595 LegacyOperationalPolicy policy = new LegacyOperationalPolicyProvider()
596 .createOperationalPolicy(body);
597 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
598 .entity(policy).build();
599 } catch (PfModelException | PfModelRuntimeException pfme) {
600 return addLoggingHeaders(addVersionControlHeaders(
601 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
602 .entity(pfme.getErrorResponse()).build();
607 * Deletes the specified version of a particular operational policy.
609 * @param policyId the ID of specified policy
610 * @param policyVersion the version of specified policy
612 * @return the Response object containing the results of the API operation
615 @Path("/policytypes/onap.policy.controlloop.operational/versions/1.0.0/"
616 + "policies/{policyId}/versions/{policyVersion}")
617 @Produces("application/json; vnd.onap.operational")
618 @ApiOperation(value = "Delete a particular version of a specified operational policy",
619 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
620 authorizations = @Authorization(value = "basicAuth"),
621 tags = { "Legacy Operational Policy", },
622 response = LegacyOperationalPolicy.class,
624 @ResponseHeader(name = "X-MinorVersion",
625 description = "Used to request or communicate a MINOR version back from the client"
626 + " to the server, and from the server back to the client",
627 response = String.class),
628 @ResponseHeader(name = "X-PatchVersion",
629 description = "Used only to communicate a PATCH version in a response for"
630 + " troubleshooting purposes only, and will not be provided by"
631 + " the client on request",
632 response = String.class),
633 @ResponseHeader(name = "X-LatestVersion",
634 description = "Used only to communicate an API's latest version",
635 response = String.class),
636 @ResponseHeader(name = "X-ONAP-RequestID",
637 description = "Used to track REST transactions for logging purpose",
638 response = UUID.class)
641 @Extension(name = "interface info", properties = {
642 @ExtensionProperty(name = "api-version", value = "1.0.0"),
643 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
646 @ApiResponses(value = {
647 @ApiResponse(code = 401, message = "Authentication Error"),
648 @ApiResponse(code = 403, message = "Authorization Error"),
649 @ApiResponse(code = 404, message = "Resource Not Found"),
650 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
651 @ApiResponse(code = 500, message = "Internal Server Error")
653 public Response deleteSpecificVersionOfOperationalPolicy(
654 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
655 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
656 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
659 LegacyOperationalPolicy policy = new LegacyOperationalPolicyProvider()
660 .deleteOperationalPolicies(policyId, policyVersion);
661 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
662 .entity(policy).build();
663 } catch (PfModelException | PfModelRuntimeException pfme) {
664 return addLoggingHeaders(addVersionControlHeaders(
665 Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
666 .entity(pfme.getErrorResponse()).build();
670 private ResponseBuilder addVersionControlHeaders(ResponseBuilder rb) {
671 return rb.header("X-MinorVersion", "0").header("X-PatchVersion", "0").header("X-LatestVersion", "1.0.0");
674 private ResponseBuilder addLoggingHeaders(ResponseBuilder rb, UUID requestId) {
675 if (requestId == null) {
676 // Generate a random uuid if client does not embed requestId in rest request
677 return rb.header("X-ONAP-RequestID", UUID.randomUUID());
679 return rb.header("X-ONAP-RequestID", requestId);