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"); you may not use this file except
6 * in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
14 * ============LICENSE_END========================================================================
17 package org.onap.dcaegen2.collectors.datafile.controllers;
19 import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.ENTRY;
20 import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.EXIT;
22 import io.swagger.annotations.Api;
23 import io.swagger.annotations.ApiOperation;
24 import io.swagger.annotations.ApiResponse;
25 import io.swagger.annotations.ApiResponses;
27 import org.onap.dcaegen2.collectors.datafile.model.Counters;
28 import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
29 import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.http.HttpHeaders;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.web.bind.annotation.GetMapping;
37 import org.springframework.web.bind.annotation.RequestHeader;
38 import org.springframework.web.bind.annotation.RestController;
39 import reactor.core.publisher.Mono;
42 * REST Controller to check the heart beat and status of the DFC.
45 @Api(value = "StatusController")
46 public class StatusController {
48 private static final Logger logger = LoggerFactory.getLogger(StatusController.class);
50 private final ScheduledTasks scheduledTasks;
53 public StatusController(ScheduledTasks scheduledTasks) {
54 this.scheduledTasks = scheduledTasks;
58 * Checks the heart beat of DFC.
60 * @return the heart beat status of DFC.
62 @GetMapping("/heartbeat")
63 @ApiOperation(value = "Returns liveness of DATAFILE service")
66 @ApiResponse(code = 200, message = "DATAFILE service is living"),
67 @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
68 @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
69 @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")})
70 public Mono<ResponseEntity<String>> heartbeat(@RequestHeader HttpHeaders headers) {
71 MappedDiagnosticContext.initializeTraceContext(headers);
72 logger.info(ENTRY, "Heartbeat request");
74 String statusString = "I'm living!";
76 Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(statusString, HttpStatus.OK));
77 logger.info(EXIT, "Heartbeat request");
82 * Returns diagnostics and statistics information. It is intended for testing and trouble
85 * @return information.
87 @GetMapping("/status")
88 @ApiOperation(value = "Returns status and statistics of DATAFILE service")
91 @ApiResponse(code = 200, message = "DATAFILE service is living"),
92 @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
93 @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
94 @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")})
95 public Mono<ResponseEntity<String>> status(@RequestHeader HttpHeaders headers) {
96 MappedDiagnosticContext.initializeTraceContext(headers);
97 logger.info(ENTRY, "Status request");
99 Counters counters = scheduledTasks.getCounters();
100 Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(counters.toString(), HttpStatus.OK));
101 logger.info(EXIT, "Status request");