e56ee24baf2e55ccad440df239594d7127baec3e
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.apihandlerinfra;
24
25 import io.swagger.v3.oas.annotations.OpenAPIDefinition;
26 import io.swagger.v3.oas.annotations.Operation;
27 import io.swagger.v3.oas.annotations.info.Info;
28 import io.swagger.v3.oas.annotations.media.ArraySchema;
29 import io.swagger.v3.oas.annotations.media.Content;
30 import io.swagger.v3.oas.annotations.media.Schema;
31 import io.swagger.v3.oas.annotations.responses.ApiResponse;
32 import org.apache.http.HttpStatus;
33 import org.onap.so.logger.LoggingAnchor;
34 import org.onap.so.logger.MessageEnum;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.stereotype.Component;
38 import javax.transaction.Transactional;
39 import javax.ws.rs.GET;
40 import javax.ws.rs.Path;
41 import javax.ws.rs.Produces;
42 import javax.ws.rs.container.ContainerRequestContext;
43 import javax.ws.rs.core.Context;
44 import javax.ws.rs.core.Response;
45 import java.net.UnknownHostException;
46
47 @Path("/nodehealthcheck")
48 @OpenAPIDefinition(info = @Info(title = "/nodehealthcheck", description = "API Handler Infra Node Health Check"))
49 @Component
50 public class NodeHealthcheckHandler {
51
52     private static Logger logger = LoggerFactory.getLogger(NodeHealthcheckHandler.class);
53
54     private static final String CHECK_HTML =
55             "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>";
56
57     public static final Response HEALTH_CHECK_RESPONSE = Response.status(HttpStatus.SC_OK).entity(CHECK_HTML).build();
58
59     @GET
60     @Produces("text/html")
61     @Operation(description = "Performing node health check", responses = @ApiResponse(
62             content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
63     @Transactional
64     public Response nodeHealthcheck(@Context ContainerRequestContext requestContext) throws UnknownHostException {
65         // Generated RequestId
66         String requestId = requestContext.getProperty("requestId").toString();
67         logger.info(LoggingAnchor.TWO, MessageEnum.APIH_GENERATED_REQUEST_ID.toString(), requestId);
68         return HEALTH_CHECK_RESPONSE;
69     }
70 }