Adding Junit
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / openecomp / mso / apihandlerinfra / GlobalHealthcheckHandler.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.DefaultValue;\r
24 import javax.ws.rs.GET;\r
25 import javax.ws.rs.HEAD;\r
26 import javax.ws.rs.Path;\r
27 import javax.ws.rs.Produces;\r
28 import javax.ws.rs.QueryParam;\r
29 import javax.ws.rs.core.Response;\r
30 \r
31 import org.openecomp.mso.HealthCheckUtils;\r
32 import org.openecomp.mso.logger.MsoLogger;\r
33 import org.openecomp.mso.utils.UUIDChecker;\r
34 \r
35 import com.wordnik.swagger.annotations.Api;\r
36 import com.wordnik.swagger.annotations.ApiOperation;\r
37 \r
38 @Path("/globalhealthcheck")\r
39 @Api(value="/globalhealthcheck",description="APIH Infra Global Health Check")\r
40 public class GlobalHealthcheckHandler {\r
41 \r
42         public final static String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";\r
43 \r
44     private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);\r
45 \r
46         @HEAD\r
47     @GET\r
48     @Produces("text/html")\r
49         @ApiOperation(value="Performing global health check",response=Response.class)\r
50     public Response globalHealthcheck (@DefaultValue("true") @QueryParam("enableBpmn") boolean enableBpmn) {\r
51         long startTime = System.currentTimeMillis ();\r
52         MsoLogger.setServiceName ("GlobalHealthcheck");\r
53         // Generate a Request Id\r
54         String requestId = UUIDChecker.generateUUID(msoLogger);\r
55         HealthCheckUtils healthCheck = new HealthCheckUtils ();\r
56         if (!healthCheck.siteStatusCheck (msoLogger)) {\r
57             return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;\r
58         }\r
59 \r
60         if (healthCheck.verifyGlobalHealthCheck(enableBpmn, requestId)) {\r
61             msoLogger.debug("globalHealthcheck - Successful");\r
62             return HealthCheckUtils.HEALTH_CHECK_RESPONSE;\r
63         } else {\r
64             msoLogger.debug("globalHealthcheck - At leaset one of the sub-modules is not available");\r
65             return  HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;\r
66         }\r
67     } \r
68 }\r