2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 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.List;
37 import java.util.UUID;
39 import javax.ws.rs.Consumes;
40 import javax.ws.rs.DELETE;
41 import javax.ws.rs.GET;
42 import javax.ws.rs.HeaderParam;
43 import javax.ws.rs.POST;
44 import javax.ws.rs.Path;
45 import javax.ws.rs.PathParam;
46 import javax.ws.rs.Produces;
47 import javax.ws.rs.core.Response;
49 import org.apache.commons.lang3.tuple.Pair;
50 import org.onap.policy.api.main.rest.provider.LegacyGuardPolicyProvider;
51 import org.onap.policy.api.main.rest.provider.LegacyOperationalPolicyProvider;
52 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
53 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
54 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
55 import org.onap.policy.models.base.PfModelException;
56 import org.onap.policy.models.base.PfModelRuntimeException;
57 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
58 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
59 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
64 * Class to provide legacy REST API services.
66 * @author Chenfei Gao (cgao@research.att.com)
68 @Path("/policy/api/v1")
69 @Api(value = "Legacy Policy Design API")
70 @Produces({"application/json", "application/yaml"})
71 @Consumes({"application/json", "application/yaml"})
72 public class LegacyApiRestController extends CommonRestController {
74 private static final Logger LOGGER = LoggerFactory.getLogger(LegacyApiRestController.class);
77 * Retrieves the latest version of a particular guard policy.
79 * @param policyId the ID of specified guard policy
81 * @return the Response object containing the results of the API operation
84 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/latest")
85 @ApiOperation(value = "Retrieve the latest version of a particular guard policy",
86 notes = "Returns the latest version of the specified guard policy",
87 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
89 @ResponseHeader(name = "X-MinorVersion",
90 description = "Used to request or communicate a MINOR version back from the client"
91 + " to the server, and from the server back to the client",
92 response = String.class),
93 @ResponseHeader(name = "X-PatchVersion",
94 description = "Used only to communicate a PATCH version in a response for"
95 + " troubleshooting purposes only, and will not be provided by"
96 + " the client on request",
97 response = String.class),
98 @ResponseHeader(name = "X-LatestVersion",
99 description = "Used only to communicate an API's latest version", response = String.class),
100 @ResponseHeader(name = "X-ONAP-RequestID",
101 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
102 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Guard Policy",},
103 extensions = {@Extension(name = "interface info",
104 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
105 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
106 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
107 @ApiResponse(code = 403, message = "Authorization Error"),
108 @ApiResponse(code = 404, message = "Resource Not Found"),
109 @ApiResponse(code = 500, message = "Internal Server Error")})
110 public Response getLatestVersionOfGuardPolicy(
111 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
112 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
114 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
115 Map<String, LegacyGuardPolicyOutput> policies = guardPolicyProvider.fetchGuardPolicy(policyId, null);
116 return makeOkResponse(requestId, policies);
117 } catch (PfModelException | PfModelRuntimeException pfme) {
119 "GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}" + "/versions/latest",
121 return makeErrorResponse(requestId, pfme);
126 * Retrieves the specified version of a particular guard policy.
128 * @param policyId the ID of specified policy
129 * @param policyVersion the version of specified policy
131 * @return the Response object containing the results of the API operation
134 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
135 @ApiOperation(value = "Retrieve one version of a particular guard policy",
136 notes = "Returns a particular version of a specified guard policy",
137 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
139 @ResponseHeader(name = "X-MinorVersion",
140 description = "Used to request or communicate a MINOR version back from the client"
141 + " to the server, and from the server back to the client",
142 response = String.class),
143 @ResponseHeader(name = "X-PatchVersion",
144 description = "Used only to communicate a PATCH version in a response for"
145 + " troubleshooting purposes only, and will not be provided by"
146 + " the client on request",
147 response = String.class),
148 @ResponseHeader(name = "X-LatestVersion",
149 description = "Used only to communicate an API's latest version", response = String.class),
150 @ResponseHeader(name = "X-ONAP-RequestID",
151 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
152 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Guard Policy",},
153 extensions = {@Extension(name = "interface info",
154 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
155 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
156 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
157 @ApiResponse(code = 403, message = "Authorization Error"),
158 @ApiResponse(code = 404, message = "Resource Not Found"),
159 @ApiResponse(code = 500, message = "Internal Server Error")})
160 public Response getSpecificVersionOfGuardPolicy(
161 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
162 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
163 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
165 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
166 Map<String, LegacyGuardPolicyOutput> policies =
167 guardPolicyProvider.fetchGuardPolicy(policyId, policyVersion);
168 return makeOkResponse(requestId, policies);
169 } catch (PfModelException | PfModelRuntimeException pfme) {
170 LOGGER.debug("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
171 policyId, policyVersion, pfme);
172 return makeErrorResponse(requestId, pfme);
177 * Retrieves deployed versions of a particular guard policy in PDP groups.
179 * @param policyId the ID of specified policy
181 * @return the Response object containing the results of the API operation
184 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/" + "policies/{policyId}/versions/deployed")
185 @ApiOperation(value = "Retrieve deployed versions of a particular guard policy in pdp groups",
186 notes = "Returns deployed versions of a specified guard policy in pdp groups",
187 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
189 @ResponseHeader(name = "X-MinorVersion",
190 description = "Used to request or communicate a MINOR version back from the client"
191 + " to the server, and from the server back to the client",
192 response = String.class),
193 @ResponseHeader(name = "X-PatchVersion",
194 description = "Used only to communicate a PATCH version in a response for"
195 + " troubleshooting purposes only, and will not be provided by"
196 + " the client on request",
197 response = String.class),
198 @ResponseHeader(name = "X-LatestVersion",
199 description = "Used only to communicate an API's latest version", response = String.class),
200 @ResponseHeader(name = "X-ONAP-RequestID",
201 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
202 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Guard Policy",},
203 extensions = {@Extension(name = "interface info",
204 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
205 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
206 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
207 @ApiResponse(code = 403, message = "Authorization Error"),
208 @ApiResponse(code = 404, message = "Resource Not Found"),
209 @ApiResponse(code = 500, message = "Internal Server Error")})
210 public Response getDeployedVersionsOfGuardPolicy(
211 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
212 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
214 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
215 Map<Pair<String, String>, Map<String, LegacyGuardPolicyOutput>> deployedGuardPolicies =
216 guardPolicyProvider.fetchDeployedGuardPolicies(policyId);
217 return makeOkResponse(requestId, deployedGuardPolicies);
218 } catch (PfModelException | PfModelRuntimeException pfme) {
219 LOGGER.debug("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/"
220 + "policies/{}/versions/deployed", policyId, pfme);
221 return makeErrorResponse(requestId, pfme);
226 * Creates a new guard policy.
228 * @param body the body of policy
230 * @return the Response object containing the results of the API operation
233 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies")
234 @ApiOperation(value = "Create a new guard policy",
235 notes = "Client should provide entity body of the new guard policy",
236 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Guard Policy",},
237 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
239 @ResponseHeader(name = "X-MinorVersion",
240 description = "Used to request or communicate a MINOR version back from the client"
241 + " to the server, and from the server back to the client",
242 response = String.class),
243 @ResponseHeader(name = "X-PatchVersion",
244 description = "Used only to communicate a PATCH version in a response for"
245 + " troubleshooting purposes only, and will not be provided by"
246 + " the client on request",
247 response = String.class),
248 @ResponseHeader(name = "X-LatestVersion",
249 description = "Used only to communicate an API's latest version",
250 response = String.class),
251 @ResponseHeader(name = "X-ONAP-RequestID",
252 description = "Used to track REST transactions for logging purpose",
253 response = UUID.class)
256 @Extension(name = "interface info", properties = {
257 @ExtensionProperty(name = "api-version", value = "1.0.0"),
258 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
261 @ApiResponses(value = {
262 @ApiResponse(code = 400, message = "Invalid Body"),
263 @ApiResponse(code = 401, message = "Authentication Error"),
264 @ApiResponse(code = 403, message = "Authorization Error"),
265 @ApiResponse(code = 406, message = "Not Acceptable Payload"),
266 @ApiResponse(code = 500, message = "Internal Server Error")
268 public Response createGuardPolicy(
269 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
270 @ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicyInput body) {
272 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
273 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
274 "/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", toJson(body));
277 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
278 Map<String, LegacyGuardPolicyOutput> policy = guardPolicyProvider.createGuardPolicy(body);
279 return makeOkResponse(requestId, policy);
280 } catch (PfModelException | PfModelRuntimeException pfme) {
281 LOGGER.debug("POST /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", pfme);
282 return makeErrorResponse(requestId, pfme);
287 * Deletes the specified version of a particular guard policy.
289 * @param policyId the ID of specified policy
290 * @param policyVersion the version of specified policy
292 * @return the Response object containing the results of the API operation
295 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
296 @ApiOperation(value = "Delete a particular version of a guard policy",
297 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
298 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Guard Policy",},
299 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
301 @ResponseHeader(name = "X-MinorVersion",
302 description = "Used to request or communicate a MINOR version back from the client"
303 + " to the server, and from the server back to the client",
304 response = String.class),
305 @ResponseHeader(name = "X-PatchVersion",
306 description = "Used only to communicate a PATCH version in a response for"
307 + " troubleshooting purposes only, and will not be provided by"
308 + " the client on request",
309 response = String.class),
310 @ResponseHeader(name = "X-LatestVersion",
311 description = "Used only to communicate an API's latest version", response = String.class),
312 @ResponseHeader(name = "X-ONAP-RequestID",
313 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
314 extensions = {@Extension(name = "interface info",
315 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
316 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
317 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
318 @ApiResponse(code = 403, message = "Authorization Error"),
319 @ApiResponse(code = 404, message = "Resource Not Found"),
320 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
321 @ApiResponse(code = 500, message = "Internal Server Error")})
322 public Response deleteSpecificVersionOfGuardPolicy(
323 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
324 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
325 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
327 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
328 Map<String, LegacyGuardPolicyOutput> policies =
329 guardPolicyProvider.deleteGuardPolicy(policyId, policyVersion);
330 return makeOkResponse(requestId, policies);
331 } catch (PfModelException | PfModelRuntimeException pfme) {
332 LOGGER.debug("DELETE /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
333 policyId, policyVersion, pfme);
334 return makeErrorResponse(requestId, pfme);
339 * Retrieves the latest version of a particular operational policy.
341 * @param policyId the ID of specified operational policy
343 * @return the Response object containing the results of the API operation
346 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{policyId}/versions/latest")
347 @ApiOperation(value = "Retrieve the latest version of a particular operational policy",
348 notes = "Returns the latest version of the specified operational policy",
349 response = LegacyOperationalPolicy.class,
351 @ResponseHeader(name = "X-MinorVersion",
352 description = "Used to request or communicate a MINOR version back from the client"
353 + " to the server, and from the server back to the client",
354 response = String.class),
355 @ResponseHeader(name = "X-PatchVersion",
356 description = "Used only to communicate a PATCH version in a response for"
357 + " troubleshooting purposes only, and will not be provided by"
358 + " the client on request",
359 response = String.class),
360 @ResponseHeader(name = "X-LatestVersion",
361 description = "Used only to communicate an API's latest version", response = String.class),
362 @ResponseHeader(name = "X-ONAP-RequestID",
363 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
364 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
365 extensions = {@Extension(name = "interface info",
366 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
367 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
368 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
369 @ApiResponse(code = 403, message = "Authorization Error"),
370 @ApiResponse(code = 404, message = "Resource Not Found"),
371 @ApiResponse(code = 500, message = "Internal Server Error")})
372 public Response getLatestVersionOfOperationalPolicy(
373 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
374 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
376 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
377 LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, null);
378 return makeOkResponse(requestId, policy);
379 } catch (PfModelException | PfModelRuntimeException pfme) {
380 LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}"
381 + "/versions/latest", policyId, pfme);
382 return makeErrorResponse(requestId, pfme);
387 * Retrieves the specified version of a particular operational policy.
389 * @param policyId the ID of specified policy
390 * @param policyVersion the version of specified policy
392 * @return the Response object containing the results of the API operation
395 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
396 + "policies/{policyId}/versions/{policyVersion}")
397 @ApiOperation(value = "Retrieve one version of a particular operational policy",
398 notes = "Returns a particular version of a specified operational policy",
399 response = LegacyOperationalPolicy.class,
401 @ResponseHeader(name = "X-MinorVersion",
402 description = "Used to request or communicate a MINOR version back from the client"
403 + " to the server, and from the server back to the client",
404 response = String.class),
405 @ResponseHeader(name = "X-PatchVersion",
406 description = "Used only to communicate a PATCH version in a response for"
407 + " troubleshooting purposes only, and will not be provided by"
408 + " the client on request",
409 response = String.class),
410 @ResponseHeader(name = "X-LatestVersion",
411 description = "Used only to communicate an API's latest version", response = String.class),
412 @ResponseHeader(name = "X-ONAP-RequestID",
413 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
414 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
415 extensions = {@Extension(name = "interface info",
416 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
417 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
418 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
419 @ApiResponse(code = 403, message = "Authorization Error"),
420 @ApiResponse(code = 404, message = "Resource Not Found"),
421 @ApiResponse(code = 500, message = "Internal Server Error")})
422 public Response getSpecificVersionOfOperationalPolicy(
423 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
424 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
425 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
427 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
428 LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, policyVersion);
429 return makeOkResponse(requestId, policy);
430 } catch (PfModelException | PfModelRuntimeException pfme) {
431 LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
432 + "policies/{}/versions/{}", policyId, policyVersion, pfme);
433 return makeErrorResponse(requestId, pfme);
438 * Retrieves deployed versions of a particular operational policy in PDP groups.
440 * @param policyId the ID of specified policy
442 * @return the Response object containing the results of the API operation
445 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
446 + "policies/{policyId}/versions/deployed")
447 @ApiOperation(value = "Retrieve deployed versions of a particular operational policy in pdp groups",
448 notes = "Returns deployed versions of a specified operational policy in pdp groups",
449 response = LegacyOperationalPolicy.class, responseContainer = "List",
451 @ResponseHeader(name = "X-MinorVersion",
452 description = "Used to request or communicate a MINOR version back from the client"
453 + " to the server, and from the server back to the client",
454 response = String.class),
455 @ResponseHeader(name = "X-PatchVersion",
456 description = "Used only to communicate a PATCH version in a response for"
457 + " troubleshooting purposes only, and will not be provided by"
458 + " the client on request",
459 response = String.class),
460 @ResponseHeader(name = "X-LatestVersion",
461 description = "Used only to communicate an API's latest version", response = String.class),
462 @ResponseHeader(name = "X-ONAP-RequestID",
463 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
464 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
465 extensions = {@Extension(name = "interface info",
466 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
467 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
468 @ApiResponses(value = {@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 public Response getDeployedVersionsOfOperationalPolicy(
473 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
474 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
476 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
477 Map<Pair<String, String>, List<LegacyOperationalPolicy>> deployedOperationalPolicies =
478 operationalPolicyProvider.fetchDeployedOperationalPolicies(policyId);
479 return makeOkResponse(requestId, deployedOperationalPolicies);
480 } catch (PfModelException | PfModelRuntimeException pfme) {
481 LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
482 + "policies/{}/versions/deployed", policyId, pfme);
483 return makeErrorResponse(requestId, pfme);
488 * Creates a new operational policy.
490 * @param body the body of policy
492 * @return the Response object containing the results of the API operation
495 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies")
496 @ApiOperation(value = "Create a new operational policy",
497 notes = "Client should provide entity body of the new operational policy",
498 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
499 response = LegacyOperationalPolicy.class,
501 @ResponseHeader(name = "X-MinorVersion",
502 description = "Used to request or communicate a MINOR version back from the client"
503 + " to the server, and from the server back to the client",
504 response = String.class),
505 @ResponseHeader(name = "X-PatchVersion",
506 description = "Used only to communicate a PATCH version in a response for"
507 + " troubleshooting purposes only, and will not be provided by"
508 + " the client on request",
509 response = String.class),
510 @ResponseHeader(name = "X-LatestVersion",
511 description = "Used only to communicate an API's latest version",
512 response = String.class),
513 @ResponseHeader(name = "X-ONAP-RequestID",
514 description = "Used to track REST transactions for logging purpose",
515 response = UUID.class)
518 @Extension(name = "interface info", properties = {
519 @ExtensionProperty(name = "api-version", value = "1.0.0"),
520 @ExtensionProperty(name = "last-mod-release", value = "Dublin")
523 @ApiResponses(value = {
524 @ApiResponse(code = 400, message = "Invalid Body"),
525 @ApiResponse(code = 401, message = "Authentication Error"),
526 @ApiResponse(code = 403, message = "Authorization Error"),
527 @ApiResponse(code = 406, message = "Not Acceptable Payload"),
528 @ApiResponse(code = 500, message = "Internal Server Error")
530 public Response createOperationalPolicy(
531 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
532 @ApiParam(value = "Entity body of policy", required = true) LegacyOperationalPolicy body) {
534 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
535 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
536 "/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", toJson(body));
539 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
540 LegacyOperationalPolicy policy = operationalPolicyProvider.createOperationalPolicy(body);
541 return makeOkResponse(requestId, policy);
542 } catch (PfModelException | PfModelRuntimeException pfme) {
543 LOGGER.debug("POST /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", pfme);
544 return makeErrorResponse(requestId, pfme);
549 * Deletes the specified version of a particular operational policy.
551 * @param policyId the ID of specified policy
552 * @param policyVersion the version of specified policy
554 * @return the Response object containing the results of the API operation
557 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
558 + "policies/{policyId}/versions/{policyVersion}")
559 @ApiOperation(value = "Delete a particular version of a specified operational policy",
560 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
561 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
562 response = LegacyOperationalPolicy.class,
564 @ResponseHeader(name = "X-MinorVersion",
565 description = "Used to request or communicate a MINOR version back from the client"
566 + " to the server, and from the server back to the client",
567 response = String.class),
568 @ResponseHeader(name = "X-PatchVersion",
569 description = "Used only to communicate a PATCH version in a response for"
570 + " troubleshooting purposes only, and will not be provided by"
571 + " the client on request",
572 response = String.class),
573 @ResponseHeader(name = "X-LatestVersion",
574 description = "Used only to communicate an API's latest version", response = String.class),
575 @ResponseHeader(name = "X-ONAP-RequestID",
576 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
577 extensions = {@Extension(name = "interface info",
578 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
579 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
580 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
581 @ApiResponse(code = 403, message = "Authorization Error"),
582 @ApiResponse(code = 404, message = "Resource Not Found"),
583 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
584 @ApiResponse(code = 500, message = "Internal Server Error")})
585 public Response deleteSpecificVersionOfOperationalPolicy(
586 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
587 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
588 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
590 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
591 LegacyOperationalPolicy policy = operationalPolicyProvider.deleteOperationalPolicy(policyId, policyVersion);
592 return makeOkResponse(requestId, policy);
593 } catch (PfModelException | PfModelRuntimeException pfme) {
594 LOGGER.debug("DELETE /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
595 + "policies/{}/versions/{}", policyId, policyVersion, pfme);
596 return makeErrorResponse(requestId, pfme);