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