070fe591c305019e651102efd53d2d60e548f7dc
[dcaegen2/collectors/datafile.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * Datafile Collector Service
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dcaegen2.collectors.datafile.controllers;
22
23 import io.swagger.annotations.Api;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.http.HttpStatus;
30 import org.springframework.http.ResponseEntity;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestMethod;
33 import org.springframework.web.bind.annotation.RestController;
34 import reactor.core.publisher.Mono;
35
36 /**
37  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/19/18
38  */
39 @RestController
40 @Api(value = "HeartbeatController", description = "Check liveness of Datafile service")
41 public class HeartbeatController {
42
43     private final Logger logger = LoggerFactory.getLogger(this.getClass());
44
45     /**
46      * Endpoint for checking that Datafile is alive.
47      *
48      * @return HTTP Status Code
49      */
50     @RequestMapping(value = "heartbeat", method = RequestMethod.GET)
51     @ApiOperation(value = "Returns liveness of Datafile service")
52     @ApiResponses(value = {
53         @ApiResponse(code = 200, message = "Datafile sevice is living"),
54         @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
55         @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
56         @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
57         }
58     )
59     public Mono<ResponseEntity<String>> heartbeat() {
60         logger.trace("Receiving heartbeat request");
61         return Mono.defer(() ->
62             Mono.just(new ResponseEntity<>("alive", HttpStatus.OK))
63         );
64     }
65 }