2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
\r
6 * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
\r
7 * Modifications Copyright (C) 2020,2022 Nordix Foundation.
\r
8 * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
\r
9 * ================================================================================
\r
10 * Licensed under the Apache License, Version 2.0 (the "License");
\r
11 * you may not use this file except in compliance with the License.
\r
12 * You may obtain a copy of the License at
\r
14 * http://www.apache.org/licenses/LICENSE-2.0
\r
16 * Unless required by applicable law or agreed to in writing, software
\r
17 * distributed under the License is distributed on an "AS IS" BASIS,
\r
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
19 * See the License for the specific language governing permissions and
\r
20 * limitations under the License.
\r
22 * SPDX-License-Identifier: Apache-2.0
\r
23 * ============LICENSE_END=========================================================
\r
26 package org.onap.policy.api.main.rest;
\r
28 import io.swagger.annotations.Api;
\r
29 import io.swagger.annotations.ApiOperation;
\r
30 import io.swagger.annotations.ApiParam;
\r
31 import io.swagger.annotations.ApiResponse;
\r
32 import io.swagger.annotations.ApiResponses;
\r
33 import io.swagger.annotations.Authorization;
\r
34 import io.swagger.annotations.BasicAuthDefinition;
\r
35 import io.swagger.annotations.Extension;
\r
36 import io.swagger.annotations.ExtensionProperty;
\r
37 import io.swagger.annotations.Info;
\r
38 import io.swagger.annotations.ResponseHeader;
\r
39 import io.swagger.annotations.SecurityDefinition;
\r
40 import io.swagger.annotations.SwaggerDefinition;
\r
41 import java.net.HttpURLConnection;
\r
42 import java.util.List;
\r
43 import java.util.UUID;
\r
44 import javax.ws.rs.core.Response.Status;
\r
45 import lombok.RequiredArgsConstructor;
\r
46 import org.onap.policy.api.main.exception.PolicyApiRuntimeException;
\r
47 import org.onap.policy.api.main.rest.provider.healthcheck.HealthCheckProvider;
\r
48 import org.onap.policy.api.main.rest.provider.statistics.ApiStatisticsManager;
\r
49 import org.onap.policy.api.main.rest.provider.statistics.StatisticsProvider;
\r
50 import org.onap.policy.api.main.rest.provider.statistics.StatisticsReport;
\r
51 import org.onap.policy.api.main.service.ToscaServiceTemplateService;
\r
52 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
\r
53 import org.onap.policy.common.endpoints.report.HealthCheckReport;
\r
54 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
\r
55 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
\r
56 import org.onap.policy.models.base.PfModelException;
\r
57 import org.onap.policy.models.base.PfModelRuntimeException;
\r
58 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
59 import org.springframework.http.HttpMethod;
\r
60 import org.springframework.http.HttpStatus;
\r
61 import org.springframework.http.ResponseEntity;
\r
62 import org.springframework.web.bind.annotation.DeleteMapping;
\r
63 import org.springframework.web.bind.annotation.GetMapping;
\r
64 import org.springframework.web.bind.annotation.PathVariable;
\r
65 import org.springframework.web.bind.annotation.PostMapping;
\r
66 import org.springframework.web.bind.annotation.RequestBody;
\r
67 import org.springframework.web.bind.annotation.RequestHeader;
\r
68 import org.springframework.web.bind.annotation.RequestMapping;
\r
69 import org.springframework.web.bind.annotation.RequestParam;
\r
70 import org.springframework.web.bind.annotation.RestController;
\r
73 * Class to provide REST API services.
\r
75 * @author Chenfei Gao (cgao@research.att.com)
\r
78 @RequestMapping(path = "/policy/api/v1", produces = { "application/json", "application/yaml" })
\r
79 @Api(value = "Policy Design API")
\r
82 description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
\r
83 + " policy types, policy type implementation and policies which can be recognized"
\r
84 + " and executable by incorporated policy engines. It is an"
\r
85 + " independent component running rest service that takes all policy design API calls"
\r
86 + " from clients and then assign them to different API working functions. Besides"
\r
87 + " that, API is also exposed for clients to retrieve healthcheck status of this API"
\r
88 + " rest service and the statistics report including the counters of API invocation.",
\r
89 version = "1.0.0", title = "Policy Design",
\r
90 extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
\r
91 @ExtensionProperty(name = "component", value = "Policy Framework")})}),
\r
92 schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
\r
93 securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
\r
94 @RequiredArgsConstructor
\r
95 public class ApiRestController extends CommonRestController {
\r
97 private enum Target {
\r
103 private final ToscaServiceTemplateService toscaServiceTemplateService;
\r
104 private final HealthCheckProvider healthCheckProvider;
\r
105 private final ApiStatisticsManager mgr;
\r
106 private final StatisticsProvider statisticsProvider;
\r
109 * Retrieves the healthcheck status of the API component.
\r
111 * @return the Response object containing the results of the API operation
\r
113 @GetMapping("/healthcheck")
\r
114 @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",
\r
115 response = HealthCheckReport.class,
\r
116 responseHeaders = {
\r
117 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
118 description = VERSION_MINOR_DESCRIPTION,
\r
119 response = String.class),
\r
120 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
121 description = VERSION_PATCH_DESCRIPTION,
\r
122 response = String.class),
\r
123 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
124 response = String.class),
\r
125 @ResponseHeader(name = REQUEST_ID_NAME,
\r
126 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
127 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"HealthCheck", },
\r
129 @Extension(name = EXTENSION_NAME, properties = {
\r
130 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
131 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
132 @ApiResponses(value = {
\r
133 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
134 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
135 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
136 public ResponseEntity<HealthCheckReport> getHealthCheck(
\r
137 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
138 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
139 final var report = healthCheckProvider.performHealthCheck();
\r
140 updateApiStatisticsCounter(Target.OTHER, HttpStatus.resolve(report.getCode()), HttpMethod.GET);
\r
141 return makeResponse(requestId, report, report.getCode());
\r
145 * Retrieves the statistics report of the API component.
\r
147 * @return the Response object containing the results of the API operation
\r
149 @GetMapping("/statistics")
\r
150 @ApiOperation(value = "Retrieve current statistics",
\r
151 notes = "Returns current statistics including the counters of API invocation",
\r
152 response = StatisticsReport.class,
\r
153 responseHeaders = {
\r
154 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
155 description = VERSION_MINOR_DESCRIPTION,
\r
156 response = String.class),
\r
157 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
158 description = VERSION_PATCH_DESCRIPTION,
\r
159 response = String.class),
\r
160 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
161 response = String.class),
\r
162 @ResponseHeader(name = REQUEST_ID_NAME,
\r
163 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
164 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Statistics", },
\r
166 @Extension(name = EXTENSION_NAME, properties = {
\r
167 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
168 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
169 @ApiResponses(value = {
\r
170 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
171 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
172 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
173 public ResponseEntity<StatisticsReport> getStatistics(
\r
174 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
175 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
176 updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);
\r
177 return makeOkResponse(requestId, statisticsProvider.fetchCurrentStatistics());
\r
181 * Retrieves all available policy types.
\r
183 * @return the Response object containing the results of the API operation
\r
185 @GetMapping("/policytypes")
\r
186 @ApiOperation(value = "Retrieve existing policy types",
\r
187 notes = "Returns a list of existing policy types stored in Policy Framework",
\r
188 response = ToscaServiceTemplate.class,
\r
189 responseHeaders = {
\r
190 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
191 description = VERSION_MINOR_DESCRIPTION,
\r
192 response = String.class),
\r
193 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
194 description = VERSION_PATCH_DESCRIPTION,
\r
195 response = String.class),
\r
196 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
197 response = String.class),
\r
198 @ResponseHeader(name = REQUEST_ID_NAME,
\r
199 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
200 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
202 @Extension(name = EXTENSION_NAME, properties = {
\r
203 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
204 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
205 @ApiResponses(value = {
\r
206 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
207 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
208 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
209 public ResponseEntity<ToscaServiceTemplate> getAllPolicyTypes(
\r
210 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
211 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
213 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(null, null);
\r
214 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
215 return makeOkResponse(requestId, serviceTemplate);
\r
216 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
217 final var msg = "GET /policytypes";
\r
218 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
219 .getStatusCode()), HttpMethod.GET);
\r
220 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
225 * Retrieves all versions of a particular policy type.
\r
227 * @param policyTypeId the ID of specified policy type
\r
229 * @return the Response object containing the results of the API operation
\r
231 @GetMapping("/policytypes/{policyTypeId}")
\r
232 @ApiOperation(value = "Retrieve all available versions of a policy type",
\r
233 notes = "Returns a list of all available versions for the specified policy type",
\r
234 response = ToscaServiceTemplate.class,
\r
235 responseHeaders = {
\r
236 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
237 description = VERSION_MINOR_DESCRIPTION,
\r
238 response = String.class),
\r
239 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
240 description = VERSION_PATCH_DESCRIPTION,
\r
241 response = String.class),
\r
242 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
243 response = String.class),
\r
244 @ResponseHeader(name = REQUEST_ID_NAME,
\r
245 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
246 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
248 @Extension(name = EXTENSION_NAME, properties = {
\r
249 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
250 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
251 @ApiResponses(value = {
\r
252 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
253 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
254 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
255 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
256 public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicyType(
\r
257 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
258 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
259 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
261 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, null);
\r
262 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
263 return makeOkResponse(requestId, serviceTemplate);
\r
264 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
265 var msg = String.format("GET /policytypes/%s", policyTypeId);
\r
266 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
267 .getStatusCode()), HttpMethod.GET);
\r
268 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
273 * Retrieves specified version of a particular policy type.
\r
275 * @param policyTypeId the ID of specified policy type
\r
276 * @param versionId the version of specified policy type
\r
278 * @return the Response object containing the results of the API operation
\r
280 @GetMapping("/policytypes/{policyTypeId}/versions/{versionId}")
\r
281 @ApiOperation(value = "Retrieve one particular version of a policy type",
\r
282 notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
\r
283 responseHeaders = {
\r
284 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
285 description = VERSION_MINOR_DESCRIPTION,
\r
286 response = String.class),
\r
287 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
288 description = VERSION_PATCH_DESCRIPTION,
\r
289 response = String.class),
\r
290 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
291 response = String.class),
\r
292 @ResponseHeader(name = REQUEST_ID_NAME,
\r
293 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
294 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
296 @Extension(name = EXTENSION_NAME, properties = {
\r
297 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
298 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
299 @ApiResponses(value = {
\r
300 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
301 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
302 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
303 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
304 public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicyType(
\r
305 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
306 @PathVariable("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
307 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
308 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
310 ToscaServiceTemplate serviceTemplate =
\r
311 toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, versionId);
\r
312 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
313 return makeOkResponse(requestId, serviceTemplate);
\r
314 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
315 var msg = String.format("GET /policytypes/%s/versions/%s", policyTypeId, versionId);
\r
316 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
317 .getStatusCode()), HttpMethod.GET);
\r
318 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
323 * Retrieves latest version of a particular policy type.
\r
325 * @param policyTypeId the ID of specified policy type
\r
327 * @return the Response object containing the results of the API operation
\r
329 @GetMapping("/policytypes/{policyTypeId}/versions/latest")
\r
330 @ApiOperation(value = "Retrieve latest version of a policy type",
\r
331 notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
\r
332 responseHeaders = {
\r
333 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
334 description = VERSION_MINOR_DESCRIPTION,
\r
335 response = String.class),
\r
336 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
337 description = VERSION_PATCH_DESCRIPTION,
\r
338 response = String.class),
\r
339 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
340 response = String.class),
\r
341 @ResponseHeader(name = REQUEST_ID_NAME,
\r
342 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
343 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
345 @Extension(name = EXTENSION_NAME, properties = {
\r
346 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
347 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
348 @ApiResponses(value = {
\r
349 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
350 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
351 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
352 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
353 public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicyType(
\r
354 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
355 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
356 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
358 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicyTypes(policyTypeId);
\r
359 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
360 return makeOkResponse(requestId, serviceTemplate);
\r
361 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
362 var msg = String.format("GET /policytypes/%s/versions/latest", policyTypeId);
\r
363 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
364 .getStatusCode()), HttpMethod.GET);
\r
365 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
370 * Creates a new policy type.
\r
372 * @param body the body of policy type following TOSCA definition
\r
374 * @return the Response object containing the results of the API operation
\r
376 @PostMapping("/policytypes")
\r
377 @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",
\r
378 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
379 response = ToscaServiceTemplate.class,
\r
380 responseHeaders = {
\r
381 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
382 description = VERSION_MINOR_DESCRIPTION,
\r
383 response = String.class),
\r
384 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
385 description = VERSION_PATCH_DESCRIPTION,
\r
386 response = String.class),
\r
387 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
388 response = String.class),
\r
389 @ResponseHeader(name = REQUEST_ID_NAME,
\r
390 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
392 @Extension(name = EXTENSION_NAME, properties = {
\r
393 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
394 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
395 @ApiResponses(value = {
\r
396 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
397 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
398 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
399 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
400 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
401 public ResponseEntity<ToscaServiceTemplate> createPolicyType(
\r
402 @RequestBody @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
\r
403 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
404 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
405 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
406 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
\r
409 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(body);
\r
410 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.POST);
\r
411 return makeOkResponse(requestId, serviceTemplate);
\r
412 } catch (PfModelRuntimeException pfme) {
\r
413 final var msg = "POST /policytypes";
\r
414 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
415 .getStatusCode()), HttpMethod.POST);
\r
416 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
421 * Deletes specified version of a particular policy type.
\r
423 * @param policyTypeId the ID of specified policy type
\r
424 * @param versionId the version of specified policy type
\r
426 * @return the Response object containing the results of the API operation
\r
428 @DeleteMapping("/policytypes/{policyTypeId}/versions/{versionId}")
\r
429 @ApiOperation(value = "Delete one version of a policy type",
\r
430 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
431 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
432 + "The parameterizing TOSCA policies must be deleted first;",
\r
433 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
434 response = ToscaServiceTemplate.class,
\r
435 responseHeaders = {
\r
436 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
437 description = VERSION_MINOR_DESCRIPTION,
\r
438 response = String.class),
\r
439 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
440 description = VERSION_PATCH_DESCRIPTION,
\r
441 response = String.class),
\r
442 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
443 response = String.class),
\r
444 @ResponseHeader(name = REQUEST_ID_NAME,
\r
445 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
447 @Extension(name = EXTENSION_NAME, properties = {
\r
448 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
449 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
450 @ApiResponses(value = {
\r
451 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
452 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
453 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
454 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
455 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
456 public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicyType(
\r
457 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
458 @PathVariable("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
459 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
460 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
462 ToscaServiceTemplate serviceTemplate =
\r
463 toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);
\r
464 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.DELETE);
\r
465 return makeOkResponse(requestId, serviceTemplate);
\r
466 } catch (PfModelRuntimeException pfme) {
\r
467 var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);
\r
468 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
469 .getStatusCode()), HttpMethod.DELETE);
\r
470 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
475 * Retrieves all versions of a particular policy.
\r
477 * @param policyTypeId the ID of specified policy type
\r
478 * @param policyTypeVersion the version of specified policy type
\r
480 * @return the Response object containing the results of the API operation
\r
482 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
484 value = "Retrieve all versions of a policy created for a particular policy type version",
\r
485 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
\r
486 response = ToscaServiceTemplate.class,
\r
487 responseHeaders = {
\r
488 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
489 description = VERSION_MINOR_DESCRIPTION,
\r
490 response = String.class),
\r
491 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
492 description = VERSION_PATCH_DESCRIPTION,
\r
493 response = String.class),
\r
494 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
495 response = String.class),
\r
496 @ResponseHeader(name = REQUEST_ID_NAME,
\r
497 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
498 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy,"},
\r
500 @Extension(name = EXTENSION_NAME, properties = {
\r
501 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
502 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
506 @ApiResponses(value = {
\r
507 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
508 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
509 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
510 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
512 public ResponseEntity<ToscaServiceTemplate> getAllPolicies(
\r
513 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
514 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
515 required = true) String policyTypeVersion,
\r
516 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
517 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
518 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
519 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
521 ToscaServiceTemplate serviceTemplate =
\r
522 toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
\r
523 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
524 return makeOkResponse(requestId, serviceTemplate);
\r
525 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
526 var msg = String.format("GET /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);
\r
527 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
528 .getStatusCode()), HttpMethod.GET);
\r
529 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
534 * Retrieves all versions of a particular policy.
\r
536 * @param policyTypeId the ID of specified policy type
\r
537 * @param policyTypeVersion the version of specified policy type
\r
538 * @param policyId the ID of specified policy
\r
540 * @return the Response object containing the results of the API operation
\r
542 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
543 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
\r
544 notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class,
\r
545 responseHeaders = {
\r
546 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
547 description = VERSION_MINOR_DESCRIPTION,
\r
548 response = String.class),
\r
549 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
550 description = VERSION_PATCH_DESCRIPTION,
\r
551 response = String.class),
\r
552 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
553 response = String.class),
\r
554 @ResponseHeader(name = REQUEST_ID_NAME,
\r
555 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
556 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
558 @Extension(name = EXTENSION_NAME, properties = {
\r
559 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
560 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
564 @ApiResponses(value = {
\r
565 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
566 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
567 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
568 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
570 public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicy(
\r
571 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
572 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
573 required = true) String policyTypeVersion,
\r
574 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
575 @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
576 @RequestParam(name = "mode", defaultValue = "bare")
\r
577 @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
578 + " REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
580 ToscaServiceTemplate serviceTemplate =
\r
581 toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
\r
582 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
583 return makeOkResponse(requestId, serviceTemplate);
\r
584 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
585 var msg = String.format("/policytypes/%s/versions/%s/policies/%s",
\r
586 policyTypeId, policyTypeVersion, policyId);
\r
587 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
588 .getStatusCode()), HttpMethod.GET);
\r
589 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
594 * Retrieves the specified version of a particular policy.
\r
596 * @param policyTypeId the ID of specified policy type
\r
597 * @param policyTypeVersion the version of specified policy type
\r
598 * @param policyId the ID of specified policy
\r
599 * @param policyVersion the version of specified policy
\r
601 * @return the Response object containing the results of the API operation
\r
603 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
604 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
\r
605 notes = "Returns a particular version of specified policy created for the specified policy type version",
\r
606 response = ToscaServiceTemplate.class,
\r
607 responseHeaders = {
\r
608 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
609 description = VERSION_MINOR_DESCRIPTION,
\r
610 response = String.class),
\r
611 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
612 description = VERSION_PATCH_DESCRIPTION,
\r
613 response = String.class),
\r
614 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
615 response = String.class),
\r
616 @ResponseHeader(name = REQUEST_ID_NAME,
\r
617 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
618 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
620 @Extension(name = EXTENSION_NAME, properties = {
\r
621 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
622 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
626 @ApiResponses(value = {
\r
627 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
628 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
629 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
630 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
632 public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicy(
\r
633 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
634 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
635 required = true) String policyTypeVersion,
\r
636 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
637 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
638 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
639 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
640 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare policies"
\r
641 + " (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
643 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService
\r
644 .fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
\r
645 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
646 return makeOkResponse(requestId, serviceTemplate);
\r
647 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
648 var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/%s",
\r
649 policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
650 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
651 .getStatusCode()), HttpMethod.GET);
\r
652 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
657 * Retrieves the latest version of a particular policy.
\r
659 * @param policyTypeId the ID of specified policy type
\r
660 * @param policyTypeVersion the version of specified policy type
\r
661 * @param policyId the ID of specified policy
\r
663 * @return the Response object containing the results of the API operation
\r
665 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
\r
666 @ApiOperation(value = "Retrieve the latest version of a particular policy",
\r
667 notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
\r
668 responseHeaders = {
\r
669 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
670 description = VERSION_MINOR_DESCRIPTION,
\r
671 response = String.class),
\r
672 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
673 description = VERSION_PATCH_DESCRIPTION,
\r
674 response = String.class),
\r
675 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
676 response = String.class),
\r
677 @ResponseHeader(name = REQUEST_ID_NAME,
\r
678 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
679 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
681 @Extension(name = EXTENSION_NAME, properties = {
\r
682 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
683 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
684 @ApiResponses(value = {
\r
685 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
686 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
687 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
688 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
689 public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicy(
\r
690 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
691 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
692 required = true) String policyTypeVersion,
\r
693 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
694 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
695 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
696 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, TERSE for bare "
\r
697 + "policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
699 ToscaServiceTemplate serviceTemplate =
\r
700 toscaServiceTemplateService.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
\r
701 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
702 return makeOkResponse(requestId, serviceTemplate);
\r
703 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
704 var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/latest",
\r
705 policyTypeId, policyTypeVersion, policyId);
\r
706 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
707 .getStatusCode()), HttpMethod.GET);
\r
708 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
713 * Creates a new policy for a particular policy type and version.
\r
715 * @param policyTypeId the ID of specified policy type
\r
716 * @param policyTypeVersion the version of specified policy type
\r
717 * @param body the body of policy following TOSCA definition
\r
719 * @return the Response object containing the results of the API operation
\r
721 @PostMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
722 @ApiOperation(value = "Create a new policy for a policy type version",
\r
723 notes = "Client should provide TOSCA body of the new policy",
\r
724 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
725 response = ToscaServiceTemplate.class,
\r
726 responseHeaders = {
\r
727 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
728 description = VERSION_MINOR_DESCRIPTION,
\r
729 response = String.class),
\r
730 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
731 description = VERSION_PATCH_DESCRIPTION,
\r
732 response = String.class),
\r
733 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
734 response = String.class),
\r
735 @ResponseHeader(name = REQUEST_ID_NAME,
\r
736 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
738 @Extension(name = EXTENSION_NAME, properties = {
\r
739 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
740 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
741 @ApiResponses(value = {
\r
742 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
743 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
744 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
745 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
746 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
747 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
748 public ResponseEntity<ToscaServiceTemplate> createPolicy(
\r
749 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
750 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
751 required = true) String policyTypeVersion,
\r
752 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
753 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
754 @RequestBody @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
755 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
756 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
\r
757 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
\r
760 ToscaServiceTemplate serviceTemplate =
\r
761 toscaServiceTemplateService.createPolicy(policyTypeId, policyTypeVersion, body);
\r
762 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);
\r
763 return makeOkResponse(requestId, serviceTemplate);
\r
764 } catch (PfModelRuntimeException pfme) {
\r
765 var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);
\r
766 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
767 .getStatusCode()), HttpMethod.POST);
\r
768 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
773 * Deletes the specified version of a particular policy.
\r
775 * @param policyTypeId the ID of specified policy type
\r
776 * @param policyTypeVersion the version of specified policy type
\r
777 * @param policyId the ID of specified policy
\r
778 * @param policyVersion the version of specified policy
\r
780 * @return the Response object containing the results of the API operation
\r
782 @DeleteMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/"
\r
783 + "versions/{policyVersion}")
\r
784 @ApiOperation(value = "Delete a particular version of a policy",
\r
785 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
786 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
787 response = ToscaServiceTemplate.class,
\r
788 responseHeaders = {
\r
789 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
790 description = VERSION_MINOR_DESCRIPTION,
\r
791 response = String.class),
\r
792 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
793 description = VERSION_PATCH_DESCRIPTION,
\r
794 response = String.class),
\r
795 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
796 response = String.class),
\r
797 @ResponseHeader(name = REQUEST_ID_NAME,
\r
798 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
800 @Extension(name = EXTENSION_NAME, properties = {
\r
801 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
802 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
803 @ApiResponses(value = {
\r
804 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
805 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
806 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
807 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
808 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
809 public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicy(
\r
810 @PathVariable("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
\r
811 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
812 required = true) String policyTypeVersion,
\r
813 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
814 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
815 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
816 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
818 ToscaServiceTemplate serviceTemplate =
\r
819 toscaServiceTemplateService.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
820 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);
\r
821 return makeOkResponse(requestId, serviceTemplate);
\r
822 } catch (PfModelRuntimeException pfme) {
\r
823 var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",
\r
824 policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
825 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
826 .getStatusCode()), HttpMethod.DELETE);
\r
827 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
832 * Retrieves all the available policies.
\r
834 * @return the Response object containing the results of the API operation
\r
836 @GetMapping("/policies")
\r
837 @ApiOperation(value = "Retrieve all versions of available policies",
\r
838 notes = "Returns all version of available policies",
\r
839 response = ToscaServiceTemplate.class,
\r
840 responseHeaders = {
\r
841 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
842 description = VERSION_MINOR_DESCRIPTION,
\r
843 response = String.class),
\r
844 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
845 description = VERSION_PATCH_DESCRIPTION,
\r
846 response = String.class),
\r
847 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
848 response = String.class),
\r
849 @ResponseHeader(name = REQUEST_ID_NAME,
\r
850 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
851 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
853 @Extension(name = EXTENSION_NAME, properties = {
\r
854 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
855 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")
\r
859 @ApiResponses(value = {
\r
860 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
861 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
862 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
863 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
865 public ResponseEntity<ToscaServiceTemplate> getPolicies(
\r
866 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
867 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
868 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
869 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
871 ToscaServiceTemplate serviceTemplate =
\r
872 toscaServiceTemplateService.fetchPolicies(null, null, null, null, mode);
\r
873 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
874 return makeOkResponse(requestId, serviceTemplate);
\r
875 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
876 final var msg = "GET /policies/ --";
\r
877 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
878 .getStatusCode()), HttpMethod.GET);
\r
879 if (pfme.getErrorResponse().getResponseCode().equals(Status.NOT_FOUND)) {
\r
880 pfme.getErrorResponse().setErrorMessage(ERROR_MESSAGE_NO_POLICIES_FOUND);
\r
881 pfme.getErrorResponse().setErrorDetails(List.of(ERROR_MESSAGE_NO_POLICIES_FOUND));
\r
883 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
888 * Retrieves the specified version of a particular policy.
\r
890 * @param policyId the Name of specified policy
\r
891 * @param policyVersion the version of specified policy
\r
893 * @return the Response object containing the results of the API operation
\r
895 @GetMapping("/policies/{policyId}/versions/{policyVersion}")
\r
896 @ApiOperation(value = "Retrieve specific version of a specified policy",
\r
897 notes = "Returns a particular version of specified policy",
\r
898 response = ToscaServiceTemplate.class,
\r
899 responseHeaders = {
\r
900 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
901 description = VERSION_MINOR_DESCRIPTION,
\r
902 response = String.class),
\r
903 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
904 description = VERSION_PATCH_DESCRIPTION,
\r
905 response = String.class),
\r
906 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
907 response = String.class),
\r
908 @ResponseHeader(name = REQUEST_ID_NAME,
\r
909 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
910 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
912 @Extension(name = EXTENSION_NAME, properties = {
\r
913 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
914 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")
\r
918 @ApiResponses(value = {
\r
919 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
920 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
921 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
922 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
924 public ResponseEntity<ToscaServiceTemplate> getSpecificPolicy(
\r
925 @PathVariable("policyId") @ApiParam(value = "Name of policy", required = true) String policyId,
\r
926 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
927 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
928 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
929 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
930 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
932 ToscaServiceTemplate serviceTemplate =
\r
933 toscaServiceTemplateService.fetchPolicies(null, null, policyId, policyVersion, mode);
\r
934 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
935 return makeOkResponse(requestId, serviceTemplate);
\r
936 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
937 var msg = String.format("GET /policies/%s/versions/%s", policyId, policyVersion);
\r
938 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
939 .getStatusCode()), HttpMethod.GET);
\r
940 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
945 * Creates one or more new policies in one call.
\r
947 * @param body the body of policy following TOSCA definition
\r
949 * @return the Response object containing the results of the API operation
\r
951 @PostMapping("/policies")
\r
952 @ApiOperation(value = "Create one or more new policies",
\r
953 notes = "Client should provide TOSCA body of the new polic(ies)",
\r
954 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
955 response = ToscaServiceTemplate.class,
\r
956 responseHeaders = {
\r
957 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
958 description = VERSION_MINOR_DESCRIPTION,
\r
959 response = String.class),
\r
960 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
961 description = VERSION_PATCH_DESCRIPTION,
\r
962 response = String.class),
\r
963 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
964 response = String.class),
\r
965 @ResponseHeader(name = REQUEST_ID_NAME,
\r
966 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
968 @Extension(name = EXTENSION_NAME, properties = {
\r
969 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
970 @ExtensionProperty(name = LAST_MOD_NAME, value = "El Alto")})})
\r
971 @ApiResponses(value = {
\r
972 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
973 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
974 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
975 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
976 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
977 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
978 public ResponseEntity<ToscaServiceTemplate> createPolicies(
\r
979 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
980 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
981 @RequestBody @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
982 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
983 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));
\r
986 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicies(body);
\r
987 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);
\r
988 return makeOkResponse(requestId, serviceTemplate);
\r
989 } catch (PfModelRuntimeException pfme) {
\r
990 final var msg = "POST /policies";
\r
991 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
992 .getStatusCode()), HttpMethod.POST);
\r
993 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
998 * Deletes the specified version of a particular policy.
\r
1000 * @param policyId the ID of specified policy
\r
1001 * @param policyVersion the version of specified policy
\r
1003 * @return the Response object containing the results of the API operation
\r
1005 @DeleteMapping("/policies/{policyId}/versions/{policyVersion}")
\r
1006 @ApiOperation(value = "Delete a particular version of a policy",
\r
1007 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
1008 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
1009 response = ToscaServiceTemplate.class,
\r
1010 responseHeaders = {
\r
1011 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
1012 description = VERSION_MINOR_DESCRIPTION,
\r
1013 response = String.class),
\r
1014 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
1015 description = VERSION_PATCH_DESCRIPTION,
\r
1016 response = String.class),
\r
1017 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
1018 response = String.class),
\r
1019 @ResponseHeader(name = REQUEST_ID_NAME,
\r
1020 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
1022 @Extension(name = EXTENSION_NAME, properties = {
\r
1023 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
1024 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")})})
\r
1025 @ApiResponses(value = {
\r
1026 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
1027 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
1028 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
1029 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
1030 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
1031 public ResponseEntity<ToscaServiceTemplate> deleteSpecificPolicy(
\r
1032 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
1033 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
1034 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
1035 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
1037 ToscaServiceTemplate serviceTemplate =
\r
1038 toscaServiceTemplateService.deletePolicy(null, null, policyId, policyVersion);
\r
1039 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);
\r
1040 return makeOkResponse(requestId, serviceTemplate);
\r
1041 } catch (PfModelRuntimeException pfme) {
\r
1042 var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);
\r
1043 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
1044 .getStatusCode()), HttpMethod.DELETE);
\r
1045 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
1049 private void updateApiStatisticsCounter(Target target, HttpStatus result, HttpMethod http) {
\r
1050 mgr.updateTotalApiCallCount();
\r
1053 updatePolicyStats(result, http);
\r
1056 updatePolicyTypeStats(result, http);
\r
1059 mgr.updateApiCallSuccessCount();
\r
1064 private void updatePolicyStats(HttpStatus result, HttpMethod http) {
\r
1065 if (result.equals(HttpStatus.OK)) {
\r
1068 mgr.updateApiCallSuccessCount();
\r
1069 mgr.updateTotalPolicyGetCount();
\r
1070 mgr.updatePolicyGetSuccessCount();
\r
1073 mgr.updateApiCallSuccessCount();
\r
1074 mgr.updateTotalPolicyPostCount();
\r
1075 mgr.updatePolicyPostSuccessCount();
\r
1078 mgr.updateApiCallSuccessCount();
\r
1079 mgr.updateTotalPolicyDeleteCount();
\r
1080 mgr.updatePolicyDeleteSuccessCount();
\r
1083 mgr.updateApiCallSuccessCount();
\r
1089 mgr.updateApiCallFailureCount();
\r
1090 mgr.updateTotalPolicyGetCount();
\r
1091 mgr.updatePolicyGetFailureCount();
\r
1094 mgr.updateApiCallFailureCount();
\r
1095 mgr.updateTotalPolicyPostCount();
\r
1096 mgr.updatePolicyPostFailureCount();
\r
1099 mgr.updateApiCallFailureCount();
\r
1100 mgr.updateTotalPolicyDeleteCount();
\r
1101 mgr.updatePolicyDeleteFailureCount();
\r
1104 mgr.updateApiCallFailureCount();
\r
1110 private void updatePolicyTypeStats(HttpStatus result, HttpMethod http) {
\r
1111 if (result.equals(HttpStatus.OK)) {
\r
1114 mgr.updateApiCallSuccessCount();
\r
1115 mgr.updateTotalPolicyTypeGetCount();
\r
1116 mgr.updatePolicyTypeGetSuccessCount();
\r
1119 mgr.updateApiCallSuccessCount();
\r
1120 mgr.updateTotalPolicyTypePostCount();
\r
1121 mgr.updatePolicyTypePostSuccessCount();
\r
1124 mgr.updateApiCallSuccessCount();
\r
1125 mgr.updateTotalPolicyTypeDeleteCount();
\r
1126 mgr.updatePolicyTypeDeleteSuccessCount();
\r
1129 mgr.updateApiCallSuccessCount();
\r
1135 mgr.updateApiCallFailureCount();
\r
1136 mgr.updateTotalPolicyTypeGetCount();
\r
1137 mgr.updatePolicyTypeGetFailureCount();
\r
1140 mgr.updateApiCallFailureCount();
\r
1141 mgr.updateTotalPolicyTypePostCount();
\r
1142 mgr.updatePolicyTypePostFailureCount();
\r
1145 mgr.updateApiCallFailureCount();
\r
1146 mgr.updateTotalPolicyTypeDeleteCount();
\r
1147 mgr.updatePolicyTypeDeleteFailureCount();
\r
1150 mgr.updateApiCallFailureCount();
\r