Open Kilda Java Documentation
HealthCheckController.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * 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
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.northbound.controller;
17 
18 import io.swagger.annotations.Api;
19 import io.swagger.annotations.ApiOperation;
20 import io.swagger.annotations.ApiResponse;
21 import io.swagger.annotations.ApiResponses;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.context.annotation.PropertySource;
29 import org.springframework.http.HttpHeaders;
30 import org.springframework.http.HttpStatus;
31 import org.springframework.http.MediaType;
32 import org.springframework.http.ResponseEntity;
33 import org.springframework.web.bind.annotation.RequestMapping;
34 import org.springframework.web.bind.annotation.RequestMethod;
35 import org.springframework.web.bind.annotation.RestController;
36 
40 @RestController
41 @PropertySource("classpath:northbound.properties")
42 @Api
43 public class HealthCheckController {
47  private static final Logger logger = LoggerFactory.getLogger(HealthCheckController.class);
48 
52  @Autowired
53  private HealthCheckService healthCheckService;
54 
60  @ApiOperation(value = "Gets health-check status", response = HealthCheck.class)
61  @ApiResponses(value = {
62  @ApiResponse(code = 200, response = HealthCheck.class, message = "Operation is successful"),
63  @ApiResponse(code = 401, response = MessageError.class, message = "Unauthorized"),
64  @ApiResponse(code = 403, response = MessageError.class, message = "Forbidden"),
65  @ApiResponse(code = 404, response = MessageError.class, message = "Not found"),
66  @ApiResponse(code = 503, response = MessageError.class, message = "Service unavailable")})
67  @RequestMapping(value = "/health-check",
68  method = RequestMethod.GET,
69  produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
70  public ResponseEntity<HealthCheck> getHealthCheck() {
71  logger.debug("getHealthCheck");
72 
73  HealthCheck healthCheck = healthCheckService.getHealthCheck();
74  HttpStatus status = healthCheck.hasNonOperational() ? HttpStatus.GATEWAY_TIMEOUT : HttpStatus.OK;
75 
76  return new ResponseEntity<>(healthCheck, new HttpHeaders(), status);
77  }
78 }
value
Definition: nodes.py:62
def status()
Definition: rest.py:593