2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
\r
6 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
\r
7 * Modifications Copyright (C) 2020 Nordix Foundation.
\r
8 * Modifications Copyright (C) 2020 Bell Canada.
\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.Consumes;
\r
45 import javax.ws.rs.DELETE;
\r
46 import javax.ws.rs.DefaultValue;
\r
47 import javax.ws.rs.GET;
\r
48 import javax.ws.rs.HeaderParam;
\r
49 import javax.ws.rs.POST;
\r
50 import javax.ws.rs.Path;
\r
51 import javax.ws.rs.PathParam;
\r
52 import javax.ws.rs.Produces;
\r
53 import javax.ws.rs.QueryParam;
\r
54 import javax.ws.rs.core.Response;
\r
55 import javax.ws.rs.core.Response.Status;
\r
56 import org.onap.policy.api.main.rest.provider.HealthCheckProvider;
\r
57 import org.onap.policy.api.main.rest.provider.PolicyProvider;
\r
58 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;
\r
59 import org.onap.policy.api.main.rest.provider.StatisticsProvider;
\r
60 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
\r
61 import org.onap.policy.common.endpoints.report.HealthCheckReport;
\r
62 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
\r
63 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
\r
64 import org.onap.policy.models.base.PfModelException;
\r
65 import org.onap.policy.models.base.PfModelRuntimeException;
\r
66 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
67 import org.slf4j.Logger;
\r
68 import org.slf4j.LoggerFactory;
\r
71 * Class to provide REST API services.
\r
73 * @author Chenfei Gao (cgao@research.att.com)
\r
75 @Path("/policy/api/v1")
\r
76 @Api(value = "Policy Design API")
\r
77 @Produces({"application/json", "application/yaml"})
\r
78 @Consumes({"application/json", "application/yaml"})
\r
81 description = "Policy Design API is publicly exposed for clients to Create/Read/Update/Delete"
\r
82 + " policy types, policy type implementation and policies which can be recognized"
\r
83 + " and executable by incorporated policy engines. It is an"
\r
84 + " independent component running rest service that takes all policy design API calls"
\r
85 + " from clients and then assign them to different API working functions. Besides"
\r
86 + " that, API is also exposed for clients to retrieve healthcheck status of this API"
\r
87 + " rest service and the statistics report including the counters of API invocation.",
\r
88 version = "1.0.0", title = "Policy Design",
\r
89 extensions = {@Extension(properties = {@ExtensionProperty(name = "planned-retirement-date", value = "tbd"),
\r
90 @ExtensionProperty(name = "component", value = "Policy Framework")})}),
\r
91 schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
\r
92 securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
\r
93 public class ApiRestController extends CommonRestController {
\r
95 private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);
\r
97 private static final String ERROR_MESSAGE_NO_POLICIES_FOUND = "No policies found";
\r
99 private static final String EXTENSION_NAME = "interface info";
\r
101 private static final String API_VERSION_NAME = "api-version";
\r
102 private static final String API_VERSION = "1.0.0";
\r
104 private static final String LAST_MOD_NAME = "last-mod-release";
\r
106 private static final String AUTHORIZATION_TYPE = "basicAuth";
\r
108 private static final String VERSION_MINOR_NAME = "X-MinorVersion";
\r
109 private static final String VERSION_MINOR_DESCRIPTION =
\r
110 "Used to request or communicate a MINOR version back from the client"
\r
111 + " to the server, and from the server back to the client";
\r
113 private static final String VERSION_PATCH_NAME = "X-PatchVersion";
\r
114 private static final String VERSION_PATCH_DESCRIPTION = "Used only to communicate a PATCH version in a response for"
\r
115 + " troubleshooting purposes only, and will not be provided by" + " the client on request";
\r
117 private static final String VERSION_LATEST_NAME = "X-LatestVersion";
\r
118 private static final String VERSION_LATEST_DESCRIPTION = "Used only to communicate an API's latest version";
\r
120 private static final String REQUEST_ID_NAME = "X-ONAP-RequestID";
\r
121 private static final String REQUEST_ID_HDR_DESCRIPTION = "Used to track REST transactions for logging purpose";
\r
122 private static final String REQUEST_ID_PARAM_DESCRIPTION = "RequestID for http transaction";
\r
124 private static final String AUTHENTICATION_ERROR_MESSAGE = "Authentication Error";
\r
125 private static final String AUTHORIZATION_ERROR_MESSAGE = "Authorization Error";
\r
126 private static final String SERVER_ERROR_MESSAGE = "Internal Server Error";
\r
127 private static final String NOT_FOUND_MESSAGE = "Resource Not Found";
\r
128 private static final String INVALID_BODY_MESSAGE = "Invalid Body";
\r
129 private static final String INVALID_PAYLOAD_MESSAGE = "Not Acceptable Payload";
\r
130 private static final String HTTP_CONFLICT_MESSAGE = "Delete Conflict, Rule Violation";
\r
134 * Retrieves the healthcheck status of the API component.
\r
136 * @return the Response object containing the results of the API operation
\r
139 @Path("/healthcheck")
\r
140 @ApiOperation(value = "Perform a system healthcheck", notes = "Returns healthy status of the Policy API component",
\r
141 response = HealthCheckReport.class,
\r
142 responseHeaders = {
\r
143 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
144 description = VERSION_MINOR_DESCRIPTION,
\r
145 response = String.class),
\r
146 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
147 description = VERSION_PATCH_DESCRIPTION,
\r
148 response = String.class),
\r
149 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
150 response = String.class),
\r
151 @ResponseHeader(name = REQUEST_ID_NAME,
\r
152 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
153 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"HealthCheck", },
\r
155 @Extension(name = EXTENSION_NAME, properties = {
\r
156 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
157 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
158 @ApiResponses(value = {
\r
159 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
160 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
161 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
163 getHealthCheck(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
165 updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
\r
166 return makeOkResponse(requestId, new HealthCheckProvider().performHealthCheck());
\r
170 * Retrieves the statistics report of the API component.
\r
172 * @return the Response object containing the results of the API operation
\r
175 @Path("/statistics")
\r
176 @ApiOperation(value = "Retrieve current statistics",
\r
177 notes = "Returns current statistics including the counters of API invocation",
\r
178 response = StatisticsReport.class,
\r
179 responseHeaders = {
\r
180 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
181 description = VERSION_MINOR_DESCRIPTION,
\r
182 response = String.class),
\r
183 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
184 description = VERSION_PATCH_DESCRIPTION,
\r
185 response = String.class),
\r
186 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
187 response = String.class),
\r
188 @ResponseHeader(name = REQUEST_ID_NAME,
\r
189 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
190 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Statistics", },
\r
192 @Extension(name = EXTENSION_NAME, properties = {
\r
193 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
194 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
195 @ApiResponses(value = {
\r
196 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
197 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
198 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
200 getStatistics(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
202 updateApiStatisticsCounter(Target.OTHER, Result.SUCCESS, HttpMethod.GET);
\r
204 return makeOkResponse(requestId, new StatisticsProvider().fetchCurrentStatistics());
\r
208 * Retrieves all available policy types.
\r
210 * @return the Response object containing the results of the API operation
\r
213 @Path("/policytypes")
\r
214 @ApiOperation(value = "Retrieve existing policy types",
\r
215 notes = "Returns a list of existing policy types stored in Policy Framework",
\r
216 response = ToscaServiceTemplate.class,
\r
217 responseHeaders = {
\r
218 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
219 description = VERSION_MINOR_DESCRIPTION,
\r
220 response = String.class),
\r
221 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
222 description = VERSION_PATCH_DESCRIPTION,
\r
223 response = String.class),
\r
224 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
225 response = String.class),
\r
226 @ResponseHeader(name = REQUEST_ID_NAME,
\r
227 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
228 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
230 @Extension(name = EXTENSION_NAME, properties = {
\r
231 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
232 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
233 @ApiResponses(value = {
\r
234 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
235 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
236 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
238 getAllPolicyTypes(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
240 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
241 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);
\r
242 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
243 return makeOkResponse(requestId, serviceTemplate);
\r
244 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
245 LOGGER.warn("GET /policytypes", pfme);
\r
246 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
247 return makeErrorResponse(requestId, pfme);
\r
252 * Retrieves all versions of a particular policy type.
\r
254 * @param policyTypeId the ID of specified policy type
\r
256 * @return the Response object containing the results of the API operation
\r
259 @Path("/policytypes/{policyTypeId}")
\r
260 @ApiOperation(value = "Retrieve all available versions of a policy type",
\r
261 notes = "Returns a list of all available versions for the specified policy type",
\r
262 response = ToscaServiceTemplate.class,
\r
263 responseHeaders = {
\r
264 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
265 description = VERSION_MINOR_DESCRIPTION,
\r
266 response = String.class),
\r
267 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
268 description = VERSION_PATCH_DESCRIPTION,
\r
269 response = String.class),
\r
270 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
271 response = String.class),
\r
272 @ResponseHeader(name = REQUEST_ID_NAME,
\r
273 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
274 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
276 @Extension(name = EXTENSION_NAME, properties = {
\r
277 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
278 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
279 @ApiResponses(value = {
\r
280 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
281 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
282 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
283 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
284 public Response getAllVersionsOfPolicyType(
\r
285 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
286 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
288 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
289 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);
\r
290 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
291 return makeOkResponse(requestId, serviceTemplate);
\r
292 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
293 LOGGER.warn("GET /policytypes/{}", policyTypeId, pfme);
\r
294 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
295 return makeErrorResponse(requestId, pfme);
\r
300 * Retrieves specified version of a particular policy type.
\r
302 * @param policyTypeId the ID of specified policy type
\r
303 * @param versionId the version of specified policy type
\r
305 * @return the Response object containing the results of the API operation
\r
308 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
309 @ApiOperation(value = "Retrieve one particular version of a policy type",
\r
310 notes = "Returns a particular version for the specified policy type", response = ToscaServiceTemplate.class,
\r
311 responseHeaders = {
\r
312 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
313 description = VERSION_MINOR_DESCRIPTION,
\r
314 response = String.class),
\r
315 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
316 description = VERSION_PATCH_DESCRIPTION,
\r
317 response = String.class),
\r
318 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
319 response = String.class),
\r
320 @ResponseHeader(name = REQUEST_ID_NAME,
\r
321 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
322 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
324 @Extension(name = EXTENSION_NAME, properties = {
\r
325 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
326 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
327 @ApiResponses(value = {
\r
328 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
329 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
330 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
331 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
332 public Response getSpecificVersionOfPolicyType(
\r
333 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
334 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
335 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
337 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
338 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);
\r
339 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
340 return makeOkResponse(requestId, serviceTemplate);
\r
341 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
342 LOGGER.warn("GET /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
\r
343 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
344 return makeErrorResponse(requestId, pfme);
\r
349 * Retrieves latest version of a particular policy type.
\r
351 * @param policyTypeId the ID of specified policy type
\r
353 * @return the Response object containing the results of the API operation
\r
356 @Path("/policytypes/{policyTypeId}/versions/latest")
\r
357 @ApiOperation(value = "Retrieve latest version of a policy type",
\r
358 notes = "Returns latest version for the specified policy type", response = ToscaServiceTemplate.class,
\r
359 responseHeaders = {
\r
360 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
361 description = VERSION_MINOR_DESCRIPTION,
\r
362 response = String.class),
\r
363 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
364 description = VERSION_PATCH_DESCRIPTION,
\r
365 response = String.class),
\r
366 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
367 response = String.class),
\r
368 @ResponseHeader(name = REQUEST_ID_NAME,
\r
369 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
370 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
372 @Extension(name = EXTENSION_NAME, properties = {
\r
373 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
374 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
375 @ApiResponses(value = {
\r
376 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
377 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
378 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
379 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
380 public Response getLatestVersionOfPolicyType(
\r
381 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
382 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
384 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
385 ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
\r
386 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
\r
387 return makeOkResponse(requestId, serviceTemplate);
\r
388 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
389 LOGGER.warn("GET /policytypes/{}/versions/latest", policyTypeId, pfme);
\r
390 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
\r
391 return makeErrorResponse(requestId, pfme);
\r
396 * Creates a new policy type.
\r
398 * @param body the body of policy type following TOSCA definition
\r
400 * @return the Response object containing the results of the API operation
\r
403 @Path("/policytypes")
\r
404 @ApiOperation(value = "Create a new policy type", notes = "Client should provide TOSCA body of the new policy type",
\r
405 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
406 response = ToscaServiceTemplate.class,
\r
407 responseHeaders = {
\r
408 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
409 description = VERSION_MINOR_DESCRIPTION,
\r
410 response = String.class),
\r
411 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
412 description = VERSION_PATCH_DESCRIPTION,
\r
413 response = String.class),
\r
414 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
415 response = String.class),
\r
416 @ResponseHeader(name = REQUEST_ID_NAME,
\r
417 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
419 @Extension(name = EXTENSION_NAME, properties = {
\r
420 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
421 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
422 @ApiResponses(value = {
\r
423 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
424 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
425 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
426 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
427 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
428 public Response createPolicyType(
\r
429 @ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,
\r
430 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
432 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
433 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
\r
436 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
437 ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);
\r
438 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);
\r
439 return makeOkResponse(requestId, serviceTemplate);
\r
440 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
441 LOGGER.warn("POST /policytypes", pfme);
\r
442 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.POST);
\r
443 return makeErrorResponse(requestId, pfme);
\r
448 * Deletes specified version of a particular policy type.
\r
450 * @param policyTypeId the ID of specified policy type
\r
451 * @param versionId the version of specified policy type
\r
453 * @return the Response object containing the results of the API operation
\r
456 @Path("/policytypes/{policyTypeId}/versions/{versionId}")
\r
457 @ApiOperation(value = "Delete one version of a policy type",
\r
458 notes = "Rule 1: pre-defined policy types cannot be deleted;"
\r
459 + "Rule 2: policy types that are in use (parameterized by a TOSCA policy) cannot be deleted."
\r
460 + "The parameterizing TOSCA policies must be deleted first;",
\r
461 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"PolicyType", },
\r
462 response = ToscaServiceTemplate.class,
\r
463 responseHeaders = {
\r
464 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
465 description = VERSION_MINOR_DESCRIPTION,
\r
466 response = String.class),
\r
467 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
468 description = VERSION_PATCH_DESCRIPTION,
\r
469 response = String.class),
\r
470 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
471 response = String.class),
\r
472 @ResponseHeader(name = REQUEST_ID_NAME,
\r
473 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
475 @Extension(name = EXTENSION_NAME, properties = {
\r
476 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
477 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
478 @ApiResponses(value = {
\r
479 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
480 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
481 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
482 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
483 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
484 public Response deleteSpecificVersionOfPolicyType(
\r
485 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
486 @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
\r
487 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
489 try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
\r
490 ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);
\r
491 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.DELETE);
\r
492 return makeOkResponse(requestId, serviceTemplate);
\r
493 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
494 LOGGER.warn("DELETE /policytypes/{}/versions/{}", policyTypeId, versionId, pfme);
\r
495 updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.DELETE);
\r
496 return makeErrorResponse(requestId, pfme);
\r
501 * Retrieves all versions of a particular policy.
\r
503 * @param policyTypeId the ID of specified policy type
\r
504 * @param policyTypeVersion the version of specified policy type
\r
506 * @return the Response object containing the results of the API operation
\r
509 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
511 value = "Retrieve all versions of a policy created for a particular policy type version",
\r
512 notes = "Returns a list of all versions of specified policy created for the specified policy type version",
\r
513 response = ToscaServiceTemplate.class,
\r
514 responseHeaders = {
\r
515 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
516 description = VERSION_MINOR_DESCRIPTION,
\r
517 response = String.class),
\r
518 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
519 description = VERSION_PATCH_DESCRIPTION,
\r
520 response = String.class),
\r
521 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
522 response = String.class),
\r
523 @ResponseHeader(name = REQUEST_ID_NAME,
\r
524 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
525 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy,"},
\r
527 @Extension(name = EXTENSION_NAME, properties = {
\r
528 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
529 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
533 @ApiResponses(value = {
\r
534 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
535 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
536 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
537 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
539 public Response getAllPolicies(
\r
540 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
541 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
542 required = true) String policyTypeVersion,
\r
543 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
544 @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
545 + " REFERENCED for fully referenced policies") PolicyFetchMode mode
\r
548 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
549 ToscaServiceTemplate serviceTemplate =
\r
550 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
\r
551 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
552 return makeOkResponse(requestId, serviceTemplate);
\r
553 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
554 LOGGER.warn("GET /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
\r
555 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
556 return makeErrorResponse(requestId, pfme);
\r
561 * Retrieves all versions of a particular policy.
\r
563 * @param policyTypeId the ID of specified policy type
\r
564 * @param policyTypeVersion the version of specified policy type
\r
565 * @param policyId the ID of specified policy
\r
567 * @return the Response object containing the results of the API operation
\r
570 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}")
\r
571 @ApiOperation(value = "Retrieve all version details of a policy created for a particular policy type version",
\r
572 notes = "Returns a list of all version details of the specified policy", response = ToscaServiceTemplate.class,
\r
573 responseHeaders = {
\r
574 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
575 description = VERSION_MINOR_DESCRIPTION,
\r
576 response = String.class),
\r
577 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
578 description = VERSION_PATCH_DESCRIPTION,
\r
579 response = String.class),
\r
580 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
581 response = String.class),
\r
582 @ResponseHeader(name = REQUEST_ID_NAME,
\r
583 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
584 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
586 @Extension(name = EXTENSION_NAME, properties = {
\r
587 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
588 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
592 @ApiResponses(value = {
\r
593 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
594 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
595 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
596 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
598 public Response getAllVersionsOfPolicy(
\r
599 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
600 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
601 required = true) String policyTypeVersion,
\r
602 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
603 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
604 @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
605 + " REFERENCED for fully referenced policies") PolicyFetchMode mode
\r
607 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
608 ToscaServiceTemplate serviceTemplate =
\r
609 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
\r
610 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
611 return makeOkResponse(requestId, serviceTemplate);
\r
612 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
613 LOGGER.warn("/policytypes/{}/versions/{}/policies/{}", policyTypeId, policyTypeVersion, policyId, pfme);
\r
614 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
615 return makeErrorResponse(requestId, pfme);
\r
620 * Retrieves the specified version of a particular policy.
\r
622 * @param policyTypeId the ID of specified policy type
\r
623 * @param policyTypeVersion the version of specified policy type
\r
624 * @param policyId the ID of specified policy
\r
625 * @param policyVersion the version of specified policy
\r
627 * @return the Response object containing the results of the API operation
\r
630 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
631 @ApiOperation(value = "Retrieve one version of a policy created for a particular policy type version",
\r
632 notes = "Returns a particular version of specified policy created for the specified policy type version",
\r
633 response = ToscaServiceTemplate.class,
\r
634 responseHeaders = {
\r
635 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
636 description = VERSION_MINOR_DESCRIPTION,
\r
637 response = String.class),
\r
638 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
639 description = VERSION_PATCH_DESCRIPTION,
\r
640 response = String.class),
\r
641 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
642 response = String.class),
\r
643 @ResponseHeader(name = REQUEST_ID_NAME,
\r
644 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
645 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
647 @Extension(name = EXTENSION_NAME, properties = {
\r
648 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
649 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")
\r
653 @ApiResponses(value = {
\r
654 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
655 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
656 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
657 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
659 public Response getSpecificVersionOfPolicy(
\r
660 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
661 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
662 required = true) String policyTypeVersion,
\r
663 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
664 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
665 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
666 @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
667 + " REFERENCED for fully referenced policies") PolicyFetchMode mode
\r
669 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
670 ToscaServiceTemplate serviceTemplate =
\r
671 policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
\r
672 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
673 return makeOkResponse(requestId, serviceTemplate);
\r
674 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
675 LOGGER.warn("GET /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
\r
676 policyId, policyVersion, pfme);
\r
677 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
678 return makeErrorResponse(requestId, pfme);
\r
683 * Retrieves the latest version of a particular policy.
\r
685 * @param policyTypeId the ID of specified policy type
\r
686 * @param policyTypeVersion the version of specified policy type
\r
687 * @param policyId the ID of specified policy
\r
689 * @return the Response object containing the results of the API operation
\r
692 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
\r
693 @ApiOperation(value = "Retrieve the latest version of a particular policy",
\r
694 notes = "Returns the latest version of specified policy", response = ToscaServiceTemplate.class,
\r
695 responseHeaders = {
\r
696 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
697 description = VERSION_MINOR_DESCRIPTION,
\r
698 response = String.class),
\r
699 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
700 description = VERSION_PATCH_DESCRIPTION,
\r
701 response = String.class),
\r
702 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
703 response = String.class),
\r
704 @ResponseHeader(name = REQUEST_ID_NAME,
\r
705 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
706 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
708 @Extension(name = EXTENSION_NAME, properties = {
\r
709 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
710 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
711 @ApiResponses(value = {
\r
712 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
713 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
714 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
715 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
716 public Response getLatestVersionOfPolicy(
\r
717 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
718 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
719 required = true) String policyTypeVersion,
\r
720 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
721 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
722 @QueryParam("mode") @ApiParam("Fetch mode for policies, TERSE for bare policies (default), "
\r
723 + "REFERENCED for fully referenced policies") PolicyFetchMode mode) {
\r
725 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
726 ToscaServiceTemplate serviceTemplate =
\r
727 policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
\r
728 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
729 return makeOkResponse(requestId, serviceTemplate);
\r
730 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
731 LOGGER.warn("GET /policytypes/{}/versions/{}/policies/{}/versions/latest", policyTypeId, policyTypeVersion,
\r
733 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
734 return makeErrorResponse(requestId, pfme);
\r
739 * Creates a new policy for a particular policy type and version.
\r
741 * @param policyTypeId the ID of specified policy type
\r
742 * @param policyTypeVersion the version of specified policy type
\r
743 * @param body the body of policy following TOSCA definition
\r
745 * @return the Response object containing the results of the API operation
\r
748 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
\r
749 @ApiOperation(value = "Create a new policy for a policy type version",
\r
750 notes = "Client should provide TOSCA body of the new policy",
\r
751 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
752 response = ToscaServiceTemplate.class,
\r
753 responseHeaders = {
\r
754 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
755 description = VERSION_MINOR_DESCRIPTION,
\r
756 response = String.class),
\r
757 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
758 description = VERSION_PATCH_DESCRIPTION,
\r
759 response = String.class),
\r
760 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
761 response = String.class),
\r
762 @ResponseHeader(name = REQUEST_ID_NAME,
\r
763 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
765 @Extension(name = EXTENSION_NAME, properties = {
\r
766 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
767 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
768 @ApiResponses(value = {
\r
769 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
770 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
771 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
772 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
773 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
774 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
775 public Response createPolicy(
\r
776 @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
\r
777 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
778 required = true) String policyTypeVersion,
\r
779 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
780 @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
782 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
783 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
\r
784 "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
\r
787 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
788 ToscaServiceTemplate serviceTemplate = policyProvider.createPolicy(policyTypeId, policyTypeVersion, body);
\r
789 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
\r
790 return makeOkResponse(requestId, serviceTemplate);
\r
791 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
792 LOGGER.warn("POST /policytypes/{}/versions/{}/policies", policyTypeId, policyTypeVersion, pfme);
\r
793 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
\r
794 return makeErrorResponse(requestId, pfme);
\r
799 * Deletes the specified version of a particular policy.
\r
801 * @param policyTypeId the ID of specified policy type
\r
802 * @param policyTypeVersion the version of specified policy type
\r
803 * @param policyId the ID of specified policy
\r
804 * @param policyVersion the version of specified policy
\r
806 * @return the Response object containing the results of the API operation
\r
809 @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/{policyVersion}")
\r
810 @ApiOperation(value = "Delete a particular version of a policy",
\r
811 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
812 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
813 response = ToscaServiceTemplate.class,
\r
814 responseHeaders = {
\r
815 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
816 description = VERSION_MINOR_DESCRIPTION,
\r
817 response = String.class),
\r
818 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
819 description = VERSION_PATCH_DESCRIPTION,
\r
820 response = String.class),
\r
821 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
822 response = String.class),
\r
823 @ResponseHeader(name = REQUEST_ID_NAME,
\r
824 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
826 @Extension(name = EXTENSION_NAME, properties = {
\r
827 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
828 @ExtensionProperty(name = LAST_MOD_NAME, value = "Dublin")})})
\r
829 @ApiResponses(value = {
\r
830 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
831 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
832 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
833 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
834 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
835 public Response deleteSpecificVersionOfPolicy(
\r
836 @PathParam("policyTypeId") @ApiParam(value = "PolicyType ID", required = true) String policyTypeId,
\r
837 @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",
\r
838 required = true) String policyTypeVersion,
\r
839 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
840 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
841 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
843 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
844 ToscaServiceTemplate serviceTemplate =
\r
845 policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
846 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.DELETE);
\r
847 return makeOkResponse(requestId, serviceTemplate);
\r
848 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
849 LOGGER.warn("DELETE /policytypes/{}/versions/{}/policies/{}/versions/{}", policyTypeId, policyTypeVersion,
\r
850 policyId, policyVersion, pfme);
\r
851 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.DELETE);
\r
852 return makeErrorResponse(requestId, pfme);
\r
857 * Retrieves all the available policies.
\r
859 * @return the Response object containing the results of the API operation
\r
863 @ApiOperation(value = "Retrieve all versions of available policies",
\r
864 notes = "Returns all version of available policies",
\r
865 response = ToscaServiceTemplate.class,
\r
866 responseHeaders = {
\r
867 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
868 description = VERSION_MINOR_DESCRIPTION,
\r
869 response = String.class),
\r
870 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
871 description = VERSION_PATCH_DESCRIPTION,
\r
872 response = String.class),
\r
873 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
874 response = String.class),
\r
875 @ResponseHeader(name = REQUEST_ID_NAME,
\r
876 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
877 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
879 @Extension(name = EXTENSION_NAME, properties = {
\r
880 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
881 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")
\r
885 @ApiResponses(value = {
\r
886 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
887 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
888 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
889 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
891 public Response getPolicies(
\r
892 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
893 @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
894 + " REFERENCED for fully referenced policies") PolicyFetchMode mode
\r
896 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
897 ToscaServiceTemplate serviceTemplate =
\r
898 policyProvider.fetchPolicies(null, null, null, null, mode);
\r
899 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
900 return makeOkResponse(requestId, serviceTemplate);
\r
901 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
902 LOGGER.warn("GET /policies/ --", pfme);
\r
903 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
904 if (pfme.getErrorResponse().getResponseCode().equals(Status.NOT_FOUND)) {
\r
905 pfme.getErrorResponse().setErrorMessage(ERROR_MESSAGE_NO_POLICIES_FOUND);
\r
906 pfme.getErrorResponse().setErrorDetails(List.of(ERROR_MESSAGE_NO_POLICIES_FOUND));
\r
908 return makeErrorResponse(requestId, pfme);
\r
913 * Retrieves the specified version of a particular policy.
\r
915 * @param policyId the Name of specified policy
\r
916 * @param policyVersion the version of specified policy
\r
918 * @return the Response object containing the results of the API operation
\r
921 @Path("/policies/{policyId}/versions/{policyVersion}")
\r
922 @ApiOperation(value = "Retrieve specific version of a specified policy",
\r
923 notes = "Returns a particular version of specified policy",
\r
924 response = ToscaServiceTemplate.class,
\r
925 responseHeaders = {
\r
926 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
927 description = VERSION_MINOR_DESCRIPTION,
\r
928 response = String.class),
\r
929 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
930 description = VERSION_PATCH_DESCRIPTION,
\r
931 response = String.class),
\r
932 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
933 response = String.class),
\r
934 @ResponseHeader(name = REQUEST_ID_NAME,
\r
935 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
936 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
938 @Extension(name = EXTENSION_NAME, properties = {
\r
939 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
940 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")
\r
944 @ApiResponses(value = {
\r
945 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
946 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
947 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
948 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)
\r
950 public Response getSpecificPolicy(
\r
951 @PathParam("policyId") @ApiParam(value = "Name of policy", required = true) String policyId,
\r
952 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
953 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
954 @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
\r
955 + " REFERENCED for fully referenced policies") PolicyFetchMode mode
\r
957 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
958 ToscaServiceTemplate serviceTemplate =
\r
959 policyProvider.fetchPolicies(null, null, policyId, policyVersion, mode);
\r
960 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
\r
961 return makeOkResponse(requestId, serviceTemplate);
\r
962 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
963 LOGGER.warn("GET /policies/{}/versions/{}", policyId, policyVersion, pfme);
\r
964 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);
\r
965 return makeErrorResponse(requestId, pfme);
\r
970 * Creates one or more new policies in one call.
\r
972 * @param body the body of policy following TOSCA definition
\r
974 * @return the Response object containing the results of the API operation
\r
978 @ApiOperation(value = "Create one or more new policies",
\r
979 notes = "Client should provide TOSCA body of the new polic(ies)",
\r
980 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
981 response = ToscaServiceTemplate.class,
\r
982 responseHeaders = {
\r
983 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
984 description = VERSION_MINOR_DESCRIPTION,
\r
985 response = String.class),
\r
986 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
987 description = VERSION_PATCH_DESCRIPTION,
\r
988 response = String.class),
\r
989 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
990 response = String.class),
\r
991 @ResponseHeader(name = REQUEST_ID_NAME,
\r
992 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
994 @Extension(name = EXTENSION_NAME, properties = {
\r
995 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
996 @ExtensionProperty(name = LAST_MOD_NAME, value = "El Alto")})})
\r
997 @ApiResponses(value = {
\r
998 @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = INVALID_BODY_MESSAGE),
\r
999 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
1000 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
1001 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
1002 @ApiResponse(code = HttpURLConnection.HTTP_NOT_ACCEPTABLE, message = INVALID_PAYLOAD_MESSAGE),
\r
1003 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
1004 public Response createPolicies(
\r
1005 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
\r
1006 @ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {
\r
1008 if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
\r
1009 NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));
\r
1012 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
1013 ToscaServiceTemplate serviceTemplate = policyProvider.createPolicies(body);
\r
1014 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
\r
1015 return makeOkResponse(requestId, serviceTemplate);
\r
1016 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
1017 LOGGER.warn("POST /policies", pfme);
\r
1018 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.POST);
\r
1019 return makeErrorResponse(requestId, pfme);
\r
1024 * Deletes the specified version of a particular policy.
\r
1026 * @param policyId the ID of specified policy
\r
1027 * @param policyVersion the version of specified policy
\r
1029 * @return the Response object containing the results of the API operation
\r
1032 @Path("/policies/{policyId}/versions/{policyVersion}")
\r
1033 @ApiOperation(value = "Delete a particular version of a policy",
\r
1034 notes = "Rule: the version that has been deployed in PDP group(s) cannot be deleted",
\r
1035 authorizations = @Authorization(value = AUTHORIZATION_TYPE), tags = {"Policy", },
\r
1036 response = ToscaServiceTemplate.class,
\r
1037 responseHeaders = {
\r
1038 @ResponseHeader(name = VERSION_MINOR_NAME,
\r
1039 description = VERSION_MINOR_DESCRIPTION,
\r
1040 response = String.class),
\r
1041 @ResponseHeader(name = VERSION_PATCH_NAME,
\r
1042 description = VERSION_PATCH_DESCRIPTION,
\r
1043 response = String.class),
\r
1044 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
\r
1045 response = String.class),
\r
1046 @ResponseHeader(name = REQUEST_ID_NAME,
\r
1047 description = REQUEST_ID_HDR_DESCRIPTION, response = UUID.class)},
\r
1049 @Extension(name = EXTENSION_NAME, properties = {
\r
1050 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
\r
1051 @ExtensionProperty(name = LAST_MOD_NAME, value = "Guilin")})})
\r
1052 @ApiResponses(value = {
\r
1053 @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = AUTHENTICATION_ERROR_MESSAGE),
\r
1054 @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = AUTHORIZATION_ERROR_MESSAGE),
\r
1055 @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = NOT_FOUND_MESSAGE),
\r
1056 @ApiResponse(code = HttpURLConnection.HTTP_CONFLICT, message = HTTP_CONFLICT_MESSAGE),
\r
1057 @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = SERVER_ERROR_MESSAGE)})
\r
1058 public Response deleteSpecificPolicy(
\r
1059 @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
\r
1060 @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
\r
1061 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
\r
1063 try (PolicyProvider policyProvider = new PolicyProvider()) {
\r
1064 ToscaServiceTemplate serviceTemplate =
\r
1065 policyProvider.deletePolicy(null, null, policyId, policyVersion);
\r
1066 updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.DELETE);
\r
1067 return makeOkResponse(requestId, serviceTemplate);
\r
1068 } catch (PfModelException | PfModelRuntimeException pfme) {
\r
1069 LOGGER.warn("DELETE /policies/{}/versions/{}", policyId, policyVersion, pfme);
\r
1070 updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.DELETE);
\r
1071 return makeErrorResponse(requestId, pfme);
\r
1077 private enum Target {
\r
1083 private enum Result {
\r
1088 private enum HttpMethod {
\r
1094 private void updateApiStatisticsCounter(Target target, Result result, HttpMethod http) {
\r
1096 ApiStatisticsManager.updateTotalApiCallCount();
\r
1100 updatePolicyStats(result, http);
\r
1103 updatePolicyTypeStats(result, http);
\r
1106 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1111 private void updatePolicyStats(Result result, HttpMethod http) {
\r
1112 if (result == Result.SUCCESS) {
\r
1115 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1116 ApiStatisticsManager.updateTotalPolicyGetCount();
\r
1117 ApiStatisticsManager.updatePolicyGetSuccessCount();
\r
1120 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1121 ApiStatisticsManager.updateTotalPolicyPostCount();
\r
1122 ApiStatisticsManager.updatePolicyPostSuccessCount();
\r
1125 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1126 ApiStatisticsManager.updateTotalPolicyDeleteCount();
\r
1127 ApiStatisticsManager.updatePolicyDeleteSuccessCount();
\r
1130 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1136 ApiStatisticsManager.updateApiCallFailureCount();
\r
1137 ApiStatisticsManager.updateTotalPolicyGetCount();
\r
1138 ApiStatisticsManager.updatePolicyGetFailureCount();
\r
1141 ApiStatisticsManager.updateApiCallFailureCount();
\r
1142 ApiStatisticsManager.updateTotalPolicyPostCount();
\r
1143 ApiStatisticsManager.updatePolicyPostFailureCount();
\r
1146 ApiStatisticsManager.updateApiCallFailureCount();
\r
1147 ApiStatisticsManager.updateTotalPolicyDeleteCount();
\r
1148 ApiStatisticsManager.updatePolicyDeleteFailureCount();
\r
1151 ApiStatisticsManager.updateApiCallFailureCount();
\r
1157 private void updatePolicyTypeStats(Result result, HttpMethod http) {
\r
1158 if (result == Result.SUCCESS) {
\r
1161 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1162 ApiStatisticsManager.updateTotalPolicyTypeGetCount();
\r
1163 ApiStatisticsManager.updatePolicyTypeGetSuccessCount();
\r
1166 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1167 ApiStatisticsManager.updateTotalPolicyTypePostCount();
\r
1168 ApiStatisticsManager.updatePolicyTypePostSuccessCount();
\r
1171 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1172 ApiStatisticsManager.updateTotalPolicyTypeDeleteCount();
\r
1173 ApiStatisticsManager.updatePolicyTypeDeleteSuccessCount();
\r
1176 ApiStatisticsManager.updateApiCallSuccessCount();
\r
1182 ApiStatisticsManager.updateApiCallFailureCount();
\r
1183 ApiStatisticsManager.updateTotalPolicyTypeGetCount();
\r
1184 ApiStatisticsManager.updatePolicyTypeGetFailureCount();
\r
1187 ApiStatisticsManager.updateApiCallFailureCount();
\r
1188 ApiStatisticsManager.updateTotalPolicyTypePostCount();
\r
1189 ApiStatisticsManager.updatePolicyTypePostFailureCount();
\r
1192 ApiStatisticsManager.updateApiCallFailureCount();
\r
1193 ApiStatisticsManager.updateTotalPolicyTypeDeleteCount();
\r
1194 ApiStatisticsManager.updatePolicyTypeDeleteFailureCount();
\r
1197 ApiStatisticsManager.updateApiCallFailureCount();
\r