Fix java check style issue
[msb/discovery.git] / sdclient / discovery-service / src / main / java / org / onap / msb / sdclient / health / ConsulLinkHealthCheck.java
1 /**
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package org.onap.msb.sdclient.health;
15
16 import org.apache.commons.lang3.StringUtils;
17 import org.onap.msb.sdclient.wrapper.util.HttpClientUtil;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import com.codahale.metrics.health.HealthCheck;
22
23 public class ConsulLinkHealthCheck extends HealthCheck {
24
25
26     private static final Logger LOGGER = LoggerFactory.getLogger(ConsulLinkHealthCheck.class);
27
28     private String CHECK_IP = "127.0.0.1";
29     private String CHECK_PORT = "8500";
30     private String CHECK_URL = "http://" + CHECK_IP + ":" + CHECK_PORT + "/v1/status/leader";
31
32
33     @Override
34     protected Result check() throws Exception {
35         // TODO Auto-generated method stub
36
37         if (!StringUtils.isBlank(System.getenv("CONSUL_IP"))) {
38             CHECK_IP = System.getenv("CONSUL_IP");
39             CHECK_URL = "http://" + CHECK_IP + ":" + CHECK_PORT + "/v1/status/leader";
40             LOGGER.info("check consul URL:" + CHECK_URL);
41         }
42
43         int resultStatus = HttpClientUtil.httpGetStatus(CHECK_URL);
44
45         if (resultStatus == 200) {
46             return Result.healthy();
47         } else {
48             return Result.unhealthy("check consul link {} fail:{}", CHECK_URL, resultStatus);
49         }
50
51     }
52
53 }