2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
4 * Copyright (C) 2018-2023 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.oran.datafile.controllers;
20 import io.swagger.v3.oas.annotations.Operation;
21 import io.swagger.v3.oas.annotations.responses.ApiResponse;
22 import io.swagger.v3.oas.annotations.responses.ApiResponses;
23 import io.swagger.v3.oas.annotations.tags.Tag;
25 import org.oran.datafile.model.Counters;
26 import org.oran.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(responseCode = "200", description = "DATAFILE service is living"),
62 @ApiResponse(responseCode = "401", description = "You are not authorized to view the resource"),
65 description = "Accessing the resource you were trying to reach is forbidden"),
66 @ApiResponse(responseCode = "404", description = "The resource you were trying to reach is not found")})
67 public Mono<ResponseEntity<String>> heartbeat(@RequestHeader HttpHeaders headers) {
68 logger.info("ENTRY {}", "Heartbeat request");
70 String statusString = "I'm living!";
72 Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(statusString, HttpStatus.OK));
73 logger.info("EXIT {}", "Heartbeat request");
78 * Returns diagnostics and statistics information. It is intended for testing
82 * @return information.
84 @GetMapping("/status")
85 @Operation(summary = "Returns status and statistics of DATAFILE service")
88 @ApiResponse(responseCode = "200", description = "DATAFILE service is living"),
89 @ApiResponse(responseCode = "401", description = "You are not authorized to view the resource"),
92 description = "Accessing the resource you were trying to reach is forbidden"),
93 @ApiResponse(responseCode = "404", description = "The resource you were trying to reach is not found")})
94 public Mono<ResponseEntity<String>> status(@RequestHeader HttpHeaders headers) {
96 logger.info("ENTRY {}", "Status request");
98 Counters counters = collectAndReportFiles.getCounters();
99 Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(counters.toString(), HttpStatus.OK));
100 logger.info("EXIT {}", "Status request");