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 updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);
\r
140 return makeOkResponse(requestId, healthCheckProvider.performHealthCheck());
\r
144 * Retrieves the statistics report of the API component.
\r
146 * @return the Response object containing the results of the API operation
\r
148 @GetMapping("/statistics")
\r
149 @ApiOperation(value = "Retrieve current statistics",
\r
150 notes = "Returns current statistics including the counters of API invocation",
\r
151 response = StatisticsReport.class,
\r
152 responseHeaders = {
\r
153 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
154 description = VERSION_MINOR_DESCRIPTION,
\r
155 response = String.class),
\r
156 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
157 description = VERSION_PATCH_DESCRIPTION,
\r
158 response = String.class),
\r
159 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
160 response = String.class),
\r
161 @ResponseHeader(name = REQUEST_ID_NAME,
\r
162 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
163 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Statistics", },
\r
165 @Extension(name = EXTENSION_NAME, properties = {
\r
166 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
167 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
168 @ApiResponses(value = {
\r
169 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
170 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
171 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
172 public ResponseEntity<StatisticsReport> getStatistics(
\r
173 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
174 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
175 updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);
\r
176 return makeOkResponse(requestId, statisticsProvider.fetchCurrentStatistics());
\r
180 * Retrieves all available policy types.
\r
182 * @return the Response object containing the results of the API operation
\r
184 @GetMapping("/policytypes")
\r
185 @ApiOperation(value = "Retrieve existing policy types",
\r
186 notes = "Returns a list of existing policy types stored in Policy Framework",
\r
187 response = ToscaServiceTemplate.class,
\r
188 responseHeaders = {
\r
189 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
190 description = VERSION_MINOR_DESCRIPTION,
\r
191 response = String.class),
\r
192 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
193 description = VERSION_PATCH_DESCRIPTION,
\r
194 response = String.class),
\r
195 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
196 response = String.class),
\r
197 @ResponseHeader(name = REQUEST_ID_NAME,
\r
198 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
199 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
201 @Extension(name = EXTENSION_NAME, properties = {
\r
202 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
203 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
204 @ApiResponses(value = {
\r
205 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
206 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
207 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
208 public ResponseEntity<ToscaServiceTemplate> getAllPolicyTypes(
\r
209 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
210 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
212 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(null, null);
\r
213 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
214 return makeOkResponse(requestId, serviceTemplate);
\r
215 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
216 final var msg = "GET /policytypes";
\r
217 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
218 .getStatusCode()), HttpMethod.GET);
\r
219 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
224 * Retrieves all versions of a particular policy type.
\r
226 * @param policyTypeId the ID of specified policy type
\r
228 * @return the Response object containing the results of the API operation
\r
230 @GetMapping("/policytypes/{policyTypeId}")
\r
231 @ApiOperation(value = "Retrieve all available versions of a policy type",
\r
232 notes = "Returns a list of all available versions for the specified policy type",
\r
233 response = ToscaServiceTemplate.class,
\r
234 responseHeaders = {
\r
235 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
236 description = VERSION_MINOR_DESCRIPTION,
\r
237 response = String.class),
\r
238 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
239 description = VERSION_PATCH_DESCRIPTION,
\r
240 response = String.class),
\r
241 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
242 response = String.class),
\r
243 @ResponseHeader(name = REQUEST_ID_NAME,
\r
244 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
245 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
247 @Extension(name = EXTENSION_NAME, properties = {
\r
248 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
249 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
250 @ApiResponses(value = {
\r
251 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
252 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
253 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
254 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
255 public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicyType(
\r
256 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
257 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
258 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
260 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, null);
\r
261 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
262 return makeOkResponse(requestId, serviceTemplate);
\r
263 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
264 var msg = String.format("GET /policytypes/%s", policyTypeId);
\r
265 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
266 .getStatusCode()), HttpMethod.GET);
\r
267 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
272 * Retrieves specified version of a particular policy type.
\r
274 * @param policyTypeId the ID of specified policy type
\r
275 * @param versionId the version of specified policy type
\r
277 * @return the Response object containing the results of the API operation
\r
279 @GetMapping("/policytypes/{policyTypeId}/versions/{versionId}")
\r
280 @ApiOperation(value = "Retrieve one particular version of a policy type",
\r
281 notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
\r
282 responseHeaders = {
\r
283 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
284 description = VERSION_MINOR_DESCRIPTION,
\r
285 response = String.class),
\r
286 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
287 description = VERSION_PATCH_DESCRIPTION,
\r
288 response = String.class),
\r
289 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
290 response = String.class),
\r
291 @ResponseHeader(name = REQUEST_ID_NAME,
\r
292 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
293 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
295 @Extension(name = EXTENSION_NAME, properties = {
\r
296 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
297 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
298 @ApiResponses(value = {
\r
299 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
300 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
301 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
302 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
303 public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicyType(
\r
304 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
305 @PathVariable("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
306 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
307 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
309 ToscaServiceTemplate serviceTemplate =
\r
310 toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, versionId);
\r
311 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
312 return makeOkResponse(requestId, serviceTemplate);
\r
313 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
314 var msg = String.format("GET /policytypes/%s/versions/%s", policyTypeId, versionId);
\r
315 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
316 .getStatusCode()), HttpMethod.GET);
\r
317 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
322 * Retrieves latest version of a particular policy type.
\r
324 * @param policyTypeId the ID of specified policy type
\r
326 * @return the Response object containing the results of the API operation
\r
328 @GetMapping("/policytypes/{policyTypeId}/versions/latest")
\r
329 @ApiOperation(value = "Retrieve latest version of a policy type",
\r
330 notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
\r
331 responseHeaders = {
\r
332 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
333 description = VERSION_MINOR_DESCRIPTION,
\r
334 response = String.class),
\r
335 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
336 description = VERSION_PATCH_DESCRIPTION,
\r
337 response = String.class),
\r
338 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
339 response = String.class),
\r
340 @ResponseHeader(name = REQUEST_ID_NAME,
\r
341 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
342 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
344 @Extension(name = EXTENSION_NAME, properties = {
\r
345 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
346 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
347 @ApiResponses(value = {
\r
348 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
349 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
350 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
351 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
352 public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicyType(
\r
353 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
354 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
355 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
357 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicyTypes(policyTypeId);
\r
358 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
359 return makeOkResponse(requestId, serviceTemplate);
\r
360 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
361 var msg = String.format("GET /policytypes/%s/versions/latest", policyTypeId);
\r
362 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
363 .getStatusCode()), HttpMethod.GET);
\r
364 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
369 * Creates a new policy type.
\r
371 * @param body the body of policy type following TOSCA definition
\r
373 * @return the Response object containing the results of the API operation
\r
375 @PostMapping("/policytypes")
\r
376 @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",
\r
377 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
378 response = ToscaServiceTemplate.class,
\r
379 responseHeaders = {
\r
380 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
381 description = VERSION_MINOR_DESCRIPTION,
\r
382 response = String.class),
\r
383 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
384 description = VERSION_PATCH_DESCRIPTION,
\r
385 response = String.class),
\r
386 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
387 response = String.class),
\r
388 @ResponseHeader(name = REQUEST_ID_NAME,
\r
389 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
391 @Extension(name = EXTENSION_NAME, properties = {
\r
392 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
393 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
394 @ApiResponses(value = {
\r
395 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
396 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
397 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
398 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
399 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
400 public ResponseEntity<ToscaServiceTemplate> createPolicyType(
\r
401 @RequestBody @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
\r
402 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
403 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
404 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
405 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
\r
408 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(body);
\r
409 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.POST);
\r
410 return makeOkResponse(requestId, serviceTemplate);
\r
411 } catch (PfModelRuntimeException pfme) {
\r
412 final var msg = "POST /policytypes";
\r
413 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
414 .getStatusCode()), HttpMethod.POST);
\r
415 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
420 * Deletes specified version of a particular policy type.
\r
422 * @param policyTypeId the ID of specified policy type
\r
423 * @param versionId the version of specified policy type
\r
425 * @return the Response object containing the results of the API operation
\r
427 @DeleteMapping("/policytypes/{policyTypeId}/versions/{versionId}")
\r
428 @ApiOperation(value = "Delete one version of a policy type",
\r
429 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
430 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
431 + "The parameterizing TOSCA policies must be deleted first;",
\r
432 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
433 response = ToscaServiceTemplate.class,
\r
434 responseHeaders = {
\r
435 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
436 description = VERSION_MINOR_DESCRIPTION,
\r
437 response = String.class),
\r
438 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
439 description = VERSION_PATCH_DESCRIPTION,
\r
440 response = String.class),
\r
441 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
442 response = String.class),
\r
443 @ResponseHeader(name = REQUEST_ID_NAME,
\r
444 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
446 @Extension(name = EXTENSION_NAME, properties = {
\r
447 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
448 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
449 @ApiResponses(value = {
\r
450 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
451 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
452 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
453 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
454 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
455 public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicyType(
\r
456 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
457 @PathVariable("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
458 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
459 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
461 ToscaServiceTemplate serviceTemplate =
\r
462 toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);
\r
463 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.DELETE);
\r
464 return makeOkResponse(requestId, serviceTemplate);
\r
465 } catch (PfModelRuntimeException pfme) {
\r
466 var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);
\r
467 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
468 .getStatusCode()), HttpMethod.DELETE);
\r
469 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
474 * Retrieves all versions of a particular policy.
\r
476 * @param policyTypeId the ID of specified policy type
\r
477 * @param policyTypeVersion the version of specified policy type
\r
479 * @return the Response object containing the results of the API operation
\r
481 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
483 value = "Retrieve all versions of a policy created for a particular policy type version",
\r
484 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
\r
485 response = ToscaServiceTemplate.class,
\r
486 responseHeaders = {
\r
487 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
488 description = VERSION_MINOR_DESCRIPTION,
\r
489 response = String.class),
\r
490 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
491 description = VERSION_PATCH_DESCRIPTION,
\r
492 response = String.class),
\r
493 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
494 response = String.class),
\r
495 @ResponseHeader(name = REQUEST_ID_NAME,
\r
496 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
497 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy,"},
\r
499 @Extension(name = EXTENSION_NAME, properties = {
\r
500 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
501 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
505 @ApiResponses(value = {
\r
506 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
507 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
508 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
509 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
511 public ResponseEntity<ToscaServiceTemplate> getAllPolicies(
\r
512 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
513 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
514 required = true) String policyTypeVersion,
\r
515 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
516 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
517 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
518 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
520 ToscaServiceTemplate serviceTemplate =
\r
521 toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
\r
522 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
523 return makeOkResponse(requestId, serviceTemplate);
\r
524 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
525 var msg = String.format("GET /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);
\r
526 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
527 .getStatusCode()), HttpMethod.GET);
\r
528 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
533 * Retrieves all versions of a particular policy.
\r
535 * @param policyTypeId the ID of specified policy type
\r
536 * @param policyTypeVersion the version of specified policy type
\r
537 * @param policyId the ID of specified policy
\r
539 * @return the Response object containing the results of the API operation
\r
541 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
542 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
\r
543 notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class,
\r
544 responseHeaders = {
\r
545 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
546 description = VERSION_MINOR_DESCRIPTION,
\r
547 response = String.class),
\r
548 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
549 description = VERSION_PATCH_DESCRIPTION,
\r
550 response = String.class),
\r
551 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
552 response = String.class),
\r
553 @ResponseHeader(name = REQUEST_ID_NAME,
\r
554 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
555 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
557 @Extension(name = EXTENSION_NAME, properties = {
\r
558 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
559 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
563 @ApiResponses(value = {
\r
564 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
565 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
566 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
567 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
569 public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicy(
\r
570 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
571 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
572 required = true) String policyTypeVersion,
\r
573 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
574 @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
575 @RequestParam(name = "mode", defaultValue = "bare")
\r
576 @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
577 + " REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
579 ToscaServiceTemplate serviceTemplate =
\r
580 toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
\r
581 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
582 return makeOkResponse(requestId, serviceTemplate);
\r
583 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
584 var msg = String.format("/policytypes/%s/versions/%s/policies/%s",
\r
585 policyTypeId, policyTypeVersion, policyId);
\r
586 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
587 .getStatusCode()), HttpMethod.GET);
\r
588 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
593 * Retrieves the specified version of a particular policy.
\r
595 * @param policyTypeId the ID of specified policy type
\r
596 * @param policyTypeVersion the version of specified policy type
\r
597 * @param policyId the ID of specified policy
\r
598 * @param policyVersion the version of specified policy
\r
600 * @return the Response object containing the results of the API operation
\r
602 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
603 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
\r
604 notes = "Returns a particular version of specified policy created for the specified policy type version",
\r
605 response = ToscaServiceTemplate.class,
\r
606 responseHeaders = {
\r
607 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
608 description = VERSION_MINOR_DESCRIPTION,
\r
609 response = String.class),
\r
610 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
611 description = VERSION_PATCH_DESCRIPTION,
\r
612 response = String.class),
\r
613 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
614 response = String.class),
\r
615 @ResponseHeader(name = REQUEST_ID_NAME,
\r
616 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
617 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
619 @Extension(name = EXTENSION_NAME, properties = {
\r
620 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
621 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
625 @ApiResponses(value = {
\r
626 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
627 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
628 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
629 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
631 public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicy(
\r
632 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
633 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
634 required = true) String policyTypeVersion,
\r
635 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
636 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
637 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
638 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
639 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare policies"
\r
640 + " (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
642 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService
\r
643 .fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
\r
644 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
645 return makeOkResponse(requestId, serviceTemplate);
\r
646 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
647 var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/%s",
\r
648 policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
649 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
650 .getStatusCode()), HttpMethod.GET);
\r
651 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
656 * Retrieves the latest version of a particular policy.
\r
658 * @param policyTypeId the ID of specified policy type
\r
659 * @param policyTypeVersion the version of specified policy type
\r
660 * @param policyId the ID of specified policy
\r
662 * @return the Response object containing the results of the API operation
\r
664 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
\r
665 @ApiOperation(value = "Retrieve the latest version of a particular policy",
\r
666 notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
\r
667 responseHeaders = {
\r
668 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
669 description = VERSION_MINOR_DESCRIPTION,
\r
670 response = String.class),
\r
671 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
672 description = VERSION_PATCH_DESCRIPTION,
\r
673 response = String.class),
\r
674 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
675 response = String.class),
\r
676 @ResponseHeader(name = REQUEST_ID_NAME,
\r
677 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
678 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
680 @Extension(name = EXTENSION_NAME, properties = {
\r
681 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
682 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
683 @ApiResponses(value = {
\r
684 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
685 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
686 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
687 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
688 public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicy(
\r
689 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
690 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
691 required = true) String policyTypeVersion,
\r
692 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
693 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
694 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
695 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, TERSE for bare "
\r
696 + "policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
698 ToscaServiceTemplate serviceTemplate =
\r
699 toscaServiceTemplateService.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
\r
700 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
701 return makeOkResponse(requestId, serviceTemplate);
\r
702 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
703 var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/latest",
\r
704 policyTypeId, policyTypeVersion, policyId);
\r
705 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
706 .getStatusCode()), HttpMethod.GET);
\r
707 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
712 * Creates a new policy for a particular policy type and version.
\r
714 * @param policyTypeId the ID of specified policy type
\r
715 * @param policyTypeVersion the version of specified policy type
\r
716 * @param body the body of policy following TOSCA definition
\r
718 * @return the Response object containing the results of the API operation
\r
720 @PostMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
721 @ApiOperation(value = "Create a new policy for a policy type version",
\r
722 notes = "Client should provide TOSCA body of the new policy",
\r
723 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
724 response = ToscaServiceTemplate.class,
\r
725 responseHeaders = {
\r
726 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
727 description = VERSION_MINOR_DESCRIPTION,
\r
728 response = String.class),
\r
729 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
730 description = VERSION_PATCH_DESCRIPTION,
\r
731 response = String.class),
\r
732 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
733 response = String.class),
\r
734 @ResponseHeader(name = REQUEST_ID_NAME,
\r
735 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
737 @Extension(name = EXTENSION_NAME, properties = {
\r
738 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
739 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
740 @ApiResponses(value = {
\r
741 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
742 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
743 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
744 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
745 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
746 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
747 public ResponseEntity<ToscaServiceTemplate> createPolicy(
\r
748 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
749 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
750 required = true) String policyTypeVersion,
\r
751 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
752 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
753 @RequestBody @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
754 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
755 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
\r
756 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
\r
759 ToscaServiceTemplate serviceTemplate =
\r
760 toscaServiceTemplateService.createPolicy(policyTypeId, policyTypeVersion, body);
\r
761 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);
\r
762 return makeOkResponse(requestId, serviceTemplate);
\r
763 } catch (PfModelRuntimeException pfme) {
\r
764 var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);
\r
765 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
766 .getStatusCode()), HttpMethod.POST);
\r
767 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
772 * Deletes the specified version of a particular policy.
\r
774 * @param policyTypeId the ID of specified policy type
\r
775 * @param policyTypeVersion the version of specified policy type
\r
776 * @param policyId the ID of specified policy
\r
777 * @param policyVersion the version of specified policy
\r
779 * @return the Response object containing the results of the API operation
\r
781 @DeleteMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/"
\r
782 + "versions/{policyVersion}")
\r
783 @ApiOperation(value = "Delete a particular version of a policy",
\r
784 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
785 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
786 response = ToscaServiceTemplate.class,
\r
787 responseHeaders = {
\r
788 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
789 description = VERSION_MINOR_DESCRIPTION,
\r
790 response = String.class),
\r
791 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
792 description = VERSION_PATCH_DESCRIPTION,
\r
793 response = String.class),
\r
794 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
795 response = String.class),
\r
796 @ResponseHeader(name = REQUEST_ID_NAME,
\r
797 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
799 @Extension(name = EXTENSION_NAME, properties = {
\r
800 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
801 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
802 @ApiResponses(value = {
\r
803 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
804 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
805 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
806 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
807 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
808 public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicy(
\r
809 @PathVariable("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
\r
810 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
811 required = true) String policyTypeVersion,
\r
812 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
813 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
814 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
815 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
817 ToscaServiceTemplate serviceTemplate =
\r
818 toscaServiceTemplateService.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
819 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);
\r
820 return makeOkResponse(requestId, serviceTemplate);
\r
821 } catch (PfModelRuntimeException pfme) {
\r
822 var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",
\r
823 policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
824 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
825 .getStatusCode()), HttpMethod.DELETE);
\r
826 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
831 * Retrieves all the available policies.
\r
833 * @return the Response object containing the results of the API operation
\r
835 @GetMapping("/policies")
\r
836 @ApiOperation(value = "Retrieve all versions of available policies",
\r
837 notes = "Returns all version of available policies",
\r
838 response = ToscaServiceTemplate.class,
\r
839 responseHeaders = {
\r
840 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
841 description = VERSION_MINOR_DESCRIPTION,
\r
842 response = String.class),
\r
843 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
844 description = VERSION_PATCH_DESCRIPTION,
\r
845 response = String.class),
\r
846 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
847 response = String.class),
\r
848 @ResponseHeader(name = REQUEST_ID_NAME,
\r
849 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
850 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
852 @Extension(name = EXTENSION_NAME, properties = {
\r
853 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
854 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")
\r
858 @ApiResponses(value = {
\r
859 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
860 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
861 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
862 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
864 public ResponseEntity<ToscaServiceTemplate> getPolicies(
\r
865 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
866 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
867 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
868 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
870 ToscaServiceTemplate serviceTemplate =
\r
871 toscaServiceTemplateService.fetchPolicies(null, null, null, null, mode);
\r
872 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
873 return makeOkResponse(requestId, serviceTemplate);
\r
874 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
875 final var msg = "GET /policies/ --";
\r
876 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
877 .getStatusCode()), HttpMethod.GET);
\r
878 if (pfme.getErrorResponse().getResponseCode().equals(Status.NOT_FOUND)) {
\r
879 pfme.getErrorResponse().setErrorMessage(ERROR_MESSAGE_NO_POLICIES_FOUND);
\r
880 pfme.getErrorResponse().setErrorDetails(List.of(ERROR_MESSAGE_NO_POLICIES_FOUND));
\r
882 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
887 * Retrieves the specified version of a particular policy.
\r
889 * @param policyId the Name of specified policy
\r
890 * @param policyVersion the version of specified policy
\r
892 * @return the Response object containing the results of the API operation
\r
894 @GetMapping("/policies/{policyId}/versions/{policyVersion}")
\r
895 @ApiOperation(value = "Retrieve specific version of a specified policy",
\r
896 notes = "Returns a particular version of specified policy",
\r
897 response = ToscaServiceTemplate.class,
\r
898 responseHeaders = {
\r
899 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
900 description = VERSION_MINOR_DESCRIPTION,
\r
901 response = String.class),
\r
902 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
903 description = VERSION_PATCH_DESCRIPTION,
\r
904 response = String.class),
\r
905 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
906 response = String.class),
\r
907 @ResponseHeader(name = REQUEST_ID_NAME,
\r
908 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
909 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
911 @Extension(name = EXTENSION_NAME, properties = {
\r
912 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
913 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")
\r
917 @ApiResponses(value = {
\r
918 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
919 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
920 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
921 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
923 public ResponseEntity<ToscaServiceTemplate> getSpecificPolicy(
\r
924 @PathVariable("policyId") @ApiParam(value = "Name of policy", required = true) String policyId,
\r
925 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
926 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
927 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
928 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
929 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
931 ToscaServiceTemplate serviceTemplate =
\r
932 toscaServiceTemplateService.fetchPolicies(null, null, policyId, policyVersion, mode);
\r
933 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
934 return makeOkResponse(requestId, serviceTemplate);
\r
935 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
936 var msg = String.format("GET /policies/%s/versions/%s", policyId, policyVersion);
\r
937 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
938 .getStatusCode()), HttpMethod.GET);
\r
939 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
944 * Creates one or more new policies in one call.
\r
946 * @param body the body of policy following TOSCA definition
\r
948 * @return the Response object containing the results of the API operation
\r
950 @PostMapping("/policies")
\r
951 @ApiOperation(value = "Create one or more new policies",
\r
952 notes = "Client should provide TOSCA body of the new polic(ies)",
\r
953 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
954 response = ToscaServiceTemplate.class,
\r
955 responseHeaders = {
\r
956 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
957 description = VERSION_MINOR_DESCRIPTION,
\r
958 response = String.class),
\r
959 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
960 description = VERSION_PATCH_DESCRIPTION,
\r
961 response = String.class),
\r
962 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
963 response = String.class),
\r
964 @ResponseHeader(name = REQUEST_ID_NAME,
\r
965 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
967 @Extension(name = EXTENSION_NAME, properties = {
\r
968 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
969 @ExtensionProperty(name = LAST_MOD_NAME, value = "El Alto")})})
\r
970 @ApiResponses(value = {
\r
971 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
972 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
973 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
974 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
975 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
976 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
977 public ResponseEntity<ToscaServiceTemplate> createPolicies(
\r
978 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
979 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
980 @RequestBody @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
981 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
982 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));
\r
985 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicies(body);
\r
986 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);
\r
987 return makeOkResponse(requestId, serviceTemplate);
\r
988 } catch (PfModelRuntimeException pfme) {
\r
989 final var msg = "POST /policies";
\r
990 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
991 .getStatusCode()), HttpMethod.POST);
\r
992 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
997 * Deletes the specified version of a particular policy.
\r
999 * @param policyId the ID of specified policy
\r
1000 * @param policyVersion the version of specified policy
\r
1002 * @return the Response object containing the results of the API operation
\r
1004 @DeleteMapping("/policies/{policyId}/versions/{policyVersion}")
\r
1005 @ApiOperation(value = "Delete a particular version of a policy",
\r
1006 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
1007 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
1008 response = ToscaServiceTemplate.class,
\r
1009 responseHeaders = {
\r
1010 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
1011 description = VERSION_MINOR_DESCRIPTION,
\r
1012 response = String.class),
\r
1013 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
1014 description = VERSION_PATCH_DESCRIPTION,
\r
1015 response = String.class),
\r
1016 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
1017 response = String.class),
\r
1018 @ResponseHeader(name = REQUEST_ID_NAME,
\r
1019 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
1021 @Extension(name = EXTENSION_NAME, properties = {
\r
1022 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
1023 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")})})
\r
1024 @ApiResponses(value = {
\r
1025 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
1026 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
1027 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
1028 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
1029 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
1030 public ResponseEntity<ToscaServiceTemplate> deleteSpecificPolicy(
\r
1031 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
1032 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
1033 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
1034 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
1036 ToscaServiceTemplate serviceTemplate =
\r
1037 toscaServiceTemplateService.deletePolicy(null, null, policyId, policyVersion);
\r
1038 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);
\r
1039 return makeOkResponse(requestId, serviceTemplate);
\r
1040 } catch (PfModelRuntimeException pfme) {
\r
1041 var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);
\r
1042 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
1043 .getStatusCode()), HttpMethod.DELETE);
\r
1044 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
1048 private void updateApiStatisticsCounter(Target target, HttpStatus result, HttpMethod http) {
\r
1049 mgr.updateTotalApiCallCount();
\r
1052 updatePolicyStats(result, http);
\r
1055 updatePolicyTypeStats(result, http);
\r
1058 mgr.updateApiCallSuccessCount();
\r
1063 private void updatePolicyStats(HttpStatus result, HttpMethod http) {
\r
1064 if (result.equals(HttpStatus.OK)) {
\r
1067 mgr.updateApiCallSuccessCount();
\r
1068 mgr.updateTotalPolicyGetCount();
\r
1069 mgr.updatePolicyGetSuccessCount();
\r
1072 mgr.updateApiCallSuccessCount();
\r
1073 mgr.updateTotalPolicyPostCount();
\r
1074 mgr.updatePolicyPostSuccessCount();
\r
1077 mgr.updateApiCallSuccessCount();
\r
1078 mgr.updateTotalPolicyDeleteCount();
\r
1079 mgr.updatePolicyDeleteSuccessCount();
\r
1082 mgr.updateApiCallSuccessCount();
\r
1088 mgr.updateApiCallFailureCount();
\r
1089 mgr.updateTotalPolicyGetCount();
\r
1090 mgr.updatePolicyGetFailureCount();
\r
1093 mgr.updateApiCallFailureCount();
\r
1094 mgr.updateTotalPolicyPostCount();
\r
1095 mgr.updatePolicyPostFailureCount();
\r
1098 mgr.updateApiCallFailureCount();
\r
1099 mgr.updateTotalPolicyDeleteCount();
\r
1100 mgr.updatePolicyDeleteFailureCount();
\r
1103 mgr.updateApiCallFailureCount();
\r
1109 private void updatePolicyTypeStats(HttpStatus result, HttpMethod http) {
\r
1110 if (result.equals(HttpStatus.OK)) {
\r
1113 mgr.updateApiCallSuccessCount();
\r
1114 mgr.updateTotalPolicyTypeGetCount();
\r
1115 mgr.updatePolicyTypeGetSuccessCount();
\r
1118 mgr.updateApiCallSuccessCount();
\r
1119 mgr.updateTotalPolicyTypePostCount();
\r
1120 mgr.updatePolicyTypePostSuccessCount();
\r
1123 mgr.updateApiCallSuccessCount();
\r
1124 mgr.updateTotalPolicyTypeDeleteCount();
\r
1125 mgr.updatePolicyTypeDeleteSuccessCount();
\r
1128 mgr.updateApiCallSuccessCount();
\r
1134 mgr.updateApiCallFailureCount();
\r
1135 mgr.updateTotalPolicyTypeGetCount();
\r
1136 mgr.updatePolicyTypeGetFailureCount();
\r
1139 mgr.updateApiCallFailureCount();
\r
1140 mgr.updateTotalPolicyTypePostCount();
\r
1141 mgr.updatePolicyTypePostFailureCount();
\r
1144 mgr.updateApiCallFailureCount();
\r
1145 mgr.updateTotalPolicyTypeDeleteCount();
\r
1146 mgr.updatePolicyTypeDeleteFailureCount();
\r
1149 mgr.updateApiCallFailureCount();
\r