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.HealthCheckProvider;
\r
48 import org.onap.policy.api.main.rest.provider.StatisticsProvider;
\r
49 import org.onap.policy.api.main.service.ToscaServiceTemplateService;
\r
50 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
\r
51 import org.onap.policy.common.endpoints.report.HealthCheckReport;
\r
52 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
\r
53 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
\r
54 import org.onap.policy.models.base.PfModelException;
\r
55 import org.onap.policy.models.base.PfModelRuntimeException;
\r
56 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
57 import org.springframework.http.HttpMethod;
\r
58 import org.springframework.http.HttpStatus;
\r
59 import org.springframework.http.ResponseEntity;
\r
60 import org.springframework.web.bind.annotation.DeleteMapping;
\r
61 import org.springframework.web.bind.annotation.GetMapping;
\r
62 import org.springframework.web.bind.annotation.PathVariable;
\r
63 import org.springframework.web.bind.annotation.PostMapping;
\r
64 import org.springframework.web.bind.annotation.RequestBody;
\r
65 import org.springframework.web.bind.annotation.RequestHeader;
\r
66 import org.springframework.web.bind.annotation.RequestMapping;
\r
67 import org.springframework.web.bind.annotation.RequestParam;
\r
68 import org.springframework.web.bind.annotation.RestController;
\r
71 * Class to provide REST API services.
\r
73 * @author Chenfei Gao (cgao@research.att.com)
\r
76 @RequestMapping(path = "/policy/api/v1", produces = { "application/json", "application/yaml" })
\r
77 @Api(value = "Policy Design API")
\r
80 description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
\r
81 + " policy types, policy type implementation and policies which can be recognized"
\r
82 + " and executable by incorporated policy engines. It is an"
\r
83 + " independent component running rest service that takes all policy design API calls"
\r
84 + " from clients and then assign them to different API working functions. Besides"
\r
85 + " that, API is also exposed for clients to retrieve healthcheck status of this API"
\r
86 + " rest service and the statistics report including the counters of API invocation.",
\r
87 version = "1.0.0", title = "Policy Design",
\r
88 extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
\r
89 @ExtensionProperty(name = "component", value = "Policy Framework")})}),
\r
90 schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
\r
91 securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
\r
92 @RequiredArgsConstructor
\r
93 public class ApiRestController extends CommonRestController {
\r
95 private enum Target {
\r
101 private final ToscaServiceTemplateService toscaServiceTemplateService;
\r
102 private final HealthCheckProvider healthCheckProvider;
\r
103 private final ApiStatisticsManager mgr;
\r
104 private final StatisticsProvider statisticsProvider;
\r
107 * Retrieves the healthcheck status of the API component.
\r
109 * @return the Response object containing the results of the API operation
\r
111 @GetMapping("/healthcheck")
\r
112 @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",
\r
113 response = HealthCheckReport.class,
\r
114 responseHeaders = {
\r
115 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
116 description = VERSION_MINOR_DESCRIPTION,
\r
117 response = String.class),
\r
118 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
119 description = VERSION_PATCH_DESCRIPTION,
\r
120 response = String.class),
\r
121 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
122 response = String.class),
\r
123 @ResponseHeader(name = REQUEST_ID_NAME,
\r
124 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
125 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"HealthCheck", },
\r
127 @Extension(name = EXTENSION_NAME, properties = {
\r
128 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
129 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
130 @ApiResponses(value = {
\r
131 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
132 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
133 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
134 public ResponseEntity<HealthCheckReport> getHealthCheck(
\r
135 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
136 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
137 updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);
\r
138 return makeOkResponse(requestId, healthCheckProvider.performHealthCheck());
\r
142 * Retrieves the statistics report of the API component.
\r
144 * @return the Response object containing the results of the API operation
\r
146 @GetMapping("/statistics")
\r
147 @ApiOperation(value = "Retrieve current statistics",
\r
148 notes = "Returns current statistics including the counters of API invocation",
\r
149 response = StatisticsReport.class,
\r
150 responseHeaders = {
\r
151 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
152 description = VERSION_MINOR_DESCRIPTION,
\r
153 response = String.class),
\r
154 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
155 description = VERSION_PATCH_DESCRIPTION,
\r
156 response = String.class),
\r
157 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
158 response = String.class),
\r
159 @ResponseHeader(name = REQUEST_ID_NAME,
\r
160 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
161 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Statistics", },
\r
163 @Extension(name = EXTENSION_NAME, properties = {
\r
164 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
165 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
166 @ApiResponses(value = {
\r
167 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
168 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
169 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
170 public ResponseEntity<StatisticsReport> getStatistics(
\r
171 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
172 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
173 updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);
\r
174 return makeOkResponse(requestId, statisticsProvider.fetchCurrentStatistics());
\r
178 * Retrieves all available policy types.
\r
180 * @return the Response object containing the results of the API operation
\r
182 @GetMapping("/policytypes")
\r
183 @ApiOperation(value = "Retrieve existing policy types",
\r
184 notes = "Returns a list of existing policy types stored in Policy Framework",
\r
185 response = ToscaServiceTemplate.class,
\r
186 responseHeaders = {
\r
187 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
188 description = VERSION_MINOR_DESCRIPTION,
\r
189 response = String.class),
\r
190 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
191 description = VERSION_PATCH_DESCRIPTION,
\r
192 response = String.class),
\r
193 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
194 response = String.class),
\r
195 @ResponseHeader(name = REQUEST_ID_NAME,
\r
196 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
197 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
199 @Extension(name = EXTENSION_NAME, properties = {
\r
200 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
201 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
202 @ApiResponses(value = {
\r
203 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
204 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
205 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
206 public ResponseEntity<ToscaServiceTemplate> getAllPolicyTypes(
\r
207 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
208 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
210 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(null, null);
\r
211 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
212 return makeOkResponse(requestId, serviceTemplate);
\r
213 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
214 final var msg = "GET /policytypes";
\r
215 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
216 .getStatusCode()), HttpMethod.GET);
\r
217 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
222 * Retrieves all versions of a particular policy type.
\r
224 * @param policyTypeId the ID of specified policy type
\r
226 * @return the Response object containing the results of the API operation
\r
228 @GetMapping("/policytypes/{policyTypeId}")
\r
229 @ApiOperation(value = "Retrieve all available versions of a policy type",
\r
230 notes = "Returns a list of all available versions for the specified policy type",
\r
231 response = ToscaServiceTemplate.class,
\r
232 responseHeaders = {
\r
233 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
234 description = VERSION_MINOR_DESCRIPTION,
\r
235 response = String.class),
\r
236 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
237 description = VERSION_PATCH_DESCRIPTION,
\r
238 response = String.class),
\r
239 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
240 response = String.class),
\r
241 @ResponseHeader(name = REQUEST_ID_NAME,
\r
242 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
243 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
245 @Extension(name = EXTENSION_NAME, properties = {
\r
246 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
247 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
248 @ApiResponses(value = {
\r
249 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
250 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
251 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
252 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
253 public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicyType(
\r
254 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
255 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
256 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
258 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, null);
\r
259 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
260 return makeOkResponse(requestId, serviceTemplate);
\r
261 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
262 var msg = String.format("GET /policytypes/%s", policyTypeId);
\r
263 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
264 .getStatusCode()), HttpMethod.GET);
\r
265 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
270 * Retrieves specified version of a particular policy type.
\r
272 * @param policyTypeId the ID of specified policy type
\r
273 * @param versionId the version of specified policy type
\r
275 * @return the Response object containing the results of the API operation
\r
277 @GetMapping("/policytypes/{policyTypeId}/versions/{versionId}")
\r
278 @ApiOperation(value = "Retrieve one particular version of a policy type",
\r
279 notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
\r
280 responseHeaders = {
\r
281 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
282 description = VERSION_MINOR_DESCRIPTION,
\r
283 response = String.class),
\r
284 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
285 description = VERSION_PATCH_DESCRIPTION,
\r
286 response = String.class),
\r
287 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
288 response = String.class),
\r
289 @ResponseHeader(name = REQUEST_ID_NAME,
\r
290 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
291 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
293 @Extension(name = EXTENSION_NAME, properties = {
\r
294 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
295 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
296 @ApiResponses(value = {
\r
297 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
298 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
299 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
300 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
301 public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicyType(
\r
302 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
303 @PathVariable("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
304 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
305 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
307 ToscaServiceTemplate serviceTemplate =
\r
308 toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, versionId);
\r
309 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
310 return makeOkResponse(requestId, serviceTemplate);
\r
311 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
312 var msg = String.format("GET /policytypes/%s/versions/%s", policyTypeId, versionId);
\r
313 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
314 .getStatusCode()), HttpMethod.GET);
\r
315 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
320 * Retrieves latest version of a particular policy type.
\r
322 * @param policyTypeId the ID of specified policy type
\r
324 * @return the Response object containing the results of the API operation
\r
326 @GetMapping("/policytypes/{policyTypeId}/versions/latest")
\r
327 @ApiOperation(value = "Retrieve latest version of a policy type",
\r
328 notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
\r
329 responseHeaders = {
\r
330 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
331 description = VERSION_MINOR_DESCRIPTION,
\r
332 response = String.class),
\r
333 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
334 description = VERSION_PATCH_DESCRIPTION,
\r
335 response = String.class),
\r
336 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
337 response = String.class),
\r
338 @ResponseHeader(name = REQUEST_ID_NAME,
\r
339 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
340 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
342 @Extension(name = EXTENSION_NAME, properties = {
\r
343 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
344 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
345 @ApiResponses(value = {
\r
346 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
347 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
348 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
349 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
350 public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicyType(
\r
351 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
352 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
353 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
355 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicyTypes(policyTypeId);
\r
356 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
\r
357 return makeOkResponse(requestId, serviceTemplate);
\r
358 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
359 var msg = String.format("GET /policytypes/%s/versions/latest", policyTypeId);
\r
360 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
361 .getStatusCode()), HttpMethod.GET);
\r
362 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
367 * Creates a new policy type.
\r
369 * @param body the body of policy type following TOSCA definition
\r
371 * @return the Response object containing the results of the API operation
\r
373 @PostMapping("/policytypes")
\r
374 @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",
\r
375 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
376 response = ToscaServiceTemplate.class,
\r
377 responseHeaders = {
\r
378 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
379 description = VERSION_MINOR_DESCRIPTION,
\r
380 response = String.class),
\r
381 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
382 description = VERSION_PATCH_DESCRIPTION,
\r
383 response = String.class),
\r
384 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
385 response = String.class),
\r
386 @ResponseHeader(name = REQUEST_ID_NAME,
\r
387 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
389 @Extension(name = EXTENSION_NAME, properties = {
\r
390 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
391 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
392 @ApiResponses(value = {
\r
393 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
394 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
395 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
396 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
397 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
398 public ResponseEntity<ToscaServiceTemplate> createPolicyType(
\r
399 @RequestBody @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
\r
400 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
401 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
402 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
403 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
\r
406 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(body);
\r
407 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.POST);
\r
408 return makeOkResponse(requestId, serviceTemplate);
\r
409 } catch (PfModelRuntimeException pfme) {
\r
410 final var msg = "POST /policytypes";
\r
411 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
412 .getStatusCode()), HttpMethod.POST);
\r
413 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
418 * Deletes specified version of a particular policy type.
\r
420 * @param policyTypeId the ID of specified policy type
\r
421 * @param versionId the version of specified policy type
\r
423 * @return the Response object containing the results of the API operation
\r
425 @DeleteMapping("/policytypes/{policyTypeId}/versions/{versionId}")
\r
426 @ApiOperation(value = "Delete one version of a policy type",
\r
427 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
428 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
429 + "The parameterizing TOSCA policies must be deleted first;",
\r
430 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
431 response = ToscaServiceTemplate.class,
\r
432 responseHeaders = {
\r
433 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
434 description = VERSION_MINOR_DESCRIPTION,
\r
435 response = String.class),
\r
436 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
437 description = VERSION_PATCH_DESCRIPTION,
\r
438 response = String.class),
\r
439 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
440 response = String.class),
\r
441 @ResponseHeader(name = REQUEST_ID_NAME,
\r
442 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
444 @Extension(name = EXTENSION_NAME, properties = {
\r
445 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
446 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
447 @ApiResponses(value = {
\r
448 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
449 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
450 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
451 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
452 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
453 public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicyType(
\r
454 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
455 @PathVariable("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
456 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
457 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
459 ToscaServiceTemplate serviceTemplate =
\r
460 toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);
\r
461 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.DELETE);
\r
462 return makeOkResponse(requestId, serviceTemplate);
\r
463 } catch (PfModelRuntimeException pfme) {
\r
464 var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);
\r
465 updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
466 .getStatusCode()), HttpMethod.DELETE);
\r
467 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
472 * Retrieves all versions of a particular policy.
\r
474 * @param policyTypeId the ID of specified policy type
\r
475 * @param policyTypeVersion the version of specified policy type
\r
477 * @return the Response object containing the results of the API operation
\r
479 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
481 value = "Retrieve all versions of a policy created for a particular policy type version",
\r
482 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
\r
483 response = ToscaServiceTemplate.class,
\r
484 responseHeaders = {
\r
485 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
486 description = VERSION_MINOR_DESCRIPTION,
\r
487 response = String.class),
\r
488 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
489 description = VERSION_PATCH_DESCRIPTION,
\r
490 response = String.class),
\r
491 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
492 response = String.class),
\r
493 @ResponseHeader(name = REQUEST_ID_NAME,
\r
494 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
495 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy,"},
\r
497 @Extension(name = EXTENSION_NAME, properties = {
\r
498 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
499 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
503 @ApiResponses(value = {
\r
504 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
505 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
506 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
507 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
509 public ResponseEntity<ToscaServiceTemplate> getAllPolicies(
\r
510 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
511 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
512 required = true) String policyTypeVersion,
\r
513 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
514 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
515 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
516 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
518 ToscaServiceTemplate serviceTemplate =
\r
519 toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
\r
520 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
521 return makeOkResponse(requestId, serviceTemplate);
\r
522 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
523 var msg = String.format("GET /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);
\r
524 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
525 .getStatusCode()), HttpMethod.GET);
\r
526 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
531 * Retrieves all versions of a particular policy.
\r
533 * @param policyTypeId the ID of specified policy type
\r
534 * @param policyTypeVersion the version of specified policy type
\r
535 * @param policyId the ID of specified policy
\r
537 * @return the Response object containing the results of the API operation
\r
539 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
540 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
\r
541 notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class,
\r
542 responseHeaders = {
\r
543 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
544 description = VERSION_MINOR_DESCRIPTION,
\r
545 response = String.class),
\r
546 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
547 description = VERSION_PATCH_DESCRIPTION,
\r
548 response = String.class),
\r
549 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
550 response = String.class),
\r
551 @ResponseHeader(name = REQUEST_ID_NAME,
\r
552 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
553 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
555 @Extension(name = EXTENSION_NAME, properties = {
\r
556 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
557 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
561 @ApiResponses(value = {
\r
562 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
563 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
564 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
565 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
567 public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicy(
\r
568 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
569 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
570 required = true) String policyTypeVersion,
\r
571 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
572 @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
573 @RequestParam(name = "mode", defaultValue = "bare")
\r
574 @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
575 + " REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
577 ToscaServiceTemplate serviceTemplate =
\r
578 toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
\r
579 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
580 return makeOkResponse(requestId, serviceTemplate);
\r
581 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
582 var msg = String.format("/policytypes/%s/versions/%s/policies/%s",
\r
583 policyTypeId, policyTypeVersion, policyId);
\r
584 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
585 .getStatusCode()), HttpMethod.GET);
\r
586 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
591 * Retrieves the specified version of a particular policy.
\r
593 * @param policyTypeId the ID of specified policy type
\r
594 * @param policyTypeVersion the version of specified policy type
\r
595 * @param policyId the ID of specified policy
\r
596 * @param policyVersion the version of specified policy
\r
598 * @return the Response object containing the results of the API operation
\r
600 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
601 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
\r
602 notes = "Returns a particular version of specified policy created for the specified policy type version",
\r
603 response = ToscaServiceTemplate.class,
\r
604 responseHeaders = {
\r
605 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
606 description = VERSION_MINOR_DESCRIPTION,
\r
607 response = String.class),
\r
608 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
609 description = VERSION_PATCH_DESCRIPTION,
\r
610 response = String.class),
\r
611 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
612 response = String.class),
\r
613 @ResponseHeader(name = REQUEST_ID_NAME,
\r
614 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
615 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
617 @Extension(name = EXTENSION_NAME, properties = {
\r
618 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
619 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
623 @ApiResponses(value = {
\r
624 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
625 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
626 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
627 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
629 public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicy(
\r
630 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
631 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
632 required = true) String policyTypeVersion,
\r
633 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
634 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
635 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
636 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
637 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare policies"
\r
638 + " (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
640 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService
\r
641 .fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
\r
642 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
643 return makeOkResponse(requestId, serviceTemplate);
\r
644 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
645 var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/%s",
\r
646 policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
647 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
648 .getStatusCode()), HttpMethod.GET);
\r
649 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
654 * Retrieves the latest version of a particular policy.
\r
656 * @param policyTypeId the ID of specified policy type
\r
657 * @param policyTypeVersion the version of specified policy type
\r
658 * @param policyId the ID of specified policy
\r
660 * @return the Response object containing the results of the API operation
\r
662 @GetMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
\r
663 @ApiOperation(value = "Retrieve the latest version of a particular policy",
\r
664 notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
\r
665 responseHeaders = {
\r
666 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
667 description = VERSION_MINOR_DESCRIPTION,
\r
668 response = String.class),
\r
669 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
670 description = VERSION_PATCH_DESCRIPTION,
\r
671 response = String.class),
\r
672 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
673 response = String.class),
\r
674 @ResponseHeader(name = REQUEST_ID_NAME,
\r
675 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
676 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
678 @Extension(name = EXTENSION_NAME, properties = {
\r
679 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
680 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
681 @ApiResponses(value = {
\r
682 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
683 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
684 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
685 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
686 public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicy(
\r
687 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
688 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
689 required = true) String policyTypeVersion,
\r
690 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
691 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
692 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
693 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, TERSE for bare "
\r
694 + "policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
696 ToscaServiceTemplate serviceTemplate =
\r
697 toscaServiceTemplateService.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
\r
698 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
699 return makeOkResponse(requestId, serviceTemplate);
\r
700 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
701 var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/latest",
\r
702 policyTypeId, policyTypeVersion, policyId);
\r
703 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
704 .getStatusCode()), HttpMethod.GET);
\r
705 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
710 * Creates a new policy for a particular policy type and version.
\r
712 * @param policyTypeId the ID of specified policy type
\r
713 * @param policyTypeVersion the version of specified policy type
\r
714 * @param body the body of policy following TOSCA definition
\r
716 * @return the Response object containing the results of the API operation
\r
718 @PostMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
719 @ApiOperation(value = "Create a new policy for a policy type version",
\r
720 notes = "Client should provide TOSCA body of the new policy",
\r
721 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
722 response = ToscaServiceTemplate.class,
\r
723 responseHeaders = {
\r
724 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
725 description = VERSION_MINOR_DESCRIPTION,
\r
726 response = String.class),
\r
727 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
728 description = VERSION_PATCH_DESCRIPTION,
\r
729 response = String.class),
\r
730 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
731 response = String.class),
\r
732 @ResponseHeader(name = REQUEST_ID_NAME,
\r
733 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
735 @Extension(name = EXTENSION_NAME, properties = {
\r
736 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
737 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
738 @ApiResponses(value = {
\r
739 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
740 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
741 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
742 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
743 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
744 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
745 public ResponseEntity<ToscaServiceTemplate> createPolicy(
\r
746 @PathVariable("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
747 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
748 required = true) String policyTypeVersion,
\r
749 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
750 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
751 @RequestBody @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
752 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
753 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
\r
754 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
\r
757 ToscaServiceTemplate serviceTemplate =
\r
758 toscaServiceTemplateService.createPolicy(policyTypeId, policyTypeVersion, body);
\r
759 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);
\r
760 return makeOkResponse(requestId, serviceTemplate);
\r
761 } catch (PfModelRuntimeException pfme) {
\r
762 var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);
\r
763 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
764 .getStatusCode()), HttpMethod.POST);
\r
765 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
770 * Deletes the specified version of a particular policy.
\r
772 * @param policyTypeId the ID of specified policy type
\r
773 * @param policyTypeVersion the version of specified policy type
\r
774 * @param policyId the ID of specified policy
\r
775 * @param policyVersion the version of specified policy
\r
777 * @return the Response object containing the results of the API operation
\r
779 @DeleteMapping("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/"
\r
780 + "versions/{policyVersion}")
\r
781 @ApiOperation(value = "Delete a particular version of a policy",
\r
782 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
783 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
784 response = ToscaServiceTemplate.class,
\r
785 responseHeaders = {
\r
786 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
787 description = VERSION_MINOR_DESCRIPTION,
\r
788 response = String.class),
\r
789 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
790 description = VERSION_PATCH_DESCRIPTION,
\r
791 response = String.class),
\r
792 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
793 response = String.class),
\r
794 @ResponseHeader(name = REQUEST_ID_NAME,
\r
795 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
797 @Extension(name = EXTENSION_NAME, properties = {
\r
798 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
799 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
800 @ApiResponses(value = {
\r
801 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
802 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
803 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
804 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
805 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
806 public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicy(
\r
807 @PathVariable("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
\r
808 @PathVariable("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
809 required = true) String policyTypeVersion,
\r
810 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
811 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
812 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
813 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
815 ToscaServiceTemplate serviceTemplate =
\r
816 toscaServiceTemplateService.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
817 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);
\r
818 return makeOkResponse(requestId, serviceTemplate);
\r
819 } catch (PfModelRuntimeException pfme) {
\r
820 var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",
\r
821 policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
822 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
823 .getStatusCode()), HttpMethod.DELETE);
\r
824 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
829 * Retrieves all the available policies.
\r
831 * @return the Response object containing the results of the API operation
\r
833 @GetMapping("/policies")
\r
834 @ApiOperation(value = "Retrieve all versions of available policies",
\r
835 notes = "Returns all version of available policies",
\r
836 response = ToscaServiceTemplate.class,
\r
837 responseHeaders = {
\r
838 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
839 description = VERSION_MINOR_DESCRIPTION,
\r
840 response = String.class),
\r
841 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
842 description = VERSION_PATCH_DESCRIPTION,
\r
843 response = String.class),
\r
844 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
845 response = String.class),
\r
846 @ResponseHeader(name = REQUEST_ID_NAME,
\r
847 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
848 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
850 @Extension(name = EXTENSION_NAME, properties = {
\r
851 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
852 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")
\r
856 @ApiResponses(value = {
\r
857 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
858 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
859 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
860 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
862 public ResponseEntity<ToscaServiceTemplate> getPolicies(
\r
863 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
864 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
865 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
866 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
868 ToscaServiceTemplate serviceTemplate =
\r
869 toscaServiceTemplateService.fetchPolicies(null, null, null, null, mode);
\r
870 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
871 return makeOkResponse(requestId, serviceTemplate);
\r
872 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
873 final var msg = "GET /policies/ --";
\r
874 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
875 .getStatusCode()), HttpMethod.GET);
\r
876 if (pfme.getErrorResponse().getResponseCode().equals(Status.NOT_FOUND)) {
\r
877 pfme.getErrorResponse().setErrorMessage(ERROR_MESSAGE_NO_POLICIES_FOUND);
\r
878 pfme.getErrorResponse().setErrorDetails(List.of(ERROR_MESSAGE_NO_POLICIES_FOUND));
\r
880 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
885 * Retrieves the specified version of a particular policy.
\r
887 * @param policyId the Name of specified policy
\r
888 * @param policyVersion the version of specified policy
\r
890 * @return the Response object containing the results of the API operation
\r
892 @GetMapping("/policies/{policyId}/versions/{policyVersion}")
\r
893 @ApiOperation(value = "Retrieve specific version of a specified policy",
\r
894 notes = "Returns a particular version of specified policy",
\r
895 response = ToscaServiceTemplate.class,
\r
896 responseHeaders = {
\r
897 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
898 description = VERSION_MINOR_DESCRIPTION,
\r
899 response = String.class),
\r
900 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
901 description = VERSION_PATCH_DESCRIPTION,
\r
902 response = String.class),
\r
903 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
904 response = String.class),
\r
905 @ResponseHeader(name = REQUEST_ID_NAME,
\r
906 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
907 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
909 @Extension(name = EXTENSION_NAME, properties = {
\r
910 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
911 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")
\r
915 @ApiResponses(value = {
\r
916 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
917 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
918 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
919 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
921 public ResponseEntity<ToscaServiceTemplate> getSpecificPolicy(
\r
922 @PathVariable("policyId") @ApiParam(value = "Name of policy", required = true) String policyId,
\r
923 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
924 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
925 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
926 @RequestParam(name = "mode", defaultValue = "bare") @ApiParam("Fetch mode for policies, BARE for bare"
\r
927 + " policies (default), REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
929 ToscaServiceTemplate serviceTemplate =
\r
930 toscaServiceTemplateService.fetchPolicies(null, null, policyId, policyVersion, mode);
\r
931 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
\r
932 return makeOkResponse(requestId, serviceTemplate);
\r
933 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
934 var msg = String.format("GET /policies/%s/versions/%s", policyId, policyVersion);
\r
935 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
936 .getStatusCode()), HttpMethod.GET);
\r
937 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
942 * Creates one or more new policies in one call.
\r
944 * @param body the body of policy following TOSCA definition
\r
946 * @return the Response object containing the results of the API operation
\r
948 @PostMapping("/policies")
\r
949 @ApiOperation(value = "Create one or more new policies",
\r
950 notes = "Client should provide TOSCA body of the new polic(ies)",
\r
951 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
952 response = ToscaServiceTemplate.class,
\r
953 responseHeaders = {
\r
954 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
955 description = VERSION_MINOR_DESCRIPTION,
\r
956 response = String.class),
\r
957 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
958 description = VERSION_PATCH_DESCRIPTION,
\r
959 response = String.class),
\r
960 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
961 response = String.class),
\r
962 @ResponseHeader(name = REQUEST_ID_NAME,
\r
963 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
965 @Extension(name = EXTENSION_NAME, properties = {
\r
966 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
967 @ExtensionProperty(name = LAST_MOD_NAME, value = "El Alto")})})
\r
968 @ApiResponses(value = {
\r
969 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
970 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
971 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
972 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
973 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
974 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
975 public ResponseEntity<ToscaServiceTemplate> createPolicies(
\r
976 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
977 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
978 @RequestBody @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
979 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
980 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));
\r
983 ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicies(body);
\r
984 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);
\r
985 return makeOkResponse(requestId, serviceTemplate);
\r
986 } catch (PfModelRuntimeException pfme) {
\r
987 final var msg = "POST /policies";
\r
988 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
989 .getStatusCode()), HttpMethod.POST);
\r
990 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
995 * Deletes the specified version of a particular policy.
\r
997 * @param policyId the ID of specified policy
\r
998 * @param policyVersion the version of specified policy
\r
1000 * @return the Response object containing the results of the API operation
\r
1002 @DeleteMapping("/policies/{policyId}/versions/{policyVersion}")
\r
1003 @ApiOperation(value = "Delete a particular version of a policy",
\r
1004 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
1005 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
1006 response = ToscaServiceTemplate.class,
\r
1007 responseHeaders = {
\r
1008 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
1009 description = VERSION_MINOR_DESCRIPTION,
\r
1010 response = String.class),
\r
1011 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
1012 description = VERSION_PATCH_DESCRIPTION,
\r
1013 response = String.class),
\r
1014 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
1015 response = String.class),
\r
1016 @ResponseHeader(name = REQUEST_ID_NAME,
\r
1017 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
1019 @Extension(name = EXTENSION_NAME, properties = {
\r
1020 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
1021 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")})})
\r
1022 @ApiResponses(value = {
\r
1023 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
1024 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
1025 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
1026 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
1027 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
1028 public ResponseEntity<ToscaServiceTemplate> deleteSpecificPolicy(
\r
1029 @PathVariable("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
1030 @PathVariable("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
1031 @RequestHeader(name = REQUEST_ID_NAME, required = false)
\r
1032 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
1034 ToscaServiceTemplate serviceTemplate =
\r
1035 toscaServiceTemplateService.deletePolicy(null, null, policyId, policyVersion);
\r
1036 updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);
\r
1037 return makeOkResponse(requestId, serviceTemplate);
\r
1038 } catch (PfModelRuntimeException pfme) {
\r
1039 var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);
\r
1040 updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
\r
1041 .getStatusCode()), HttpMethod.DELETE);
\r
1042 throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
\r
1046 private void updateApiStatisticsCounter(Target target, HttpStatus result, HttpMethod http) {
\r
1047 mgr.updateTotalApiCallCount();
\r
1050 updatePolicyStats(result, http);
\r
1053 updatePolicyTypeStats(result, http);
\r
1056 mgr.updateApiCallSuccessCount();
\r
1061 private void updatePolicyStats(HttpStatus result, HttpMethod http) {
\r
1062 if (result.equals(HttpStatus.OK)) {
\r
1065 mgr.updateApiCallSuccessCount();
\r
1066 mgr.updateTotalPolicyGetCount();
\r
1067 mgr.updatePolicyGetSuccessCount();
\r
1070 mgr.updateApiCallSuccessCount();
\r
1071 mgr.updateTotalPolicyPostCount();
\r
1072 mgr.updatePolicyPostSuccessCount();
\r
1075 mgr.updateApiCallSuccessCount();
\r
1076 mgr.updateTotalPolicyDeleteCount();
\r
1077 mgr.updatePolicyDeleteSuccessCount();
\r
1080 mgr.updateApiCallSuccessCount();
\r
1086 mgr.updateApiCallFailureCount();
\r
1087 mgr.updateTotalPolicyGetCount();
\r
1088 mgr.updatePolicyGetFailureCount();
\r
1091 mgr.updateApiCallFailureCount();
\r
1092 mgr.updateTotalPolicyPostCount();
\r
1093 mgr.updatePolicyPostFailureCount();
\r
1096 mgr.updateApiCallFailureCount();
\r
1097 mgr.updateTotalPolicyDeleteCount();
\r
1098 mgr.updatePolicyDeleteFailureCount();
\r
1101 mgr.updateApiCallFailureCount();
\r
1107 private void updatePolicyTypeStats(HttpStatus result, HttpMethod http) {
\r
1108 if (result.equals(HttpStatus.OK)) {
\r
1111 mgr.updateApiCallSuccessCount();
\r
1112 mgr.updateTotalPolicyTypeGetCount();
\r
1113 mgr.updatePolicyTypeGetSuccessCount();
\r
1116 mgr.updateApiCallSuccessCount();
\r
1117 mgr.updateTotalPolicyTypePostCount();
\r
1118 mgr.updatePolicyTypePostSuccessCount();
\r
1121 mgr.updateApiCallSuccessCount();
\r
1122 mgr.updateTotalPolicyTypeDeleteCount();
\r
1123 mgr.updatePolicyTypeDeleteSuccessCount();
\r
1126 mgr.updateApiCallSuccessCount();
\r
1132 mgr.updateApiCallFailureCount();
\r
1133 mgr.updateTotalPolicyTypeGetCount();
\r
1134 mgr.updatePolicyTypeGetFailureCount();
\r
1137 mgr.updateApiCallFailureCount();
\r
1138 mgr.updateTotalPolicyTypePostCount();
\r
1139 mgr.updatePolicyTypePostFailureCount();
\r
1142 mgr.updateApiCallFailureCount();
\r
1143 mgr.updateTotalPolicyTypeDeleteCount();
\r
1144 mgr.updatePolicyTypeDeleteFailureCount();
\r
1147 mgr.updateApiCallFailureCount();
\r