Fix java check style warning
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / health / ApiRouteHealthCheck.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 /**
15  * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
16  *
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
19  *
20  * http://www.apache.org/licenses/LICENSE-2.0
21  *
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
25  * the License.
26  */
27 package org.onap.msb.apiroute.health;
28
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;
33
34 import com.codahale.metrics.health.HealthCheck;
35
36 public class ApiRouteHealthCheck extends HealthCheck {
37
38
39     public ApiRouteHealthCheck() {}
40
41     @Override
42     protected Result check() throws Exception {
43         DiscoverInfo discoverInfo = ConfigUtil.getInstance().getDiscoverInfo();
44
45         String checkUrl = (new StringBuilder().append("http://").append(discoverInfo.toString())
46                         .append(RouteUtil.MSB_CHECK_URL)).toString();
47
48         int resultStatus = HttpClientUtil.httpGetStatus(checkUrl);
49
50         if (resultStatus == 200) {
51             return Result.healthy();
52         } else {
53             return Result.unhealthy("check consul fail:[status]" + resultStatus);
54         }
55
56
57     }
58 }