2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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.apex.services.onappf.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;
34 import java.net.HttpURLConnection;
36 import javax.ws.rs.GET;
37 import javax.ws.rs.Path;
38 import javax.ws.rs.Produces;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
42 import org.onap.policy.common.endpoints.report.HealthCheckReport;
45 * Class to provide REST endpoints for services-onappf component health check.
47 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
50 @Path("/policy/apex-pdp/v1")
51 @Api(value = "PDP-A API")
52 @Produces(MediaType.APPLICATION_JSON)
54 info = @Info(description =
55 "PDP-A is responsible for making policy decisions and for managing the administrative"
56 + " state of the PDPs as directed by PolicyAdministration", version = "v1.0",
58 consumes = {MediaType.APPLICATION_JSON},
59 produces = {MediaType.APPLICATION_JSON},
60 schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
61 tags = {@Tag(name = "PDP-A", description = "PDP-A Operations")},
62 securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")}))
64 public class HealthCheckRestControllerV1 {
66 public static final String AUTHORIZATION_TYPE = "basicAuth";
68 public static final int AUTHENTICATION_ERROR_CODE = HttpURLConnection.HTTP_UNAUTHORIZED;
69 public static final int AUTHORIZATION_ERROR_CODE = HttpURLConnection.HTTP_FORBIDDEN;
70 public static final int SERVER_ERROR_CODE = HttpURLConnection.HTTP_INTERNAL_ERROR;
72 public static final String AUTHENTICATION_ERROR_MESSAGE = "Authentication Error";
73 public static final String AUTHORIZATION_ERROR_MESSAGE = "Authorization Error";
74 public static final String SERVER_ERROR_MESSAGE = "Internal Server Error";
78 @ApiOperation(value = "Perform healthcheck", notes = "Returns healthy status of the PDP-A component",
79 response = HealthCheckReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE))
80 @ApiResponses(value = { @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
81 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
82 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) })
83 public Response healthcheck() {
84 return Response.status(Response.Status.OK).entity(new HealthCheckProvider().performHealthCheck()).build();