Skip to content

Commit

Permalink
Merge pull request Sunbird-RC#268 from holashchand/release-1.0.0-fix
Browse files Browse the repository at this point in the history
fixed idgen and encryption endpoints and health check
  • Loading branch information
srprasanna authored Nov 15, 2023
2 parents 5670f7c + 7e76db8 commit 723e683
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ services:
- connectionInfo_username=postgres
- connectionInfo_password=postgres
- encryption_enabled=${ENCRYPTION_ENABLED-false}
- encryption_health_check_url=http://encryption-service:8013/health
- encryption_uri=http://encryption-service:8013/crypto/v1/_encrypt
- encryption_batch_uri=http://encryption-service:8013/crypto/v1/_encrypt
- event_enabled=${EVENT_ENABLED-false}
- event_topic=events
- event_providerName=dev.sunbirdrc.registry.service.impl.KafkaEventService
Expand All @@ -63,6 +66,10 @@ services:
- oauth2_resource_uri=${oauth2_resource_uri-http://keycloak:8080/auth/realms/sunbird-rc}
- oauth2_resource_roles_path=${oauth2_resource_roles_path-realm_access.roles}
- identity_provider=${identity_provider-dev.sunbirdrc.auth.keycloak.KeycloakProviderImpl}
- idgen_enabled=${IDGEN_ENABLED-false}
- idgen_health_check_url=http://id-gen-service:8088/egov-idgen/health
- idgen_generate_url=http://id-gen-service:8088/egov-idgen/id/_generate
- idgen_id_format_url=http://id-gen-service:8088/egov-idgen/id/_format/add
- sunbird_sso_admin_client_id=${KEYCLOAK_ADMIN_CLIENT_ID-admin-api}
- sunbird_sso_client_id=${KEYCLOAK_CLIENT_ID-registry-frontend}
- sunbird_sso_admin_client_secret=${KEYCLOAK_SECRET}
Expand Down Expand Up @@ -381,6 +388,7 @@ services:
spring.flyway.url: jdbc:postgresql://db:5432/registry
egov.mdms.provider: org.egov.enc.masterdata.provider.DBMasterDataProvider
spring.flyway.baseline-on-migrate: "true"
management.endpoints.web.base-path: /
depends_on:
db:
condition: service_healthy
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,13 @@ private JsonNode getUserInfoFromRegistry(HttpServletRequest request, String enti
watch.start("RegistryController.searchEntity");
JsonNode result = searchEntity(payload);
watch.stop("RegistryController.searchEntity");
if(result != null && result.get(entityName) != null && !result.get(entityName).isEmpty()) {
String uuid = result.get(entityName).get(0).get(uuidPropertyName).asText();
JsonNode user = readEntity(userId, entityName, uuid, true, null, false);
ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();
arrayNode.add(user.get(entityName));
((ObjectNode) result).set(entityName, arrayNode);
}
return result;
}
throw new Exception("Forbidden");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.sunbirdrc.pojos.ComponentHealthInfo;
import dev.sunbirdrc.pojos.SunbirdRCInstrumentation;
import dev.sunbirdrc.registry.exception.EncryptionException;
import dev.sunbirdrc.registry.middleware.util.JSONUtil;
import dev.sunbirdrc.registry.service.EncryptionService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
Expand All @@ -23,6 +24,7 @@
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClientException;

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

import static dev.sunbirdrc.registry.middleware.util.Constants.CONNECTION_FAILURE;
Expand Down Expand Up @@ -165,13 +167,13 @@ public ComponentHealthInfo getHealthInfo() {
if (encryptionEnabled) {
try {
ResponseEntity<String> response = retryRestTemplate.getForEntity(encryptionServiceHealthCheckUri);
if (!StringUtils.isEmpty(response.getBody()) && response.getBody().equalsIgnoreCase("UP")) {
if (!StringUtils.isEmpty(response.getBody()) && JSONUtil.convertStringJsonNode(response.getBody()).get("status").asText().equalsIgnoreCase("UP")) {
logger.debug("Encryption service running !");
return new ComponentHealthInfo(getServiceName(), true);
} else {
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, response.getBody());
}
} catch (RestClientException ex) {
} catch (RestClientException | IOException ex) {
logger.error("RestClientException when checking the health of the encryption service: {}", ExceptionUtils.getStackTrace(ex));
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClientException;

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

Expand Down Expand Up @@ -144,13 +145,13 @@ public ComponentHealthInfo getHealthInfo() {
if (enabled) {
try {
ResponseEntity<String> response = retryRestTemplate.getForEntity(healthCheckUrl);
if (!StringUtils.isEmpty(response.getBody()) && response.getBody().equalsIgnoreCase("UP")) {
if (!StringUtils.isEmpty(response.getBody()) && JSONUtil.convertStringJsonNode(response.getBody()).get("status").asText().equalsIgnoreCase("UP")) {
logger.debug(" running !");
return new ComponentHealthInfo(getServiceName(), true);
} else {
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, response.getBody());
}
} catch (RestClientException ex) {
} catch (RestClientException | IOException ex) {
logger.error("RestClientException when checking the health of the idgen service: {}", ExceptionUtils.getStackTrace(ex));
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void test_decrypt_api_map_param_throwing_resource_exception() throws Exce

@Test
public void test_encryption_isup() throws Exception {
when(retryRestTemplate.getForEntity(nullable(String.class))).thenReturn(ResponseEntity.accepted().body("UP"));
when(retryRestTemplate.getForEntity(nullable(String.class))).thenReturn(ResponseEntity.accepted().body("{\"status\": \"UP\"}"));
assertTrue(encryptionServiceImpl.isEncryptionServiceUp());
}

Expand Down

0 comments on commit 723e683

Please sign in to comment.