diff options
author | elinuxhenrik <henrik.b.andersson@est.tech> | 2019-04-11 07:04:31 +0000 |
---|---|---|
committer | elinuxhenrik <henrik.b.andersson@est.tech> | 2019-04-11 07:04:31 +0000 |
commit | f560cae7adfbaa90499473bb2f7bbee5d44de8a2 (patch) | |
tree | 0a973029aea7a90a0cd852507b91d0420fcba900 /datafile-app-server/src/main | |
parent | 314a1e4310545e5b70ff64e328f3e7eae281c5b4 (diff) |
Extend heartbeat to also include som health status
Add info about the internal status of DFC to the healtCheck message.
Change-Id: Ic2ad3e5b97c42d6affe1ac4e1d7cf2274027f881
Issue-ID: DCAEGEN2-1403
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Diffstat (limited to 'datafile-app-server/src/main')
3 files changed, 28 insertions, 7 deletions
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java index b0e339ef..c6d56c42 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/HeartbeatController.java @@ -16,13 +16,18 @@ package org.onap.dcaegen2.collectors.datafile.controllers; +import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.ENTRY; +import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.EXIT; + import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext; +import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -43,6 +48,13 @@ public class HeartbeatController { private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class); + private final ScheduledTasks scheduledTasks; + + @Autowired + public HeartbeatController(ScheduledTasks scheduledTasks) { + this.scheduledTasks = scheduledTasks; + } + /** * Checks the heartbeat of DFC. * @@ -54,13 +66,18 @@ public class HeartbeatController { @ApiResponse(code = 200, message = "DATAFILE service is living"), @ApiResponse(code = 401, message = "You are not authorized to view the resource"), @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"), - @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")}) + @ApiResponse(code = 404, message = "The resource you were trying to reach is not found") }) public Mono<ResponseEntity<String>> heartbeat(@RequestHeader HttpHeaders headers) { MappedDiagnosticContext.initializeTraceContext(headers); - logger.info(MappedDiagnosticContext.ENTRY, "Heartbeat request"); - Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>("I'm living", HttpStatus.OK)); - logger.trace("Heartbeat"); - logger.info(MappedDiagnosticContext.EXIT, "Heartbeat request"); + logger.info(ENTRY, "Heartbeat request"); + + StringBuilder statusString = new StringBuilder("I'm living! Status: "); + statusString.append("numberOfFileCollectionTasks=").append(scheduledTasks.getCurrentNumberOfTasks()) + .append(","); + statusString.append("fileCacheSize=").append(scheduledTasks.publishedFilesCacheSize()); + + Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>(statusString.toString(), HttpStatus.OK)); + logger.info(EXIT, "Heartbeat request"); return response; } } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java index 257c356c..2b3a0ef6 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java @@ -63,7 +63,7 @@ public class PublishedFileCache { } } - int size() { + public int size() { return publishedFiles.size(); } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java index 037f495f..3e4481dd 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java @@ -111,10 +111,14 @@ public class ScheduledTasks { return new PublishedChecker(applicationConfiguration); } - protected int getCurrentNumberOfTasks() { + public int getCurrentNumberOfTasks() { return currentNumberOfTasks.get(); } + public int publishedFilesCacheSize() { + return alreadyPublishedFiles.size(); + } + protected DMaaPMessageConsumer createConsumerTask() { return new DMaaPMessageConsumer(this.applicationConfiguration); } |