提交 | 用户 | 时间
|
e7c126
|
1 |
/* |
H |
2 |
* Copyright 1999-2018 Alibaba Group Holding Ltd. |
|
3 |
* |
|
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 |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
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. |
|
15 |
*/ |
|
16 |
|
|
17 |
package com.alibaba.nacos.console.controller; |
|
18 |
|
|
19 |
import com.alibaba.nacos.console.paramcheck.ConsoleDefaultHttpParamExtractor; |
|
20 |
import com.alibaba.nacos.core.cluster.health.ModuleHealthCheckerHolder; |
|
21 |
import com.alibaba.nacos.core.cluster.health.ReadinessResult; |
|
22 |
import com.alibaba.nacos.core.paramcheck.ExtractorManager; |
|
23 |
import org.springframework.http.HttpStatus; |
|
24 |
import org.springframework.http.ResponseEntity; |
|
25 |
import org.springframework.web.bind.annotation.GetMapping; |
|
26 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
27 |
import org.springframework.web.bind.annotation.RestController; |
|
28 |
|
|
29 |
import javax.servlet.http.HttpServletRequest; |
|
30 |
|
|
31 |
/** |
|
32 |
* Health Controller. |
|
33 |
* |
|
34 |
* @author <a href="mailto:huangxiaoyu1018@gmail.com">hxy1991</a> |
|
35 |
*/ |
|
36 |
@RestController("consoleHealth") |
|
37 |
@RequestMapping("/v1/console/health") |
|
38 |
@ExtractorManager.Extractor(httpExtractor = ConsoleDefaultHttpParamExtractor.class) |
|
39 |
public class HealthController { |
|
40 |
|
|
41 |
/** |
|
42 |
* Whether the Nacos is in broken states or not, and cannot recover except by being restarted. |
|
43 |
* |
|
44 |
* @return HTTP code equal to 200 indicates that Nacos is in right states. HTTP code equal to 500 indicates that |
|
45 |
* Nacos is in broken states. |
|
46 |
*/ |
|
47 |
@GetMapping("/liveness") |
|
48 |
public ResponseEntity<String> liveness() { |
|
49 |
return ResponseEntity.ok().body("OK"); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Ready to receive the request or not. |
|
54 |
* |
|
55 |
* @return HTTP code equal to 200 indicates that Nacos is ready. HTTP code equal to 500 indicates that Nacos is not |
|
56 |
* ready. |
|
57 |
*/ |
|
58 |
@GetMapping("/readiness") |
|
59 |
public ResponseEntity<String> readiness(HttpServletRequest request) { |
|
60 |
ReadinessResult result = ModuleHealthCheckerHolder.getInstance().checkReadiness(); |
|
61 |
if (result.isSuccess()) { |
|
62 |
return ResponseEntity.ok().body("OK"); |
|
63 |
} |
|
64 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result.getResultMessage()); |
|
65 |
} |
|
66 |
|
|
67 |
} |