98dfdedc34b95b3e537267f6144fa8347bc19d3d
[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");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END========================================================================
17  */
18
19 package org.onap.dcaegen2.collectors.datafile.controllers;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.http.HttpStatus;
24 import org.springframework.http.ResponseEntity;
25 import org.springframework.web.bind.annotation.RequestMapping;
26 import org.springframework.web.bind.annotation.RequestMethod;
27 import org.springframework.web.bind.annotation.RestController;
28
29 import io.swagger.annotations.Api;
30 import io.swagger.annotations.ApiOperation;
31 import io.swagger.annotations.ApiResponse;
32 import io.swagger.annotations.ApiResponses;
33 import reactor.core.publisher.Mono;
34
35 /**
36  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/19/18
37  * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
38  */
39 @RestController
40 @Api(value = "HeartbeatController", description = "Check liveness of DATAFILE service")
41 public class HeartbeatController {
42
43     private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class);
44
45     @RequestMapping(value = "heartbeat", method = RequestMethod.GET)
46     @ApiOperation(value = "Returns liveness of DATAFILE service")
47     @ApiResponses(value = {
48             @ApiResponse(code = 200, message = "DATAFILE service is living"),
49             @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
50             @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
51             @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
52     }
53     )
54     public Mono<ResponseEntity<String>> heartbeat() {
55         logger.trace("Receiving heartbeat request");
56         return Mono.defer(() ->
57                 Mono.just(new ResponseEntity<>("I'm living", HttpStatus.OK))
58         );
59     }
60 }