Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature errors cleanup #248

Merged
merged 28 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
861ad8e
fixed file storage errors
holashchand Sep 4, 2023
ea2eaa9
added missing exception class file
holashchand Sep 4, 2023
189c0f2
fixed tests failure
holashchand Sep 4, 2023
222c5a3
fixed elastic search issues
holashchand Sep 4, 2023
16799e5
fixed signing and certificate service logs
holashchand Sep 4, 2023
fa87187
fixed errors for audit, notification, encryption, swagger, Api Messag…
holashchand Sep 5, 2023
9f2c1ee
fixed registry helper tests failing
holashchand Sep 6, 2023
17c824a
enabling certificate and claims only when enabled
holashchand Sep 6, 2023
920da2d
fixed make tests failing
holashchand Sep 7, 2023
bb02f4f
added health check to metrics service and fixed metrics service issues
holashchand Sep 8, 2023
2fc87d3
added missing metrics files
holashchand Sep 8, 2023
abf6d03
fixed error messages
holashchand Sep 8, 2023
d391071
minor fix
holashchand Sep 11, 2023
99b4d15
fixed certificate api docker file
holashchand Sep 11, 2023
a516175
added debug plugin
holashchand Sep 11, 2023
bb1d82a
added public key
holashchand Sep 11, 2023
33b074a
added manual workflow
holashchand Sep 11, 2023
33411eb
suppressing exception while loading schema from db
holashchand Sep 11, 2023
263d211
fixed elastic search version and removed debug config
holashchand Sep 12, 2023
c4a3453
fixed error messages
holashchand Sep 12, 2023
78c9c8b
fixed error messages
holashchand Sep 12, 2023
03145c7
change error messages to print stack
holashchand Sep 12, 2023
9c6dc53
changed kafka port exposing to 9092
holashchand Sep 13, 2023
5d186fd
fixed error messages, failing tests and renamed test environments
holashchand Sep 14, 2023
488bdef
throwing notify exception
holashchand Sep 14, 2023
65eb66c
reverted from error messages to stack trace
holashchand Sep 14, 2023
ffbfcda
fixed error messages for golang
holashchand Sep 15, 2023
43f260d
adding ensure index at startup back
holashchand Sep 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/maven.yml
holashchand marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ jobs:
cache: 'maven'
- name: Set up properties
run: sh configure-dependencies.sh
# # debug step
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
# with:
# ## limits ssh access and adds the ssh public key for the user which triggered the workflow ie holashchand
# limit-access-to-actor: true
- name: Build and test
run: make test
# test:
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ java/registry/target/registry.jar: $(SOURCES)
cd java && ./mvnw clean install

test: build
@echo "VIEW_DIR=java/apitest/src/test/resources/views" >> .env || echo "no permission to append to file"
@echo "SCHEMA_DIR=java/apitest/src/test/resources/schemas" >> .env || echo "no permission to append to file"
@docker-compose down
@rm -rf db-data* || echo "no permission to delete"
# test with distributed definition manager and native search
@SEARCH_PROVIDER_NAME=dev.sunbirdrc.registry.service.NativeSearchService RELEASE_VERSION=latest KEYCLOAK_IMPORT_DIR=java/apitest/src/test/resources KEYCLOAK_SECRET=a52c5f4a-89fd-40b9-aea2-3f711f14c889 MANAGER_TYPE=DistributedDefinitionsManager DB_DIR=db-data-1 docker-compose up -d db keycloak registry certificate-signer certificate-api redis
@docker-compose --env-file test_environments/test1.env up -d db keycloak registry certificate-signer certificate-api redis
holashchand marked this conversation as resolved.
Show resolved Hide resolved
@echo "Starting the test" && sh build/wait_for_port.sh 8080
@echo "Starting the test" && sh build/wait_for_port.sh 8081
@docker-compose ps
Expand All @@ -42,7 +40,7 @@ test: build
@docker-compose down
@rm -rf db-data-1 || echo "no permission to delete"
# test with kafka(async), events, notifications,
@NOTIFICATION_ENABLED=true NOTIFICATION_URL=http://notification-ms:8765/notification-service/v1/notification TRACK_NOTIFICATIONS=true EVENT_ENABLED=true ASYNC_ENABLED=true RELEASE_VERSION=latest KEYCLOAK_IMPORT_DIR=java/apitest/src/test/resources KEYCLOAK_SECRET=a52c5f4a-89fd-40b9-aea2-3f711f14c889 DB_DIR=db-data-2 docker-compose up -d db clickhouse redis es keycloak registry certificate-signer certificate-api kafka zookeeper notification-ms metrics
@docker-compose --env-file test_environments/test2.env up -d db clickhouse redis es keycloak registry certificate-signer certificate-api kafka zookeeper notification-ms metrics
holashchand marked this conversation as resolved.
Show resolved Hide resolved
@echo "Starting the test" && sh build/wait_for_port.sh 8080
@echo "Starting the test" && sh build/wait_for_port.sh 8081
@docker-compose ps
Expand Down
2 changes: 1 addition & 1 deletion build/wait_for_port.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo "Waiting service to launch on $1..."
i=0
while ! curl localhost:$1; do
sleep 10
let i=i+1
((i=i+1))
if [[ $i -gt 60 ]]; then
echo "Failed to get the service in sane state!"
exit 1;
Expand Down
18 changes: 14 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "2.4"

services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:8.8.1
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.13
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
Expand Down Expand Up @@ -40,6 +40,7 @@ services:
- connectionInfo_uri=jdbc:postgresql://db:5432/registry
- connectionInfo_username=postgres
- connectionInfo_password=postgres
- encryption_enabled=${ENCRYPTION_ENABLED-false}
- event_enabled=${EVENT_ENABLED-false}
- event_topic=events
- event_providerName=dev.sunbirdrc.registry.service.impl.KafkaEventService
Expand All @@ -54,15 +55,18 @@ services:
- 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}
- claims_enabled=${CLAIMS_ENABLED-false}
- claims_url=http://claim-ms:8082
- signature_enabled=${SIGNATURE_ENABLED-false}
- sign_url=http://certificate-signer:8079/sign
- verify_url=http://certificate-signer:8079/verify
- sign_health_check_url=http://certificate-signer:8079/health
- signature_enabled=true
- certificate_enabled=${CERTIFICATE_ENABLED-false}
holashchand marked this conversation as resolved.
Show resolved Hide resolved
- pdf_url=http://certificate-api:8078/api/v1/certificatePDF
- certificate_health_check_url=http://certificate-api:8078/health
- template_base_url=http://registry:8081/api/v1/templates/ #Looks for certificate templates for pdf copy of the signed certificate
- sunbird_keycloak_user_set_password=true
- filestorage_enabled=false
- filestorage_connection_url=http://file-storage:9000
- filestorage_access_key=admin
- filestorage_secret_key=12345678
Expand Down Expand Up @@ -213,7 +217,7 @@ services:
zookeeper:
condition: service_started
ports:
- "9092:9092"
- "9094:9094"
holashchand marked this conversation as resolved.
Show resolved Hide resolved
environment:
KAFKA_BROKER_ID: "1"
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
Expand Down Expand Up @@ -281,9 +285,15 @@ services:
REDIS_URL: redis:6379
ports:
- "8070:8070"
healthcheck:
test:
[ "CMD-SHELL", "wget -nv -t1 --spider http://localhost:8070/health || exit 1" ]
interval: 30s
timeout: 10s
retries: 10
depends_on:
kafka:
condition: service_started
condition: service_healthy
registry:
condition: service_healthy
redis:
Expand Down
1 change: 0 additions & 1 deletion java/.mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public static void main(String args[]) {
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -11,6 +13,7 @@
import static org.junit.Assert.*;

public class ConditionResolverServiceTest {
private static final Logger logger = LoggerFactory.getLogger(ConditionResolverServiceTest.class);
ConditionResolverService conditionResolverService = new ConditionResolverService();
@Test
public void shouldAbleToResolveRequesterPaths() throws IOException {
Expand Down Expand Up @@ -44,7 +47,7 @@ public void shouldReturnTrueForValidExpression() throws IOException {
try {
resolve = conditionResolverService.resolve(getStudentJsonNode(), requester, condition, attributes);
} catch (IOException e) {
e.printStackTrace();
logger.info("Exception occurred: {}", e.getMessage());
holashchand marked this conversation as resolved.
Show resolved Hide resolved
}
String attestor = "ATTESTOR";
resolve = conditionResolverService.resolve(getTeacherJsonNode(), attestor, resolve, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import dev.sunbirdrc.pojos.AuditRecord;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.charset.StandardCharsets;
Expand All @@ -15,6 +17,7 @@
import static org.junit.Assert.*;

public class JSONUtilTest {
private static final Logger logger = LoggerFactory.getLogger(JSONUtilTest.class);
private static final String TEST_DIR = "src/test/resources/";
private static final String ACTUAL_DATA = "actual_data.json";
private static final String EXPECTED_DATA = "expected_data.json";
Expand Down Expand Up @@ -131,12 +134,8 @@ private String getContent(String fileName) {
}
return result.toString(StandardCharsets.UTF_8.name());

} catch (FileNotFoundException e1) {
e1.printStackTrace();

} catch (IOException e) {
e.printStackTrace();

logger.info("Exception occurred: {}", e.getMessage());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.stereotype.Component;

import java.util.*;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;

import static dev.sunbirdrc.registry.middleware.util.Constants.CONNECTION_FAILURE;
Expand Down Expand Up @@ -130,6 +131,9 @@ private String createOrUpdateRealmGroup(String entityName) {
private RoleRepresentation createOrGetRealmRole(String entityName) {
RolesResource rolesResource = keycloak.realm(realm).roles();
try {
return rolesResource.get(entityName).toRepresentation();
} catch (NotFoundException ex) {
logger.error("Role {} not found. Creating role {}", entityName, entityName);
RoleRepresentation roleRepresentation = new RoleRepresentation();
roleRepresentation.setName(entityName);
rolesResource.create(roleRepresentation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public String fetchClientToken() {
try {
response = restTemplateProvider.exchange(divocKeycloakUrl, HttpMethod.POST, entity, Map.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Fetching divoc token failed: ");
exception.printStackTrace();
LOGGER.error("Fetching divoc token failed: {}", exception.getMessage());
}
if (response != null && response.getBody() != null && response.getBody().containsKey(ACCESS_TOKEN)) {
LOGGER.info("Divoc token fetch successfully.");
Expand All @@ -94,8 +93,7 @@ public byte[] fetchDivocPdf(String clientToken, String preEnrollmentCode, String
response = restTemplateProvider.exchange(divocUrl, HttpMethod.POST, entity, byte[].class);
return response.getBody();
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Fetching divoc PDF failed: ", exception);
exception.printStackTrace();
LOGGER.error("Fetching divoc PDF failed: {}", exception.getMessage());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public HttpHeaders getAuthTokenHeader() {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.AUTH_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Get auth token failed: ");
exception.printStackTrace();
LOGGER.error("Get auth token failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.OK) {
LOGGER.info("Successfully authenticated with mosip");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ void subscribeForPrintServiceEvents() {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.SUBSCRIBE_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Subscription to topic failed: ");
exception.printStackTrace();
LOGGER.error("Subscription to topic failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.ACCEPTED) {
LOGGER.info("subscribed for topic {} at hub", topic);
Expand All @@ -104,8 +103,7 @@ private void registerTopic() {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.REGISTER_URL, HttpMethod.POST, entity, String.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Register topic failed: ");
exception.printStackTrace();
LOGGER.error("Register topic failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.ACCEPTED) {
LOGGER.info("topic {} registered at hub", topic);
Expand All @@ -132,8 +130,7 @@ public Object generateOTP(SendOTPDto otpDto) {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.OTP_URL, HttpMethod.POST, entity, Object.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Generate otp failed failed: ");
exception.printStackTrace();
LOGGER.error("Generate otp failed failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.OK) {
LOGGER.info("Successfully generated otp");
Expand Down Expand Up @@ -176,8 +173,7 @@ public Object fetchCredentials(FetchCredentialsDto fetchCredentialsDto) {
try {
response = restTemplateProvider.exchange(webSubHubUrl + Constants.CREDENTIALS_URL, HttpMethod.POST, entity, Object.class);
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Generate credentials failed failed: ");
exception.printStackTrace();
LOGGER.error("Generate credentials failed failed: {}", exception.getMessage());
}
if (response != null && response.getStatusCode() == HttpStatus.OK) {
LOGGER.info("Successfully generated credentials");
Expand All @@ -200,8 +196,7 @@ public byte[] fetchMosipPdf(Map<String, String> requestHeaders, String requestBo
response = restTemplateProvider.exchange(printUrl + Constants.PRINT_PDF_URL, HttpMethod.POST, entity, byte[].class);
return response.getBody();
} catch (HttpClientErrorException | HttpServerErrorException exception) {
LOGGER.error("Failed fetching pdf failed: ");
exception.printStackTrace();
LOGGER.error("Failed fetching pdf failed: {}", exception.getMessage());
}
LOGGER.error("Failed fetching pdf failed: ");
return null;
Expand Down
12 changes: 7 additions & 5 deletions java/pojos/src/main/java/dev/sunbirdrc/pojos/APIMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public APIMessage(HttpServletRequest servletRequest) {
request = new Request();
requestWrapper = new RequestWrapper(servletRequest);
String body = requestWrapper.getBody();
try {
request = new ObjectMapper().readValue(body, Request.class);
} catch (IOException jpe) {
logger.error("Can't read request body", jpe);
request = null;
if(body != null && !body.isEmpty()) {
try {
request = new ObjectMapper().readValue(body, Request.class);
} catch (IOException jpe) {
logger.error("Can't read request body", jpe);
request = null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
Expand All @@ -61,6 +62,10 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;

import static dev.sunbirdrc.registry.Constants.ATTESTATION_POLICY;

@Configuration
@EnableRetry
Expand Down Expand Up @@ -352,10 +357,8 @@ public void addInterceptors(InterceptorRegistry registry) {
if (validationEnabled) {
try {
registry.addInterceptor(validationInterceptor()).addPathPatterns("/add").order(orderIdx++);
} catch (IOException e) {
e.printStackTrace();
} catch (CustomException e) {
e.printStackTrace();
} catch (IOException | CustomException e) {
logger.info("Exception occurred while adding validation interceptor: {}", e.getMessage());
}
}
}
Expand Down Expand Up @@ -413,6 +416,8 @@ public TaskExecutor auditTaskExecutor() {
* @return - IElasticService
* @throws IOException
*/

@ConditionalOnProperty(name = "search.providerName", havingValue = "dev.sunbirdrc.registry.service.ElasticSearchService")
@Bean
public IElasticService elasticService() throws IOException {
ElasticServiceImpl elasticService = new ElasticServiceImpl();
Expand All @@ -424,11 +429,14 @@ public IElasticService elasticService() throws IOException {
elasticService.setUserName(username);
elasticService.setPassword(password);
elasticService.setScheme(scheme);
elasticService.init(iDefinitionsManager.getAllKnownDefinitions());
Set<String> indices = new HashSet<>(iDefinitionsManager.getAllKnownDefinitions());
indices.add(ATTESTATION_POLICY);
elasticService.init(indices);
}
return elasticService;
}

@ConditionalOnProperty(name = "notification.service.enabled", havingValue = "true")
@Bean
public NotificationService notificationService() {
return new NotificationService(notificationServiceConnInfo, notificationServiceHealthUrl, notificationServiceEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "filestorage.enabled", havingValue = "true", matchIfMissing = true)
public class MinioClientConfig {

private static final Logger logger = LoggerFactory.getLogger(MinioClientConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ private void loadSchemasFromDB() {
try {
schemaService.addSchema(JsonNodeFactory.instance.objectNode().set(Schema, schemaNode));
} catch (Exception e) {
logger.error("Failed loading schema to definition manager:", e);
logger.error("Failed loading schema to definition manager: {}", e.getMessage());
}
}
logger.info("Loaded {} schema from DB", searchResults.get(Schema).size());
} catch (IOException e) {
e.printStackTrace();
logger.info("Exception occurred while loading schema from db: {}", e.getMessage());
} catch (Exception e) {
logger.info("Exception occurred while searching for schemas: {}", e.getMessage());
logger.info("Make sure, you are running a compatible version of search provider");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public abstract class AbstractController {
public String uuidPropertyName;

ResponseEntity<Object> badRequestException(ResponseParams responseParams, Response response, String errorMessage) {
logger.info("Error in handling the invite {}", errorMessage);
logger.info("Error in handling the invite: {}", errorMessage);
responseParams.setStatus(Response.Status.UNSUCCESSFUL);
responseParams.setErrmsg(errorMessage);
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}

ResponseEntity<Object> internalErrorResponse(ResponseParams responseParams, Response response, Exception ex) {
logger.info("Error in handling the invite", ex);
logger.info("Error in handling the invite: {}", ex.getMessage());
responseParams.setStatus(Response.Status.UNSUCCESSFUL);
responseParams.setErrmsg("Error occurred");
if (!StringUtils.isEmpty(ex.getMessage())) {
Expand Down
Loading
Loading