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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * ============LICENSE_END========================================================================
17 package org.onap.dcaegen2.collectors.datafile.controllers;
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;
35 * Controller to check the heartbeat of DFC.
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>
41 @Api(value = "HeartbeatController")
42 public class HeartbeatController {
44 private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class);
47 * Checks the heartbeat of DFC.
49 * @return the heartbeat status of DFC.
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");