1 /*******************************************************************************
2 * Copyright 2016-2017 ZTE, Inc. and others.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
13 ******************************************************************************/
15 * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
17 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
18 * in compliance with the License. You may obtain a copy of the License at
20 * http://www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software distributed under the License
23 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
24 * or implied. See the License for the specific language governing permissions and limitations under
27 package org.onap.msb.apiroute.health;
29 import org.onap.msb.apiroute.api.DiscoverInfo;
30 import org.onap.msb.apiroute.wrapper.util.ConfigUtil;
31 import org.onap.msb.apiroute.wrapper.util.HttpClientUtil;
32 import org.onap.msb.apiroute.wrapper.util.RouteUtil;
34 import com.codahale.metrics.health.HealthCheck;
36 public class ApiRouteHealthCheck extends HealthCheck {
39 public ApiRouteHealthCheck() {}
42 protected Result check() throws Exception {
43 DiscoverInfo discoverInfo = ConfigUtil.getInstance().getDiscoverInfo();
45 String checkUrl = (new StringBuilder().append("http://").append(discoverInfo.toString())
46 .append(RouteUtil.MSB_CHECK_URL)).toString();
48 int resultStatus = HttpClientUtil.httpGetStatus(checkUrl);
50 if (resultStatus == 200) {
51 return Result.healthy();
53 return Result.unhealthy("check consul fail:[status]" + resultStatus);