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