diff --git a/README.md b/README.md index 44d4816c115..8d9ab66ff16 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,41 @@ -[![Maven Package upon a push](https://github.com/mosip/resident-services/actions/workflows/push_trigger.yml/badge.svg?branch=release-1.2.0)](https://github.com/mosip/resident-services/actions/workflows/push_trigger.yml) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mosip_resident-services&id=mosip_resident-services&branch=release-1.2.0&metric=alert_status)](https://sonarcloud.io/dashboard?id=mosip_resident-services&branch=release-1.2.0) +[![Maven Package upon a push](https://github.com/mosip/resident-services/actions/workflows/push_trigger.yml/badge.svg?branch=release-1.3.0)](https://github.com/mosip/resident-services/actions/workflows/push_trigger.yml) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mosip_resident-services&id=mosip_resident-services&branch=release-1.3.0&metric=alert_status)](https://sonarcloud.io/dashboard?id=mosip_resident-services&branch=release-1.3.0) # Resident Services -This repository contains the source code and design documents for MOSIP Resident Service. For an overview please refer [here](https://docs.mosip.io/1.2.0/modules/resident-services). This module exposes API endpoints for Resident UI (refer [Resident UI github repo](https://github.com/mosip/resident-ui/blob/master/README.md)). - +## Overview +This repository contains the source code and design documents for MOSIP Resident Service. For an overview please refer [here](https://docs.mosip.io/1.2.0/modules/resident-services). This module exposes API endpoints for Resident UI (refer [Resident UI GitHub repo](https://github.com/mosip/resident-ui/blob/master/README.md)). ## Database -See [DB guide](db_scripts/README.md) - -## Config-Server -To run Resident services, run [Config Server](https://docs.mosip.io/1.2.0/modules/module-configuration#config-server) +See [DB Scripts](db_scripts) ## Build & run (for developers) -The project requires JDK 1.21. +The project requires JDK 21.0.3 +and mvn version - 3.9.6 1. Build and install: ``` $ cd resident-service - $ mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip=true + $ mvn install -Dgpg.skip=true + ``` +2. Build Docker for a service: + ``` + $ cd + $ docker build -f Dockerfile ``` + +### Remove the version-specific suffix (PostgreSQL95Dialect) from the Hibernate dialect configuration + ``` + hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect + ``` +This is for better compatibility with future PostgreSQL versions. + +### Configure ANT Path Matcher for Spring Boot 3.x compatibility. + ``` + spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER + ``` +This is to maintain compatibility with existing ANT-style path patterns. -### Add Below Config in [resident-default.properties](https://github.com/mosip/mosip-config/blob/develop/resident-default.properties) +### Add Below Config in [resident-default.properties](https://github.com/mosip/mosip-config/blob/master/resident-default.properties) ``` hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect ## Keymanager service @@ -35,9 +50,6 @@ mosip.kernel.keymanager.hsm.config-path=/config/softhsm-application.conf mosip.kernel.keymanager.hsm.keystore-pass=${softhsm.kernel.security.pin} -# For Spring-boot 3.x we need to specify the ANT Path Matcher for using the existing ANT path patterns. -spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER - # Spring boot 3.x onwards we need to specify the below property to unmask values in actuator env url management.endpoint.env.show-values=ALWAYS @@ -45,43 +57,48 @@ resident.template.purpose.success.AUTHENTICATION_REQUEST=mosip.event.type.AUTHEN resident.template.purpose.failure.AUTHENTICATION_REQUEST=mosip.event.type.AUTHENTICATION_REQUEST ``` -### Update below config in [resident-default.properties](https://github.com/mosip/mosip-config/blob/develop/resident-default.properties) +### Update below config in [resident-default.properties](https://github.com/mosip/mosip-config/blob/master/resident-default.properties) ### The exclusion list of URL patterns that should not be part of authentication and authorization ``` mosip.service.end-points=/**/req/otp,/**/proxy/**,/**/validate-otp,/**/channel/verification-status/**,/**/req/credential/**,/**/req/card/*,/**/req/auth-history,/**/rid/check-status,/**/req/auth-lock,/**/req/auth-unlock,/**/req/update-uin,/**/req/print-uin,/**/req/euin,/**/credential/types,/**/req/policy/**,/**/aid/status,/**/individualId/otp,/**/mock/**,/**/callback/**,/**/download-card,/**/download/registration-centers-list/**,/**/download/supporting-documents/**,/**/vid/policy,/**/vid,/vid/**,/**/download/nearestRegistrationcenters/**,/**/authorize/admin/validateToken,/**/logout/user,/**/aid-stage/** ``` -1. Build Docker for a service: - ``` - $ cd - $ docker build -f Dockerfile - ``` +## Configuration +[resident-default.properties](https://github.com/mosip/mosip-config/blob/master/resident-default.properties) -### Add Below jars in a class-path to run a services - ``` - - io.mosip.kernel - kernel-auth-adapter - ${kernel.auth.adaptor.version} - - - io.mosip.kernel - kernel-ref-idobjectvalidator - ${kernel-ref-idobjectvalidator.version} - - ``` +[application-default.properties](https://github.com/mosip/mosip-config/blob/master/application-default.properties) +defined here. -## Deploy -To deploy Commons services on Kubernetes cluster using Dockers refer to [Sandbox Deployment](https://docs.mosip.io/1.2.0/deployment/sandbox-deployment). +## Config-Server +To run Resident services, run [Config Server](https://docs.mosip.io/1.2.0/modules/module-configuration#config-server) -## Configuration -[resident-default.properties](https://github.com/mosip/mosip-config/blob/develop/resident-default.properties) +## Default context, path, port +Refer to [bootstrap properties](resident/resident-service/src/main/resources/bootstrap.properties) -[application-default.properties](https://github.com/mosip/mosip-config/blob/develop/application-default.properties) -defined here. +## Deployment in K8 cluster with other MOSIP services: +### Pre-requisites +* Set KUBECONFIG variable to point to existing K8 cluster kubeconfig file: + ``` + export KUBECONFIG=~/.kube/ + ``` +### Install + ``` + $ cd deploy + $ ./install.sh + ``` +### Delete + ``` + $ cd deploy + $ ./delete.sh + ``` +### Restart + ``` + $ cd deploy + $ ./restart.sh + ``` ## Test -Automated functional tests available in [Functional Tests repo](https://github.com/mosip/mosip-functional-tests). +Automated functional tests available in [Functional Tests repo](api-test). ## APIs API documentation is available [here](https://mosip.github.io/documentation/). diff --git a/api-test/Dockerfile b/api-test/Dockerfile index aebc179e2fa..7d3e79e2d4c 100644 --- a/api-test/Dockerfile +++ b/api-test/Dockerfile @@ -1,4 +1,4 @@ -FROM mosipdev/openjdk-21-jre:latest +FROM mosipid/openjdk-21-jre:21.0.4 ARG SOURCE ARG COMMIT_HASH diff --git a/db_upgrade_scripts/mosip_resident/sql/1.2.0.1_to_1.2.1.0_rollback.sql b/db_upgrade_scripts/mosip_resident/sql/1.2.0.1_to_1.2.1.0_rollback.sql new file mode 100644 index 00000000000..381e2be11c1 --- /dev/null +++ b/db_upgrade_scripts/mosip_resident/sql/1.2.0.1_to_1.2.1.0_rollback.sql @@ -0,0 +1 @@ +\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION' \ No newline at end of file diff --git a/db_upgrade_scripts/mosip_resident/sql/1.2.0.1_to_1.2.1.0_upgrade.sql b/db_upgrade_scripts/mosip_resident/sql/1.2.0.1_to_1.2.1.0_upgrade.sql new file mode 100644 index 00000000000..381e2be11c1 --- /dev/null +++ b/db_upgrade_scripts/mosip_resident/sql/1.2.0.1_to_1.2.1.0_upgrade.sql @@ -0,0 +1 @@ +\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION' \ No newline at end of file diff --git a/db_upgrade_scripts/mosip_resident/sql/1.2.1.0_to_1.3.0_rollback.sql b/db_upgrade_scripts/mosip_resident/sql/1.2.1.0_to_1.3.0_rollback.sql new file mode 100644 index 00000000000..381e2be11c1 --- /dev/null +++ b/db_upgrade_scripts/mosip_resident/sql/1.2.1.0_to_1.3.0_rollback.sql @@ -0,0 +1 @@ +\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION' \ No newline at end of file diff --git a/db_upgrade_scripts/mosip_resident/sql/1.2.1.0_to_1.3.0_upgrade.sql b/db_upgrade_scripts/mosip_resident/sql/1.2.1.0_to_1.3.0_upgrade.sql new file mode 100644 index 00000000000..381e2be11c1 --- /dev/null +++ b/db_upgrade_scripts/mosip_resident/sql/1.2.1.0_to_1.3.0_upgrade.sql @@ -0,0 +1 @@ +\echo 'Upgrade Queries not required for transition from $CURRENT_VERSION to $UPGRADE_VERSION' \ No newline at end of file diff --git a/resident/pom.xml b/resident/pom.xml index 5c26cf285eb..37fcde85827 100644 --- a/resident/pom.xml +++ b/resident/pom.xml @@ -6,12 +6,11 @@ io.mosip.resident resident-parent - 1.2.1-SNAPSHOT + 1.3.0-SNAPSHOT pom resident Parent project of MOSIP Resident https://github.com/mosip/resident-services - MPL 2.0 @@ -79,6 +78,7 @@ **/constant/**,**/config/**,**/httpfilter/**,**/cache/**,**/dto/**,**/entity/**,**/model/**,**/exception/**,**/repository/**,**/security/**,**/*Config.java,**/*BootApplication.java,**/*VertxApplication.java,**/cbeffutil/**,**/mock/**,**/OrderCard*,**/testrig/** **/dto/**,**/entity/**,**/config/** + 1.3.0-beta.1 @@ -89,7 +89,7 @@ io.mosip.kernel kernel-bom - 1.2.1-SNAPSHOT + ${kernel-bom.version} pom import diff --git a/resident/resident-service/pom.xml b/resident/resident-service/pom.xml index a5b16e42b95..44bcff82b4e 100644 --- a/resident/resident-service/pom.xml +++ b/resident/resident-service/pom.xml @@ -7,27 +7,30 @@ io.mosip.resident resident-parent - 1.2.1-SNAPSHOT + 1.3.0-SNAPSHOT resident-service resident-service - 1.2.1-SNAPSHOT + 1.3.0-SNAPSHOT - 1.2.1-SNAPSHOT - 1.2.1-SNAPSHOT - 1.2.1-SNAPSHOT - 1.2.1-SNAPSHOT - 1.2.1-SNAPSHOT - 1.2.1-SNAPSHOT + 1.3.0-SNAPSHOT + 1.3.0-beta.1 + 1.3.0-SNAPSHOT + 1.3.0-beta.1 + 1.3.0-beta.1 + 1.3.0-beta.1 ${kernel.parent.version} - 1.2.1-SNAPSHOT - 1.2.1-SNAPSHOT + 1.3.0-beta.1 + 1.3.0-beta.1 0.8.11 - 1.2.1-SNAPSHOT - 1.2.1-SNAPSHOT + 1.3.0-beta.1 + 1.3.0-SNAPSHOT 0.8.11 1.2.1-SNAPSHOT - + 1.3.0-beta.1 + 1.3.0-beta.1 + 1.3.0-SNAPSHOT + 1.3.0-beta.1 @@ -254,7 +257,7 @@ io.mosip.kernel kernel-websubclient-api - ${project.version} + ${kernel-websubclient-api.version} org.mvel @@ -299,7 +302,7 @@ io.mosip.kernel kernel-pdfgenerator-itext - 1.2.1-SNAPSHOT + ${kernel-pdfgenerator-itext.version} org.springframework.security @@ -319,12 +322,12 @@ io.mosip.kernel kernel-auth-adapter - 1.2.1-SNAPSHOT + ${kernel-auth-adpater.version} io.mosip.kernel kernel-ref-idobjectvalidator - 1.2.1-SNAPSHOT + ${kernel-ref-idobjectvalidato.version} diff --git a/resident/resident-service/src/main/java/io/mosip/resident/ResidentBootApplication.java b/resident/resident-service/src/main/java/io/mosip/resident/ResidentBootApplication.java index 91da7352bb0..54f4dfa67d8 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/ResidentBootApplication.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/ResidentBootApplication.java @@ -8,9 +8,9 @@ import io.mosip.kernel.pdfgenerator.itext.impl.PDFGeneratorImpl; import io.mosip.kernel.templatemanager.velocity.builder.TemplateManagerBuilderImpl; import io.mosip.kernel.transliteration.icu4j.impl.TransliterationImpl; -import io.mosip.kernel.websub.api.client.PublisherClientImpl; -import io.mosip.kernel.websub.api.client.SubscriberClientImpl; +import io.mosip.kernel.websub.api.config.WebSubClientConfig; import io.mosip.kernel.websub.api.config.publisher.RestTemplateHelper; +import io.mosip.kernel.websub.api.config.publisher.WebSubPublisherClientConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -37,14 +37,16 @@ "io.mosip.kernel.virusscanner.*", "io.mosip.commons.khazana.*", "io.mosip.idrepository.core.util.*", - "io.mosip.kernel.authcodeflowproxy.*"} + "io.mosip.kernel.authcodeflowproxy.*", + "io.mosip.kernel.websub.api.config"} ) @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) @Import({TokenIDGenerator.class, ValidateTokenUtil.class, CbeffImpl.class, TransliterationService.class, TransliterationServiceUtil.class , PDFGeneratorImpl.class, UinValidatorImpl.class, VidValidatorImpl.class, RidValidatorImpl.class, TemplateManagerBuilderImpl.class, - SubscriberClientImpl.class, RestTemplateHelper.class, TransliterationImpl.class, PublisherClientImpl.class, IdObjectValidatorConfig.class - , RestTemplate.class, KeyStoreImpl.class}) + RestTemplateHelper.class, TransliterationImpl.class, IdObjectValidatorConfig.class + , RestTemplate.class, KeyStoreImpl.class, WebSubPublisherClientConfig.class, + WebSubClientConfig.class,}) public class ResidentBootApplication { public static void main(String[] args) { diff --git a/resident/resident-service/src/main/java/io/mosip/resident/config/Config.java b/resident/resident-service/src/main/java/io/mosip/resident/config/Config.java index 08de612bc72..840614330c7 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/config/Config.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/config/Config.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Properties; +import io.mosip.kernel.websub.api.config.WebSubClientConfig; import jakarta.servlet.Filter; import org.apache.commons.collections.CollectionUtils; @@ -22,6 +23,7 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; import org.springframework.core.env.Environment; import org.springframework.core.io.Resource; @@ -49,6 +51,7 @@ @Configuration @EnableScheduling @EnableAsync +@Import(WebSubClientConfig.class) public class Config { private String defaultEncoding = StandardCharsets.UTF_8.name(); /** The resource loader. */ @@ -68,7 +71,15 @@ public class Config { @Value("${" + ResidentConstants.RESIDENT_REST_TEMPLATE_METRICS_INTERCEPTOR_FILTER_ENABLED + ":false}") private boolean isResidentMetricsInterceptorFilterEnabled; - + + @Value("${task.scheduler.pool-size:10}") + private int poolSize; + + @Value("${task.scheduler.await-termination-seconds:30}") + private int awaitTerminationSeconds; + + @Value("${task.scheduler.wait-for-tasks-to-complete-on-shutdown:true}") + private boolean waitForTasksToCompleteOnShutdown; @Autowired(required = false) private RestTemplateLoggingInterceptor restTemplateLoggingInterceptor; @@ -172,8 +183,10 @@ private void addInterceptors(RestTemplate restTemplate) { @Bean public ThreadPoolTaskScheduler threadPoolTaskScheduler() { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); - threadPoolTaskScheduler.setPoolSize(5); + threadPoolTaskScheduler.setPoolSize(poolSize); threadPoolTaskScheduler.setThreadNamePrefix("ThreadPoolTaskScheduler"); + threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(waitForTasksToCompleteOnShutdown); + threadPoolTaskScheduler.setAwaitTerminationSeconds(awaitTerminationSeconds); return threadPoolTaskScheduler; } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/config/TrailingSlashRedirectFilter.java b/resident/resident-service/src/main/java/io/mosip/resident/config/TrailingSlashRedirectFilter.java index c283efa0871..5005486fceb 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/config/TrailingSlashRedirectFilter.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/config/TrailingSlashRedirectFilter.java @@ -7,6 +7,10 @@ import java.io.IOException; +/** +@author Kamesh Shekhar Prasad + */ + @Component public class TrailingSlashRedirectFilter implements Filter { @@ -16,9 +20,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha HttpServletRequest httpRequest = (HttpServletRequest) request; String path = httpRequest.getRequestURI(); - - // For other types of requests, handle the trailing slash redirection - if (path.endsWith("/")) { + if (path.endsWith("/") && !path.endsWith("status/")) { String newPath = path.substring(0, path.length() - 1); HttpServletRequest newRequest = new CustomHttpServletRequestWrapper(httpRequest, newPath); chain.doFilter(newRequest, response); diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/BaseWebSubInitializer.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/BaseWebSubInitializer.java index 95466acf646..ab09bcbad0f 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/BaseWebSubInitializer.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/BaseWebSubInitializer.java @@ -89,32 +89,53 @@ public class BaseWebSubInitializer implements ApplicationListener { - //Invoke topic registrations. This is done only once. - //Note: With authenticated websub, only register topics which are only published by IDA - tryRegisteringTopics(); - //Init topic subscriptions - initTopicSubscriptions(); - }, new Date(System.currentTimeMillis() + taskSubscriptionInitialDelay)); - - if (reSubscriptionIntervalSecs > 0) { - logger.info("Work around for web-sub notification issue after some time."); - scheduleRetrySubscriptions(); - } else { - logger.info("Scheduling for re-subscription is Disabled as the re-subsctription delay value is: " - + reSubscriptionIntervalSecs); - } + try { + // Invoke topic registrations (done only once) + tryRegisteringTopics(); + // Initialize topic subscriptions + initTopicSubscriptions(); + } catch (Exception e) { + logger.error("Error while scheduling topic registrations and subscriptions", e); + } + }, trigger -> { + // Schedule task to execute once after the initial delay + return new Date(System.currentTimeMillis() + taskSubscriptionInitialDelay).toInstant(); + }); + if (reSubscriptionIntervalSecs > 0) { + logger.info("Workaround for web-sub notification issue after some time."); + scheduleRetrySubscriptions(); + } else { + logger.info("Re-subscription scheduling is disabled as the re-subscription interval is: " + + reSubscriptionIntervalSecs); + } } - private void initTopicSubscriptions() { + + private void initTopicSubscriptions() { authTypStatusTopicSubsriptions(); authTransactionTopicSubscription(); credentialStatusUpdateTopicSubscription(); diff --git a/resident/resident-service/src/main/resources/bootstrap.properties b/resident/resident-service/src/main/resources/bootstrap.properties index cc6f20acce1..afc3286e53a 100644 --- a/resident/resident-service/src/main/resources/bootstrap.properties +++ b/resident/resident-service/src/main/resources/bootstrap.properties @@ -31,4 +31,4 @@ openapi.info.license.url=https://docs.mosip.io/platform/license mosipbox.public.url=http://localhost:8099 openapi.residentServiceServer.servers[0].url=${mosipbox.public.url}/resident/v1 openapi.residentServiceServer.servers[0].description=Resident Service -spring.devtools.restart.enabled = false +spring.devtools.restart.enabled = false \ No newline at end of file