Skip to content

Commit

Permalink
Merge pull request #25 from chinmoy12c/enhancement/async-health-endpo…
Browse files Browse the repository at this point in the history
…ints

Modified health check endpoints to work asynchronously.
  • Loading branch information
pankajjangid05 authored Apr 12, 2023
2 parents d9ca06d + 6f4d2e5 commit 817d8d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 46 deletions.
28 changes: 9 additions & 19 deletions src/main/java/com/uci/outbound/health/HealthController.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package com.uci.outbound.health;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.uci.dao.service.HealthService;

import com.uci.utils.model.ApiResponse;
import com.uci.utils.model.ApiResponseParams;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import reactor.core.publisher.Mono;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -29,15 +21,13 @@ public class HealthController {
private HealthService healthService;

@RequestMapping(value = "/health", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<ApiResponse> statusCheck() throws JsonProcessingException, IOException {
log.error("Health API called");
ApiResponse response = ApiResponse.builder()
.id("api.health")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getAllHealthNode())
.build();

return ResponseEntity.ok(response);
public Mono<ResponseEntity<ApiResponse>> statusCheck() {
return healthService.getAllHealthNode().map(health -> ApiResponse.builder()
.id("api.health")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(health)
.build()
).map(ResponseEntity::ok);
}
}
54 changes: 27 additions & 27 deletions src/main/java/com/uci/outbound/health/ServiceStatusController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.uci.utils.model.ApiResponse;
import com.uci.utils.model.ApiResponseParams;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

import java.io.IOException;

Expand Down Expand Up @@ -49,38 +50,37 @@ public ResponseEntity<ApiResponse> statusCheck() throws JsonProcessingException
}

@RequestMapping(value = "/health/cassandra", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<ApiResponse> cassandraStatusCheck() throws IOException, JsonProcessingException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.cassandra")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getCassandraHealthNode())
.build();

return ResponseEntity.ok(response);
public Mono<ResponseEntity<ApiResponse>> cassandraStatusCheck() {
return healthService.getCassandraHealthNode().map(result->
ApiResponse.builder()
.id("api.service.health.cassandra")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(result)
.build())
.map(ResponseEntity::ok);
}

@RequestMapping(value = "/health/kafka", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<ApiResponse> kafkaStatusCheck() throws IOException, JsonProcessingException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.kafka")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getKafkaHealthNode())
.build();

return ResponseEntity.ok(response);
public Mono<ResponseEntity<ApiResponse>> kafkaStatusCheck() {
return healthService.getKafkaHealthNode().map(result->
ApiResponse.builder()
.id("api.service.health.kafka")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(result)
.build())
.map(ResponseEntity::ok);
}

@RequestMapping(value = "/health/campaign", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<ApiResponse> campaignUrlStatusCheck() throws JsonProcessingException, IOException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.campaign")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getCampaignUrlHealthNode())
.build();

return ResponseEntity.ok(response);
public Mono<ResponseEntity<ApiResponse>> campaignUrlStatusCheck() {
return healthService.getCampaignUrlHealthNode().map(result ->
ApiResponse.builder().id("api.service.health.campaign")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(result)
.build())
.map(ResponseEntity::ok);
}
}

0 comments on commit 817d8d1

Please sign in to comment.