b0e339ef5641e83cb5fd6c21478d3fe53b444492
[dcaegen2/collectors/datafile.git] /
1 /*-
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6  * in compliance with the License. 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 distributed under the License
11  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12  * or implied. See the License for the specific language governing permissions and limitations under
13  * the License.
14  * ============LICENSE_END========================================================================
15  */
16
17 package org.onap.dcaegen2.collectors.datafile.controllers;
18
19 import io.swagger.annotations.Api;
20 import io.swagger.annotations.ApiOperation;
21 import io.swagger.annotations.ApiResponse;
22 import io.swagger.annotations.ApiResponses;
23 import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.http.HttpHeaders;
27 import org.springframework.http.HttpStatus;
28 import org.springframework.http.ResponseEntity;
29 import org.springframework.web.bind.annotation.GetMapping;
30 import org.springframework.web.bind.annotation.RequestHeader;
31 import org.springframework.web.bind.annotation.RestController;
32 import reactor.core.publisher.Mono;
33
34 /**
35  * Controller to check the heartbeat of DFC.
36  *
37  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/19/18
38  * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
39  */
40 @RestController
41 @Api(value = "HeartbeatController")
42 public class HeartbeatController {
43
44     private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class);
45
46     /**
47      * Checks the heartbeat of DFC.
48      *
49      * @return the heartbeat status of DFC.
50      */
51     @GetMapping("/heartbeat")
52     @ApiOperation(value = "Returns liveness of DATAFILE service")
53     @ApiResponses(value = { //
54             @ApiResponse(code = 200, message = "DATAFILE service is living"),
55             @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
56             @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
57             @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")})
58     public Mono<ResponseEntity<String>> heartbeat(@RequestHeader HttpHeaders headers) {
59         MappedDiagnosticContext.initializeTraceContext(headers);
60         logger.info(MappedDiagnosticContext.ENTRY, "Heartbeat request");
61         Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>("I'm living", HttpStatus.OK));
62         logger.trace("Heartbeat");
63         logger.info(MappedDiagnosticContext.EXIT, "Heartbeat request");
64         return response;
65     }
66 }