Containerization feature of SO
[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  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra;
22
23 import java.net.UnknownHostException;
24
25 import javax.transaction.Transactional;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.Path;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.container.ContainerRequestContext;
30 import javax.ws.rs.core.Context;
31 import javax.ws.rs.core.Response;
32
33 import org.apache.http.HttpStatus;
34 import org.onap.so.logger.MessageEnum;
35 import org.onap.so.logger.MsoLogger;
36 import org.onap.so.utils.UUIDChecker;
37 import org.springframework.stereotype.Component;
38
39 import io.swagger.annotations.Api;
40 import io.swagger.annotations.ApiOperation;
41
42 @Path("/nodehealthcheck")
43 @Api(value="/nodehealthcheck",description="API Handler Infra Node Health Check")
44 @Component
45 public class NodeHealthcheckHandler {
46
47     private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, NodeHealthcheckHandler.class);
48     
49     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>";
50
51         public static final Response HEALTH_CHECK_RESPONSE = Response.status (HttpStatus.SC_OK)
52             .entity (CHECK_HTML)
53             .build ();   
54     
55     @GET
56     @Produces("text/html")
57         @ApiOperation(value="Performing node health check",response=Response.class)
58     @Transactional
59     public Response nodeHealthcheck (@Context ContainerRequestContext requestContext) throws UnknownHostException {
60         long startTime = System.currentTimeMillis ();
61         MsoLogger.setServiceName ("NodeHealthcheck");
62         // Generated RequestId
63         String requestId = requestContext.getProperty("requestId").toString();
64         MsoLogger.setLogContext(requestId, null);
65         msoLogger.info(MessageEnum.APIH_GENERATED_REQUEST_ID, requestId, "", "");
66         return HEALTH_CHECK_RESPONSE;
67     }
68 }