2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pdpx.main.rest;
23 import io.swagger.annotations.Api;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
27 import io.swagger.annotations.Authorization;
28 import io.swagger.annotations.BasicAuthDefinition;
29 import io.swagger.annotations.Info;
30 import io.swagger.annotations.SecurityDefinition;
31 import io.swagger.annotations.SwaggerDefinition;
32 import io.swagger.annotations.Tag;
33 import javax.ws.rs.Consumes;
34 import javax.ws.rs.GET;
35 import javax.ws.rs.POST;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.core.MediaType;
39 import javax.ws.rs.core.Response;
40 import org.onap.policy.common.endpoints.report.HealthCheckReport;
41 import org.onap.policy.pdpx.main.rest.model.Decision;
42 import org.onap.policy.pdpx.main.rest.model.StatisticsReport;
43 import org.onap.policy.pdpx.main.rest.provider.DecisionProvider;
44 import org.onap.policy.pdpx.main.rest.provider.HealthCheckProvider;
45 import org.onap.policy.pdpx.main.rest.provider.StatisticsProvider;
48 * Class to provide xacml pdp REST services.
51 @Path("/policy/pdpx/v1")
53 @Produces(MediaType.APPLICATION_JSON)
54 @Consumes(MediaType.APPLICATION_JSON)
55 @SwaggerDefinition(info = @Info(description = "Policy Xacml PDP Service", version = "v1.0", title = "Policy Xacml PDP"),
56 consumes = {MediaType.APPLICATION_JSON}, produces = {MediaType.APPLICATION_JSON},
57 schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
58 tags = {@Tag(name = "policy-pdpx", description = "Policy Xacml PDP Service Operations")},
59 securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
60 public class XacmlPdpRestController {
64 @ApiOperation(value = "Perform a system healthcheck",
65 notes = "Provides healthy status of the Policy Xacml PDP component", response = HealthCheckReport.class,
66 authorizations = @Authorization(value = "basicAuth"))
67 @ApiResponses(value = {
68 @ApiResponse(code = 401, message = "Authentication Error"),
69 @ApiResponse(code = 403, message = "Authorization Error"),
70 @ApiResponse(code = 500, message = "Internal Server Error")})
71 public Response healthcheck() {
72 return Response.status(Response.Status.OK).entity(new HealthCheckProvider().performHealthCheck()).build();
77 @ApiOperation(value = "Fetch current statistics",
78 notes = "Provides current statistics of the Policy Xacml PDP component", response = StatisticsReport.class,
79 authorizations = @Authorization(value = "basicAuth"))
80 @ApiResponses(value = {
81 @ApiResponse(code = 401, message = "Authentication Error"),
82 @ApiResponse(code = 403, message = "Authorization Error"),
83 @ApiResponse(code = 500, message = "Internal Server Error")})
84 public Response statistics() {
85 return Response.status(Response.Status.OK).entity(new StatisticsProvider().fetchCurrentStatistics()).build();
90 @ApiOperation(value = "Fetch the decision using specified decision parameters",
91 notes = "Returns the policy decision from Policy Xacml PDP", response = Decision.class,
92 authorizations = @Authorization(value = "basicAuth"),
94 @ApiResponses(value = {@ApiResponse(code = 400, message = "Bad Request"),
95 @ApiResponse(code = 401, message = "Authentication Error"),
96 @ApiResponse(code = 403, message = "Authorization Error"),
97 @ApiResponse(code = 500, message = "Internal Server Error")})
98 public Response decision(Decision body) {
99 return Response.status(Response.Status.OK).entity(new DecisionProvider().fetchDecision()).build();