Skip to content

Commit

Permalink
Merge pull request #315 from holashchand/credential-health-check
Browse files Browse the repository at this point in the history
[BUG]: fixed health check return always false for credential services
  • Loading branch information
challabeehyv authored May 7, 2024
2 parents ceadd8d + 71e5c5b commit 1bc3533
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;

import static dev.sunbirdrc.registry.middleware.util.Constants.CONNECTION_FAILURE;

Expand Down Expand Up @@ -214,7 +215,8 @@ public String getServiceName() {
public ComponentHealthInfo getHealthInfo() {
try {
ResponseEntity<String> response = retryRestTemplate.getForEntity(healthCheckUrl);
if (!StringUtils.isEmpty(response.getBody()) && JSONUtil.convertStringJsonNode(response.getBody()).get("status").asText().equalsIgnoreCase("UP")) {
JsonNode responseBody = JSONUtil.convertStringJsonNode(response.getBody());
if (!StringUtils.isEmpty(response.getBody()) && Stream.of("OK","UP").anyMatch(d -> d.equalsIgnoreCase(responseBody.get("status").asText()))) {
logger.debug("{} service running!", this.getServiceName());
return new ComponentHealthInfo(getServiceName(), true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.IOException;
import java.util.*;
import java.util.stream.Stream;

import static dev.sunbirdrc.registry.middleware.util.Constants.*;

Expand Down Expand Up @@ -140,7 +141,8 @@ public String getServiceName() {
public ComponentHealthInfo getHealthInfo() {
try {
ResponseEntity<String> response = retryRestTemplate.getForEntity(healthCheckUrl);
if (!StringUtils.isEmpty(response.getBody()) && JSONUtil.convertStringJsonNode(response.getBody()).get("status").asText().equalsIgnoreCase("UP")) {
JsonNode responseBody = JSONUtil.convertStringJsonNode(response.getBody());
if (!StringUtils.isEmpty(response.getBody()) && Stream.of("OK", "UP").anyMatch(d -> d.equalsIgnoreCase(responseBody.get("status").asText()))) {
logger.debug("{} service running!", this.getServiceName());
return new ComponentHealthInfo(getServiceName(), true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;

import static dev.sunbirdrc.registry.Constants.HTTPS_URI_PREFIX;
import static dev.sunbirdrc.registry.Constants.HTTP_URI_PREFIX;
Expand Down Expand Up @@ -230,7 +231,8 @@ public String getServiceName() {
public ComponentHealthInfo getHealthInfo() {
try {
ResponseEntity<String> response = retryRestTemplate.getForEntity(healthCheckUrl);
if (!StringUtils.isEmpty(response.getBody()) && JSONUtil.convertStringJsonNode(response.getBody()).get("status").asText().equalsIgnoreCase("UP")) {
JsonNode responseBody = JSONUtil.convertStringJsonNode(response.getBody());
if (!StringUtils.isEmpty(response.getBody()) && Stream.of("OK", "UP").anyMatch(d -> d.equalsIgnoreCase(responseBody.get("status").asText()))) {
logger.debug("{} service running!", this.getServiceName());
return new ComponentHealthInfo(getServiceName(), true);
} else {
Expand Down

0 comments on commit 1bc3533

Please sign in to comment.