Added support for using oauth token for Kafka
[nonrtric/plt/ranpm.git] / datafilecollector / src / main / java / org / oran / datafile / controllers / StatusController.java
1 /*-
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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
14  * the License.
15  * ============LICENSE_END========================================================================
16  */
17
18 package org.oran.datafile.controllers;
19
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;
24
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;
36
37 /**
38  * REST Controller to check the heart beat and status of the DFC.
39  */
40 @RestController
41 @Tag(name = "StatusController")
42 public class StatusController {
43
44     private static final Logger logger = LoggerFactory.getLogger(StatusController.class);
45
46     private final CollectAndReportFiles collectAndReportFiles;
47
48     public StatusController(CollectAndReportFiles task) {
49         this.collectAndReportFiles = task;
50     }
51
52     /**
53      * Checks the heart beat of DFC.
54      *
55      * @return the heart beat status of DFC.
56      */
57     @GetMapping("/heartbeat")
58     @Operation(summary = "Returns liveness of DATAFILE service")
59     @ApiResponses(
60         value = { //
61             @ApiResponse(responseCode = "200", description = "DATAFILE service is living"),
62             @ApiResponse(responseCode = "401", description = "You are not authorized to view the resource"),
63             @ApiResponse(
64                 responseCode = "403",
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");
69
70         String statusString = "I'm living!";
71
72         Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(statusString, HttpStatus.OK));
73         logger.info("EXIT {}", "Heartbeat request");
74         return response;
75     }
76
77     /**
78      * Returns diagnostics and statistics information. It is intended for testing
79      * and trouble
80      * shooting.
81      *
82      * @return information.
83      */
84     @GetMapping("/status")
85     @Operation(summary = "Returns status and statistics of DATAFILE service")
86     @ApiResponses(
87         value = { //
88             @ApiResponse(responseCode = "200", description = "DATAFILE service is living"),
89             @ApiResponse(responseCode = "401", description = "You are not authorized to view the resource"),
90             @ApiResponse(
91                 responseCode = "403",
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) {
95
96         logger.info("ENTRY {}", "Status request");
97
98         Counters counters = collectAndReportFiles.getCounters();
99         Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(counters.toString(), HttpStatus.OK));
100         logger.info("EXIT {}", "Status request");
101         return response;
102     }
103 }