351a35826db4f4d5f5bf1b7476ee545de4a9f079
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / apihandlerinfra / NodeHealthcheckHandler.java
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 java.net.UnknownHostException;
26
27 import javax.transaction.Transactional;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.container.ContainerRequestContext;
32 import javax.ws.rs.core.Context;
33 import javax.ws.rs.core.Response;
34
35 import org.apache.http.HttpStatus;
36 import org.onap.so.logger.MessageEnum;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.stereotype.Component;
40
41 import io.swagger.annotations.Api;
42 import io.swagger.annotations.ApiOperation;
43
44 @Path("/nodehealthcheck")
45 @Api(value="/nodehealthcheck",description="API Handler Infra Node Health Check")
46 @Component
47 public class NodeHealthcheckHandler {
48
49     private static Logger logger = LoggerFactory.getLogger(NodeHealthcheckHandler.class);
50     
51     private static final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>";
52
53         public static final Response HEALTH_CHECK_RESPONSE = Response.status (HttpStatus.SC_OK)
54             .entity (CHECK_HTML)
55             .build ();   
56     
57     @GET
58     @Produces("text/html")
59         @ApiOperation(value="Performing node health check",response=Response.class)
60     @Transactional
61     public Response nodeHealthcheck (@Context ContainerRequestContext requestContext) throws UnknownHostException {
62         // Generated RequestId
63         String requestId = requestContext.getProperty("requestId").toString();
64         logger.info("{} {}", MessageEnum.APIH_GENERATED_REQUEST_ID.toString(), requestId);
65         return HEALTH_CHECK_RESPONSE;
66     }
67 }