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.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", response = String.class),
250 @ResponseHeader(name = "X-ONAP-RequestID",
251 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
252 extensions = {@Extension(name = "interface info",
253 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
254 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
255 @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
256 @ApiResponse(code = 401, message = "Authentication Error"),
257 @ApiResponse(code = 403, message = "Authorization Error"),
258 @ApiResponse(code = 500, message = "Internal Server Error")})
259 public Response createGuardPolicy(
260 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
261 @ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicyInput body) {
263 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
264 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
265 "/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", toJson(body));
268 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
269 Map<String, LegacyGuardPolicyOutput> policy = guardPolicyProvider.createGuardPolicy(body);
270 return makeOkResponse(requestId, policy);
271 } catch (PfModelException | PfModelRuntimeException pfme) {
272 LOGGER.debug("POST /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", pfme);
273 return makeErrorResponse(requestId, pfme);
278 * Deletes the specified version of a particular guard policy.
280 * @param policyId the ID of specified policy
281 * @param policyVersion the version of specified policy
283 * @return the Response object containing the results of the API operation
286 @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/{policyVersion}")
287 @ApiOperation(value = "Delete a particular version of a guard policy",
288 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
289 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Guard Policy",},
290 response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
292 @ResponseHeader(name = "X-MinorVersion",
293 description = "Used to request or communicate a MINOR version back from the client"
294 + " to the server, and from the server back to the client",
295 response = String.class),
296 @ResponseHeader(name = "X-PatchVersion",
297 description = "Used only to communicate a PATCH version in a response for"
298 + " troubleshooting purposes only, and will not be provided by"
299 + " the client on request",
300 response = String.class),
301 @ResponseHeader(name = "X-LatestVersion",
302 description = "Used only to communicate an API's latest version", response = String.class),
303 @ResponseHeader(name = "X-ONAP-RequestID",
304 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
305 extensions = {@Extension(name = "interface info",
306 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
307 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
308 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
309 @ApiResponse(code = 403, message = "Authorization Error"),
310 @ApiResponse(code = 404, message = "Resource Not Found"),
311 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
312 @ApiResponse(code = 500, message = "Internal Server Error")})
313 public Response deleteSpecificVersionOfGuardPolicy(
314 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
315 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
316 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
318 try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
319 Map<String, LegacyGuardPolicyOutput> policies =
320 guardPolicyProvider.deleteGuardPolicy(policyId, policyVersion);
321 return makeOkResponse(requestId, policies);
322 } catch (PfModelException | PfModelRuntimeException pfme) {
323 LOGGER.debug("DELETE /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}/versions/{}",
324 policyId, policyVersion, pfme);
325 return makeErrorResponse(requestId, pfme);
330 * Retrieves the latest version of a particular operational policy.
332 * @param policyId the ID of specified operational policy
334 * @return the Response object containing the results of the API operation
337 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{policyId}/versions/latest")
338 @ApiOperation(value = "Retrieve the latest version of a particular operational policy",
339 notes = "Returns the latest version of the specified operational policy",
340 response = LegacyOperationalPolicy.class,
342 @ResponseHeader(name = "X-MinorVersion",
343 description = "Used to request or communicate a MINOR version back from the client"
344 + " to the server, and from the server back to the client",
345 response = String.class),
346 @ResponseHeader(name = "X-PatchVersion",
347 description = "Used only to communicate a PATCH version in a response for"
348 + " troubleshooting purposes only, and will not be provided by"
349 + " the client on request",
350 response = String.class),
351 @ResponseHeader(name = "X-LatestVersion",
352 description = "Used only to communicate an API's latest version", response = String.class),
353 @ResponseHeader(name = "X-ONAP-RequestID",
354 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
355 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
356 extensions = {@Extension(name = "interface info",
357 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
358 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
359 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
360 @ApiResponse(code = 403, message = "Authorization Error"),
361 @ApiResponse(code = 404, message = "Resource Not Found"),
362 @ApiResponse(code = 500, message = "Internal Server Error")})
363 public Response getLatestVersionOfOperationalPolicy(
364 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
365 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
367 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
368 LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, null);
369 return makeOkResponse(requestId, policy);
370 } catch (PfModelException | PfModelRuntimeException pfme) {
371 LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}"
372 + "/versions/latest", policyId, pfme);
373 return makeErrorResponse(requestId, pfme);
378 * Retrieves the specified version of a particular operational policy.
380 * @param policyId the ID of specified policy
381 * @param policyVersion the version of specified policy
383 * @return the Response object containing the results of the API operation
386 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
387 + "policies/{policyId}/versions/{policyVersion}")
388 @ApiOperation(value = "Retrieve one version of a particular operational policy",
389 notes = "Returns a particular version of a specified operational policy",
390 response = LegacyOperationalPolicy.class,
392 @ResponseHeader(name = "X-MinorVersion",
393 description = "Used to request or communicate a MINOR version back from the client"
394 + " to the server, and from the server back to the client",
395 response = String.class),
396 @ResponseHeader(name = "X-PatchVersion",
397 description = "Used only to communicate a PATCH version in a response for"
398 + " troubleshooting purposes only, and will not be provided by"
399 + " the client on request",
400 response = String.class),
401 @ResponseHeader(name = "X-LatestVersion",
402 description = "Used only to communicate an API's latest version", response = String.class),
403 @ResponseHeader(name = "X-ONAP-RequestID",
404 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
405 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
406 extensions = {@Extension(name = "interface info",
407 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
408 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
409 @ApiResponses(value = {@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 public Response getSpecificVersionOfOperationalPolicy(
414 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
415 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
416 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
418 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
419 LegacyOperationalPolicy policy = operationalPolicyProvider.fetchOperationalPolicy(policyId, policyVersion);
420 return makeOkResponse(requestId, policy);
421 } catch (PfModelException | PfModelRuntimeException pfme) {
422 LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
423 + "policies/{}/versions/{}", policyId, policyVersion, pfme);
424 return makeErrorResponse(requestId, pfme);
429 * Retrieves deployed versions of a particular operational policy in PDP groups.
431 * @param policyId the ID of specified policy
433 * @return the Response object containing the results of the API operation
436 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
437 + "policies/{policyId}/versions/deployed")
438 @ApiOperation(value = "Retrieve deployed versions of a particular operational policy in pdp groups",
439 notes = "Returns deployed versions of a specified operational policy in pdp groups",
440 response = LegacyOperationalPolicy.class, responseContainer = "List",
442 @ResponseHeader(name = "X-MinorVersion",
443 description = "Used to request or communicate a MINOR version back from the client"
444 + " to the server, and from the server back to the client",
445 response = String.class),
446 @ResponseHeader(name = "X-PatchVersion",
447 description = "Used only to communicate a PATCH version in a response for"
448 + " troubleshooting purposes only, and will not be provided by"
449 + " the client on request",
450 response = String.class),
451 @ResponseHeader(name = "X-LatestVersion",
452 description = "Used only to communicate an API's latest version", response = String.class),
453 @ResponseHeader(name = "X-ONAP-RequestID",
454 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
455 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
456 extensions = {@Extension(name = "interface info",
457 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
458 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
459 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
460 @ApiResponse(code = 403, message = "Authorization Error"),
461 @ApiResponse(code = 404, message = "Resource Not Found"),
462 @ApiResponse(code = 500, message = "Internal Server Error")})
463 public Response getDeployedVersionsOfOperationalPolicy(
464 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
465 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
467 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
468 Map<Pair<String, String>, List<LegacyOperationalPolicy>> deployedOperationalPolicies =
469 operationalPolicyProvider.fetchDeployedOperationalPolicies(policyId);
470 return makeOkResponse(requestId, deployedOperationalPolicies);
471 } catch (PfModelException | PfModelRuntimeException pfme) {
472 LOGGER.debug("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
473 + "policies/{}/versions/deployed", policyId, pfme);
474 return makeErrorResponse(requestId, pfme);
479 * Creates a new operational policy.
481 * @param body the body of policy
483 * @return the Response object containing the results of the API operation
486 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies")
487 @ApiOperation(value = "Create a new operational policy",
488 notes = "Client should provide entity body of the new operational policy",
489 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
490 response = LegacyOperationalPolicy.class,
492 @ResponseHeader(name = "X-MinorVersion",
493 description = "Used to request or communicate a MINOR version back from the client"
494 + " to the server, and from the server back to the client",
495 response = String.class),
496 @ResponseHeader(name = "X-PatchVersion",
497 description = "Used only to communicate a PATCH version in a response for"
498 + " troubleshooting purposes only, and will not be provided by"
499 + " the client on request",
500 response = String.class),
501 @ResponseHeader(name = "X-LatestVersion",
502 description = "Used only to communicate an API's latest version", response = String.class),
503 @ResponseHeader(name = "X-ONAP-RequestID",
504 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
505 extensions = {@Extension(name = "interface info",
506 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
507 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
508 @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Body"),
509 @ApiResponse(code = 401, message = "Authentication Error"),
510 @ApiResponse(code = 403, message = "Authorization Error"),
511 @ApiResponse(code = 500, message = "Internal Server Error")})
512 public Response createOperationalPolicy(
513 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
514 @ApiParam(value = "Entity body of policy", required = true) LegacyOperationalPolicy body) {
516 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
517 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
518 "/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", toJson(body));
521 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
522 LegacyOperationalPolicy policy = operationalPolicyProvider.createOperationalPolicy(body);
523 return makeOkResponse(requestId, policy);
524 } catch (PfModelException | PfModelRuntimeException pfme) {
525 LOGGER.debug("POST /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", pfme);
526 return makeErrorResponse(requestId, pfme);
531 * Deletes the specified version of a particular operational policy.
533 * @param policyId the ID of specified policy
534 * @param policyVersion the version of specified policy
536 * @return the Response object containing the results of the API operation
539 @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
540 + "policies/{policyId}/versions/{policyVersion}")
541 @ApiOperation(value = "Delete a particular version of a specified operational policy",
542 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
543 authorizations = @Authorization(value = "basicAuth"), tags = {"Legacy Operational Policy",},
544 response = LegacyOperationalPolicy.class,
546 @ResponseHeader(name = "X-MinorVersion",
547 description = "Used to request or communicate a MINOR version back from the client"
548 + " to the server, and from the server back to the client",
549 response = String.class),
550 @ResponseHeader(name = "X-PatchVersion",
551 description = "Used only to communicate a PATCH version in a response for"
552 + " troubleshooting purposes only, and will not be provided by"
553 + " the client on request",
554 response = String.class),
555 @ResponseHeader(name = "X-LatestVersion",
556 description = "Used only to communicate an API's latest version", response = String.class),
557 @ResponseHeader(name = "X-ONAP-RequestID",
558 description = "Used to track REST transactions for logging purpose", response = UUID.class)},
559 extensions = {@Extension(name = "interface info",
560 properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),
561 @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})
562 @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),
563 @ApiResponse(code = 403, message = "Authorization Error"),
564 @ApiResponse(code = 404, message = "Resource Not Found"),
565 @ApiResponse(code = 409, message = "Delete Conflict, Rule Violation"),
566 @ApiResponse(code = 500, message = "Internal Server Error")})
567 public Response deleteSpecificVersionOfOperationalPolicy(
568 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
569 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
570 @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
572 try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
573 LegacyOperationalPolicy policy = operationalPolicyProvider.deleteOperationalPolicy(policyId, policyVersion);
574 return makeOkResponse(requestId, policy);
575 } catch (PfModelException | PfModelRuntimeException pfme) {
576 LOGGER.debug("DELETE /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
577 + "policies/{}/versions/{}", policyId, policyVersion, pfme);
578 return makeErrorResponse(requestId, pfme);