0191b546e38e5d9a1b349636ba47e6b736250584
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / openecomp / mso / apihandlerinfra / NodeHealthcheckHandler.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.mso.apihandlerinfra;\r
22 \r
23 import javax.ws.rs.GET;\r
24 import javax.ws.rs.HEAD;\r
25 import javax.ws.rs.Path;\r
26 import javax.ws.rs.Produces;\r
27 import javax.ws.rs.core.Response;\r
28 \r
29 import org.openecomp.mso.HealthCheckUtils;\r
30 import org.openecomp.mso.logger.MsoLogger;\r
31 import org.openecomp.mso.utils.UUIDChecker;\r
32 \r
33 import com.wordnik.swagger.annotations.Api;\r
34 import com.wordnik.swagger.annotations.ApiOperation;\r
35 \r
36 @Path("/nodehealthcheck")\r
37 @Api(value="/nodehealthcheck",description="API Handler Infra Node Health Check")\r
38 public class NodeHealthcheckHandler {\r
39 \r
40         public final static String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";\r
41 \r
42     private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);\r
43 \r
44         @HEAD\r
45     @GET\r
46     @Produces("text/html")\r
47         @ApiOperation(value="Performing node health check",response=Response.class)\r
48     public Response nodeHealthcheck () {\r
49         long startTime = System.currentTimeMillis ();\r
50         MsoLogger.setServiceName ("NodeHealthcheck");\r
51         // Generate a Request Id\r
52         String requestId = UUIDChecker.generateUUID(msoLogger);\r
53         HealthCheckUtils healthCheck = new HealthCheckUtils ();\r
54         if (!healthCheck.siteStatusCheck (msoLogger)) {\r
55             return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;\r
56         }\r
57 \r
58         if (healthCheck.verifyNodeHealthCheck(HealthCheckUtils.NodeType.APIH, requestId)) {\r
59             msoLogger.debug("nodeHealthcheck - Successful");\r
60             return HealthCheckUtils.HEALTH_CHECK_RESPONSE;\r
61         } else {\r
62             msoLogger.debug("nodeHealthcheck - At leaset one of the sub-modules is not available.");\r
63             return  HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;\r
64         }\r
65     }\r
66 }\r