2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
4 * Copyright (C) 2018-2021 Nordix Foundation. All rights reserved.
5 * ===============================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License
12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing permissions and limitations under
15 * ============LICENSE_END========================================================================
18 package org.onap.dcaegen2.collectors.datafile.controllers;
20 import io.swagger.annotations.ApiResponse;
21 import io.swagger.annotations.ApiResponses;
22 import io.swagger.v3.oas.annotations.Operation;
23 import io.swagger.v3.oas.annotations.tags.Tag;
25 import org.onap.dcaegen2.collectors.datafile.model.Counters;
26 import org.onap.dcaegen2.collectors.datafile.tasks.CollectAndReportFiles;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.http.HttpHeaders;
30 import org.springframework.http.HttpStatus;
31 import org.springframework.http.ResponseEntity;
32 import org.springframework.web.bind.annotation.GetMapping;
33 import org.springframework.web.bind.annotation.RequestHeader;
34 import org.springframework.web.bind.annotation.RestController;
35 import reactor.core.publisher.Mono;
38 * REST Controller to check the heart beat and status of the DFC.
41 @Tag(name = "StatusController")
42 public class StatusController {
44 private static final Logger logger = LoggerFactory.getLogger(StatusController.class);
46 private final CollectAndReportFiles collectAndReportFiles;
48 public StatusController(CollectAndReportFiles task) {
49 this.collectAndReportFiles = task;
53 * Checks the heart beat of DFC.
55 * @return the heart beat status of DFC.
57 @GetMapping("/heartbeat")
58 @Operation(summary = "Returns liveness of DATAFILE service")
61 @ApiResponse(code = 200, message = "DATAFILE service is living"),
62 @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
63 @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
64 @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")})
65 public Mono<ResponseEntity<String>> heartbeat(@RequestHeader HttpHeaders headers) {
66 logger.info("ENTRY {}", "Heartbeat request");
68 String statusString = "I'm living!";
70 Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(statusString, HttpStatus.OK));
71 logger.info("EXIT {}", "Heartbeat request");
76 * Returns diagnostics and statistics information. It is intended for testing
80 * @return information.
82 @GetMapping("/status")
83 @Operation(summary = "Returns status and statistics of DATAFILE service")
86 @ApiResponse(code = 200, message = "DATAFILE service is living"),
87 @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
88 @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
89 @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")})
90 public Mono<ResponseEntity<String>> status(@RequestHeader HttpHeaders headers) {
92 logger.info("ENTRY {}", "Status request");
94 Counters counters = collectAndReportFiles.getCounters();
95 Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(counters.toString(), HttpStatus.OK));
96 logger.info("EXIT {}", "Status request");