Add changes to support application/yaml in api
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / LegacyApiRestController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy API
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.api.main.rest;
24
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;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.UUID;
37 import javax.ws.rs.Consumes;
38 import javax.ws.rs.DELETE;
39 import javax.ws.rs.GET;
40 import javax.ws.rs.HeaderParam;
41 import javax.ws.rs.POST;
42 import javax.ws.rs.Path;
43 import javax.ws.rs.PathParam;
44 import javax.ws.rs.Produces;
45 import javax.ws.rs.core.Response;
46 import org.apache.commons.lang3.tuple.Pair;
47 import org.onap.policy.api.main.rest.provider.LegacyGuardPolicyProvider;
48 import org.onap.policy.api.main.rest.provider.LegacyOperationalPolicyProvider;
49 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
50 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
51 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
52 import org.onap.policy.models.base.PfModelException;
53 import org.onap.policy.models.base.PfModelRuntimeException;
54 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
55 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
56 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
59
60 /**
61  * Class to provide legacy REST API services.
62  *
63  * @author Chenfei Gao (cgao@research.att.com)
64  */
65 @Path("/policy/api/v1")
66 @Api(value = "Legacy Policy Design API")
67 @Produces({"application/json", "application/yaml"})
68 @Consumes({"application/json", "application/yaml"})
69 public class LegacyApiRestController extends CommonRestController {
70
71     private static final Logger LOGGER = LoggerFactory.getLogger(LegacyApiRestController.class);
72
73     /**
74      * Retrieves the latest version of a particular guard policy.
75      *
76      * @param policyId the ID of specified guard policy
77      *
78      * @return the Response object containing the results of the API operation
79      */
80     @GET
81     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/latest")
82     @ApiOperation(value = "Retrieve the latest version of a particular guard policy",
83             notes = "Returns the latest version of the specified guard policy",
84             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
85             responseHeaders = {
86                     @ResponseHeader(name = "X-MinorVersion",
87                                     description = "Used to request or communicate a MINOR version back from the client"
88                                                 + " to the server, and from the server back to the client",
89                                     response = String.class),
90                     @ResponseHeader(name = "X-PatchVersion",
91                                     description = "Used only to communicate a PATCH version in a response for"
92                                                 + " troubleshooting purposes only, and will not be provided by"
93                                                 + " the client on request",
94                                     response = String.class),
95                     @ResponseHeader(name = "X-LatestVersion",
96                                     description = "Used only to communicate an API's latest version",
97                                     response = String.class),
98                     @ResponseHeader(name = "X-ONAP-RequestID",
99                                     description = "Used to track REST transactions for logging purpose",
100                                     response = UUID.class)
101             },
102             authorizations = @Authorization(value = "basicAuth"),
103             tags = { "Legacy Guard Policy", },
104             extensions = {
105                     @Extension(name = "interface info", properties = {
106                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
107                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
108                     })
109             })
110     @ApiResponses(value = {
111             @ApiResponse(code = 401, message = "Authentication Error"),
112             @ApiResponse(code = 403, message = "Authorization Error"),
113             @ApiResponse(code = 404, message = "Resource Not Found"),
114             @ApiResponse(code = 500, message = "Internal Server Error")
115         })
116     public Response getLatestVersionOfGuardPolicy(
117             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
118             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
119
120         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
121             Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider.fetchGuardPolicy(policyId, null);
122             return makeOkResponse(requestId, policies);
123         } catch (PfModelException | PfModelRuntimeException pfme) {
124             LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}"
125                 + "/versions/latest", policyId, pfme);
126             return makeErrorResponse(requestId, pfme);
127         }
128     }
129
130     /**
131      * Retrieves the specified version of a particular guard policy.
132      *
133      * @param policyId the ID of specified policy
134      * @param policyVersion the version of specified policy
135      *
136      * @return the Response object containing the results of the API operation
137      */
138     @GET
139     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
140     @ApiOperation(value = "Retrieve one version of a particular guard policy",
141             notes = "Returns a particular version of a specified guard policy",
142             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
143             responseHeaders = {
144                     @ResponseHeader(name = "X-MinorVersion",
145                                     description = "Used to request or communicate a MINOR version back from the client"
146                                                 + " to the server, and from the server back to the client",
147                                     response = String.class),
148                     @ResponseHeader(name = "X-PatchVersion",
149                                     description = "Used only to communicate a PATCH version in a response for"
150                                                 + " troubleshooting purposes only, and will not be provided by"
151                                                 + " the client on request",
152                                     response = String.class),
153                     @ResponseHeader(name = "X-LatestVersion",
154                                     description = "Used only to communicate an API's latest version",
155                                     response = String.class),
156                     @ResponseHeader(name = "X-ONAP-RequestID",
157                                     description = "Used to track REST transactions for logging purpose",
158                                     response = UUID.class)
159             },
160             authorizations = @Authorization(value = "basicAuth"),
161             tags = { "Legacy Guard Policy", },
162             extensions = {
163                     @Extension(name = "interface info", properties = {
164                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
165                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
166                     })
167             })
168     @ApiResponses(value = {
169             @ApiResponse(code = 401, message = "Authentication Error"),
170             @ApiResponse(code = 403, message = "Authorization Error"),
171             @ApiResponse(code = 404, message = "Resource Not Found"),
172             @ApiResponse(code = 500, message = "Internal Server Error")
173         })
174     public Response getSpecificVersionOfGuardPolicy(
175             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
176             @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
177             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
178
179         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
180             Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider
181                     .fetchGuardPolicy(policyId, policyVersion);
182             return makeOkResponse(requestId, policies);
183         } catch (PfModelException | PfModelRuntimeException pfme) {
184             LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
185                     policyId, policyVersion, pfme);
186             return makeErrorResponse(requestId, pfme);
187         }
188     }
189
190     /**
191      * Retrieves deployed versions of a particular guard policy in PDP groups.
192      *
193      * @param policyId the ID of specified policy
194      *
195      * @return the Response object containing the results of the API operation
196      */
197     @GET
198     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/"
199          + "policies/{policyId}/versions/deployed")
200     @ApiOperation(value = "Retrieve deployed versions of a particular guard policy in pdp groups",
201             notes = "Returns deployed versions of a specified guard policy in pdp groups",
202             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
203             responseHeaders = {
204                     @ResponseHeader(name = "X-MinorVersion",
205                                     description = "Used to request or communicate a MINOR version back from the client"
206                                                 + " to the server, and from the server back to the client",
207                                     response = String.class),
208                     @ResponseHeader(name = "X-PatchVersion",
209                                     description = "Used only to communicate a PATCH version in a response for"
210                                                 + " troubleshooting purposes only, and will not be provided by"
211                                                 + " the client on request",
212                                     response = String.class),
213                     @ResponseHeader(name = "X-LatestVersion",
214                                     description = "Used only to communicate an API's latest version",
215                                     response = String.class),
216                     @ResponseHeader(name = "X-ONAP-RequestID",
217                                     description = "Used to track REST transactions for logging purpose",
218                                     response = UUID.class)
219             },
220             authorizations = @Authorization(value = "basicAuth"),
221             tags = { "Legacy Guard Policy", },
222             extensions = {
223                     @Extension(name = "interface info", properties = {
224                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
225                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
226                     })
227             })
228     @ApiResponses(value = {
229             @ApiResponse(code = 401, message = "Authentication Error"),
230             @ApiResponse(code = 403, message = "Authorization Error"),
231             @ApiResponse(code = 404, message = "Resource Not Found"),
232             @ApiResponse(code = 500, message = "Internal Server Error")
233         })
234     public Response getDeployedVersionsOfGuardPolicy(
235             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
236             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
237
238         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
239             Map<Pair<String, String>, Map<String, LegacyGuardPolicyOutput>> deployedGuardPolicies =
240                     guardPolicyProvider.fetchDeployedGuardPolicies(policyId);
241             return makeOkResponse(requestId, deployedGuardPolicies);
242         } catch (PfModelException | PfModelRuntimeException pfme) {
243             LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/"
244                 + "policies/{}/versions/deployed", policyId, pfme);
245             return makeErrorResponse(requestId, pfme);
246         }
247     }
248
249     /**
250      * Creates a new guard policy.
251      *
252      * @param body the body of policy
253      *
254      * @return the Response object containing the results of the API operation
255      */
256     @POST
257     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies")
258     @ApiOperation(value = "Create a new guard policy",
259             notes = "Client should provide entity body of the new guard policy",
260             authorizations = @Authorization(value = "basicAuth"),
261             tags = { "Legacy Guard Policy", },
262             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
263             responseHeaders = {
264                     @ResponseHeader(name = "X-MinorVersion",
265                                     description = "Used to request or communicate a MINOR version back from the client"
266                                                 + " to the server, and from the server back to the client",
267                                     response = String.class),
268                     @ResponseHeader(name = "X-PatchVersion",
269                                     description = "Used only to communicate a PATCH version in a response for"
270                                                 + " troubleshooting purposes only, and will not be provided by"
271                                                 + " the client on request",
272                                     response = String.class),
273                     @ResponseHeader(name = "X-LatestVersion",
274                                     description = "Used only to communicate an API's latest version",
275                                     response = String.class),
276                     @ResponseHeader(name = "X-ONAP-RequestID",
277                                     description = "Used to track REST transactions for logging purpose",
278                                     response = UUID.class)
279             },
280             extensions = {
281                     @Extension(name = "interface info", properties = {
282                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
283                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
284                     })
285             })
286     @ApiResponses(value = {
287             @ApiResponse(code = 400, message = "Invalid Body"),
288             @ApiResponse(code = 401, message = "Authentication Error"),
289             @ApiResponse(code = 403, message = "Authorization Error"),
290             @ApiResponse(code = 500, message = "Internal Server Error")
291         })
292     public Response createGuardPolicy(
293             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
294             @ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicyInput body) {
295
296         if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
297             NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
298                             "/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", toJson(body));
299         }
300
301         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
302             Map<String, LegacyGuardPolicyOutput> policy = guardPolicyProvider.createGuardPolicy(body);
303             return makeOkResponse(requestId, policy);
304         } catch (PfModelException | PfModelRuntimeException pfme) {
305             LOGGER.error("POST /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", pfme);
306             return makeErrorResponse(requestId, pfme);
307         }
308     }
309
310     /**
311      * Deletes the specified version of a particular guard policy.
312      *
313      * @param policyId the ID of specified policy
314      * @param policyVersion the version of specified policy
315      *
316      * @return the Response object containing the results of the API operation
317      */
318     @DELETE
319     @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
320     @ApiOperation(value = "Delete a particular version of a guard policy",
321             notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
322             authorizations = @Authorization(value = "basicAuth"),
323             tags = { "Legacy Guard Policy", },
324             response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
325             responseHeaders = {
326                     @ResponseHeader(name = "X-MinorVersion",
327                                     description = "Used to request or communicate a MINOR version back from the client"
328                                                 + " to the server, and from the server back to the client",
329                                     response = String.class),
330                     @ResponseHeader(name = "X-PatchVersion",
331                                     description = "Used only to communicate a PATCH version in a response for"
332                                                 + " troubleshooting purposes only, and will not be provided by"
333                                                 + " the client on request",
334                                     response = String.class),
335                     @ResponseHeader(name = "X-LatestVersion",
336                                     description = "Used only to communicate an API's latest version",
337                                     response = String.class),
338                     @ResponseHeader(name = "X-ONAP-RequestID",
339                                     description = "Used to track REST transactions for logging purpose",
340                                     response = UUID.class)
341             },
342             extensions = {
343                     @Extension(name = "interface info", properties = {
344                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
345                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
346                     })
347             })
348     @ApiResponses(value = {
349             @ApiResponse(code = 401, message = "Authentication Error"),
350             @ApiResponse(code = 403, message = "Authorization Error"),
351             @ApiResponse(code = 404, message = "Resource Not Found"),
352             @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
353             @ApiResponse(code = 500, message = "Internal Server Error")
354         })
355     public Response deleteSpecificVersionOfGuardPolicy(
356             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
357             @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
358             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
359
360         try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
361             Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider
362                     .deleteGuardPolicy(policyId, policyVersion);
363             return makeOkResponse(requestId, policies);
364         } catch (PfModelException | PfModelRuntimeException pfme) {
365             LOGGER.error("DELETE /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
366                     policyId, policyVersion, pfme);
367             return makeErrorResponse(requestId, pfme);
368         }
369     }
370
371     /**
372      * Retrieves the latest version of a particular operational policy.
373      *
374      * @param policyId the ID of specified operational policy
375      *
376      * @return the Response object containing the results of the API operation
377      */
378     @GET
379     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{policyId}/versions/latest")
380     @ApiOperation(value = "Retrieve the latest version of a particular operational policy",
381             notes = "Returns the latest version of the specified operational policy",
382             response = LegacyOperationalPolicy.class,
383             responseHeaders = {
384                     @ResponseHeader(name = "X-MinorVersion",
385                                     description = "Used to request or communicate a MINOR version back from the client"
386                                                 + " to the server, and from the server back to the client",
387                                     response = String.class),
388                     @ResponseHeader(name = "X-PatchVersion",
389                                     description = "Used only to communicate a PATCH version in a response for"
390                                                 + " troubleshooting purposes only, and will not be provided by"
391                                                 + " the client on request",
392                                     response = String.class),
393                     @ResponseHeader(name = "X-LatestVersion",
394                                     description = "Used only to communicate an API's latest version",
395                                     response = String.class),
396                     @ResponseHeader(name = "X-ONAP-RequestID",
397                                     description = "Used to track REST transactions for logging purpose",
398                                     response = UUID.class)
399             },
400             authorizations = @Authorization(value = "basicAuth"),
401             tags = { "Legacy Operational Policy", },
402             extensions = {
403                     @Extension(name = "interface info", properties = {
404                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
405                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
406                     })
407             })
408     @ApiResponses(value = {
409             @ApiResponse(code = 401, message = "Authentication Error"),
410             @ApiResponse(code = 403, message = "Authorization Error"),
411             @ApiResponse(code = 404, message = "Resource Not Found"),
412             @ApiResponse(code = 500, message = "Internal Server Error")
413         })
414     public Response getLatestVersionOfOperationalPolicy(
415             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
416             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
417
418         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
419             LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, null);
420             return makeOkResponse(requestId, policy);
421         } catch (PfModelException | PfModelRuntimeException pfme) {
422             LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}"
423                 + "/versions/latest", policyId, pfme);
424             return makeErrorResponse(requestId, pfme);
425         }
426     }
427
428     /**
429      * Retrieves the specified version of a particular operational policy.
430      *
431      * @param policyId the ID of specified policy
432      * @param policyVersion the version of specified policy
433      *
434      * @return the Response object containing the results of the API operation
435      */
436     @GET
437     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
438          + "policies/{policyId}/versions/{policyVersion}")
439     @ApiOperation(value = "Retrieve one version of a particular operational policy",
440             notes = "Returns a particular version of a specified operational policy",
441             response = LegacyOperationalPolicy.class,
442             responseHeaders = {
443                     @ResponseHeader(name = "X-MinorVersion",
444                                     description = "Used to request or communicate a MINOR version back from the client"
445                                                 + " to the server, and from the server back to the client",
446                                     response = String.class),
447                     @ResponseHeader(name = "X-PatchVersion",
448                                     description = "Used only to communicate a PATCH version in a response for"
449                                                 + " troubleshooting purposes only, and will not be provided by"
450                                                 + " the client on request",
451                                     response = String.class),
452                     @ResponseHeader(name = "X-LatestVersion",
453                                     description = "Used only to communicate an API's latest version",
454                                     response = String.class),
455                     @ResponseHeader(name = "X-ONAP-RequestID",
456                                     description = "Used to track REST transactions for logging purpose",
457                                     response = UUID.class)
458             },
459             authorizations = @Authorization(value = "basicAuth"),
460             tags = { "Legacy Operational Policy", },
461             extensions = {
462                     @Extension(name = "interface info", properties = {
463                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
464                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
465                     })
466             })
467     @ApiResponses(value = {
468             @ApiResponse(code = 401, message = "Authentication Error"),
469             @ApiResponse(code = 403, message = "Authorization Error"),
470             @ApiResponse(code = 404, message = "Resource Not Found"),
471             @ApiResponse(code = 500, message = "Internal Server Error")
472         })
473     public Response getSpecificVersionOfOperationalPolicy(
474             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
475             @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
476             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
477
478         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
479             LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, policyVersion);
480             return makeOkResponse(requestId, policy);
481         } catch (PfModelException | PfModelRuntimeException pfme) {
482             LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
483                 + "policies/{}/versions/{}", policyId, policyVersion, pfme);
484             return makeErrorResponse(requestId, pfme);
485         }
486     }
487
488     /**
489      * Retrieves deployed versions of a particular operational policy in PDP groups.
490      *
491      * @param policyId the ID of specified policy
492      *
493      * @return the Response object containing the results of the API operation
494      */
495     @GET
496     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
497          + "policies/{policyId}/versions/deployed")
498     @ApiOperation(value = "Retrieve deployed versions of a particular operational policy in pdp groups",
499             notes = "Returns deployed versions of a specified operational policy in pdp groups",
500             response = LegacyOperationalPolicy.class, responseContainer = "List",
501             responseHeaders = {
502                     @ResponseHeader(name = "X-MinorVersion",
503                                     description = "Used to request or communicate a MINOR version back from the client"
504                                                 + " to the server, and from the server back to the client",
505                                     response = String.class),
506                     @ResponseHeader(name = "X-PatchVersion",
507                                     description = "Used only to communicate a PATCH version in a response for"
508                                                 + " troubleshooting purposes only, and will not be provided by"
509                                                 + " the client on request",
510                                     response = String.class),
511                     @ResponseHeader(name = "X-LatestVersion",
512                                     description = "Used only to communicate an API's latest version",
513                                     response = String.class),
514                     @ResponseHeader(name = "X-ONAP-RequestID",
515                                     description = "Used to track REST transactions for logging purpose",
516                                     response = UUID.class)
517             },
518             authorizations = @Authorization(value = "basicAuth"),
519             tags = { "Legacy Operational Policy", },
520             extensions = {
521                     @Extension(name = "interface info", properties = {
522                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
523                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
524                     })
525             })
526     @ApiResponses(value = {
527             @ApiResponse(code = 401, message = "Authentication Error"),
528             @ApiResponse(code = 403, message = "Authorization Error"),
529             @ApiResponse(code = 404, message = "Resource Not Found"),
530             @ApiResponse(code = 500, message = "Internal Server Error")
531         })
532     public Response getDeployedVersionsOfOperationalPolicy(
533             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
534             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
535
536         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
537             Map<Pair<String, String>, List<LegacyOperationalPolicy>> deployedOperationalPolicies =
538                     operationalPolicyProvider.fetchDeployedOperationalPolicies(policyId);
539             return makeOkResponse(requestId, deployedOperationalPolicies);
540         } catch (PfModelException | PfModelRuntimeException pfme) {
541             LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
542                 + "policies/{}/versions/deployed", policyId, pfme);
543             return makeErrorResponse(requestId, pfme);
544         }
545     }
546
547     /**
548      * Creates a new operational policy.
549      *
550      * @param body the body of policy
551      *
552      * @return the Response object containing the results of the API operation
553      */
554     @POST
555     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies")
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,
561             responseHeaders = {
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)
577             },
578             extensions = {
579                     @Extension(name = "interface info", properties = {
580                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
581                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
582                     })
583             })
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")
589         })
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) {
593
594         if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
595             NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
596                             "/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", toJson(body));
597         }
598
599         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
600             LegacyOperationalPolicy policy = operationalPolicyProvider.createOperationalPolicy(body);
601             return makeOkResponse(requestId, policy);
602         } catch (PfModelException | PfModelRuntimeException pfme) {
603             LOGGER.error("POST /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", pfme);
604             return makeErrorResponse(requestId, pfme);
605         }
606     }
607
608     /**
609      * Deletes the specified version of a particular operational policy.
610      *
611      * @param policyId the ID of specified policy
612      * @param policyVersion the version of specified policy
613      *
614      * @return the Response object containing the results of the API operation
615      */
616     @DELETE
617     @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
618          + "policies/{policyId}/versions/{policyVersion}")
619     @ApiOperation(value = "Delete a particular version of a specified operational policy",
620             notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
621             authorizations = @Authorization(value = "basicAuth"),
622             tags = { "Legacy Operational Policy", },
623             response = LegacyOperationalPolicy.class,
624             responseHeaders = {
625                     @ResponseHeader(name = "X-MinorVersion",
626                                     description = "Used to request or communicate a MINOR version back from the client"
627                                                 + " to the server, and from the server back to the client",
628                                     response = String.class),
629                     @ResponseHeader(name = "X-PatchVersion",
630                                     description = "Used only to communicate a PATCH version in a response for"
631                                                 + " troubleshooting purposes only, and will not be provided by"
632                                                 + " the client on request",
633                                     response = String.class),
634                     @ResponseHeader(name = "X-LatestVersion",
635                                     description = "Used only to communicate an API's latest version",
636                                     response = String.class),
637                     @ResponseHeader(name = "X-ONAP-RequestID",
638                                     description = "Used to track REST transactions for logging purpose",
639                                     response = UUID.class)
640             },
641             extensions = {
642                     @Extension(name = "interface info", properties = {
643                             @ExtensionProperty(name = "api-version", value = "1.0.0"),
644                             @ExtensionProperty(name = "last-mod-release", value = "Dublin")
645                     })
646             })
647     @ApiResponses(value = {
648             @ApiResponse(code = 401, message = "Authentication Error"),
649             @ApiResponse(code = 403, message = "Authorization Error"),
650             @ApiResponse(code = 404, message = "Resource Not Found"),
651             @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
652             @ApiResponse(code = 500, message = "Internal Server Error")
653         })
654     public Response deleteSpecificVersionOfOperationalPolicy(
655             @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
656             @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
657             @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
658
659         try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
660             LegacyOperationalPolicy policy = operationalPolicyProvider
661                     .deleteOperationalPolicy(policyId, policyVersion);
662             return makeOkResponse(requestId, policy);
663         } catch (PfModelException | PfModelRuntimeException pfme) {
664             LOGGER.error("DELETE /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
665                 + "policies/{}/versions/{}", policyId, policyVersion, pfme);
666             return makeErrorResponse(requestId, pfme);
667         }
668     }
669 }