Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / health / OpenRestyHealthCheck.java
1 package org.onap.msb.apiroute.health;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.onap.msb.apiroute.wrapper.util.HttpClientUtil;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7
8 import com.codahale.metrics.health.HealthCheck;
9
10 public class OpenRestyHealthCheck extends HealthCheck {
11         private static final Logger LOGGER = LoggerFactory
12                         .getLogger(OpenRestyHealthCheck.class);
13         private String CHECK_IP="127.0.0.1";
14         private String CHECK_PORT="80";
15         private String CHECK_URL = "http://"+CHECK_IP+":"+CHECK_PORT+"/api/microservices/v1/apiRoute/discoverInfo";
16         
17         @Override
18         protected Result check() throws Exception {
19                 // TODO Auto-generated method stub
20                 
21                 if(!StringUtils.isBlank(System.getenv("HTTP_OVERWRITE_PORT")))
22                 {
23                         CHECK_PORT=System.getenv("HTTP_OVERWRITE_PORT");
24                         CHECK_URL = "http://"+CHECK_IP+":"+CHECK_PORT+"/api/microservices/v1/apiRoute/discoverInfo";
25                         LOGGER.info("check openresty URL:"+CHECK_URL);
26                 }
27                 
28                 int resultStatus = HttpClientUtil.httpGetStatus(CHECK_URL);
29
30                 if (resultStatus == 200) {
31                         return Result.healthy();
32                 } else {
33                         return Result
34                                         .unhealthy("check openresty fail:" + resultStatus);
35                 }
36
37         }
38
39 }