diff options
Diffstat (limited to 'src/main')
14 files changed, 70 insertions, 69 deletions
diff --git a/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java b/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java index 0a00d1f..b232df1 100644 --- a/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java +++ b/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java @@ -35,12 +35,12 @@ import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.slf4j.LoggerFactory; +import org.springframework.core.retry.RetryException; +import org.springframework.core.retry.RetryTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.retry.TerminatedRetryException; -import org.springframework.retry.support.RetryTemplate; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -169,7 +169,7 @@ public class GicsConsentService extends AbstractConsentService { new HttpEntity<>(parameterAsXml, this.headersWithHttpBasicAuth()); try { var responseEntity = - retryTemplate.execute(ctx -> + retryTemplate.execute(() -> restTemplate.exchange( endpointUri(endpoint), HttpMethod.POST, requestEntity, String.class)); @@ -188,15 +188,20 @@ public class GicsConsentService extends AbstractConsentService { log.error(msg); return null; - } catch (TerminatedRetryException terminatedRetryException) { + } catch (RetryException retryException) { + if (retryException.getCause() instanceof URISyntaxException) { + var msg = + String.format( + "Invalid URI for consents status request: '%s'", + retryException.getCause().getMessage()); + log.error(msg); + return null; + } + var msg = String.format( "Get consents status process has been terminated. termination reason: '%s", - terminatedRetryException.getMessage()); - log.error(msg); - return null; - } catch (URISyntaxException e) { - var msg = String.format("Invalid URI for consents status request: '%s'", e.getMessage()); + retryException.getMessage()); log.error(msg); return null; } diff --git a/src/main/java/dev/dnpm/etl/processor/consent/GicsGetBroadConsentService.java b/src/main/java/dev/dnpm/etl/processor/consent/GicsGetBroadConsentService.java index eb99ebf..9ba0591 100644 --- a/src/main/java/dev/dnpm/etl/processor/consent/GicsGetBroadConsentService.java +++ b/src/main/java/dev/dnpm/etl/processor/consent/GicsGetBroadConsentService.java @@ -29,11 +29,11 @@ import org.hl7.fhir.r4.model.Bundle; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import org.slf4j.LoggerFactory; +import org.springframework.core.retry.RetryException; +import org.springframework.core.retry.RetryTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.retry.TerminatedRetryException; -import org.springframework.retry.support.RetryTemplate; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -129,7 +129,7 @@ public class GicsGetBroadConsentService extends AbstractConsentService { } final var response = - this.retryTemplate.execute(retryContext -> + this.retryTemplate.execute(() -> this.restTemplate.exchange( uri, HttpMethod.GET, new HttpEntity<>(requestHeaders), String.class)); if (response.getStatusCode().is2xxSuccessful()) { @@ -142,20 +142,20 @@ public class GicsGetBroadConsentService extends AbstractConsentService { log.error(msg); return null; } + } catch (URISyntaxException e) { + var msg = String.format("Invalid URI for consents status request: '%s'", e.getMessage()); + log.error(msg); + return null; } catch (RestClientException e) { var msg = String.format("Get consents status request failed reason: '%s", e.getMessage()); log.error(msg); return null; - } catch (TerminatedRetryException terminatedRetryException) { + } catch (RetryException retryException) { var msg = String.format( "Get consents status process has been terminated. termination reason: '%s", - terminatedRetryException.getMessage()); - log.error(msg); - return null; - } catch (URISyntaxException e) { - var msg = String.format("Invalid URI for consents status request: '%s'", e.getMessage()); + retryException.getMessage()); log.error(msg); return null; } diff --git a/src/main/java/dev/dnpm/etl/processor/pseudonym/GpasPseudonymGenerator.java b/src/main/java/dev/dnpm/etl/processor/pseudonym/GpasPseudonymGenerator.java index 2e8adf7..79db2c3 100644 --- a/src/main/java/dev/dnpm/etl/processor/pseudonym/GpasPseudonymGenerator.java +++ b/src/main/java/dev/dnpm/etl/processor/pseudonym/GpasPseudonymGenerator.java @@ -37,8 +37,8 @@ import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.core.retry.RetryTemplate; import org.springframework.http.*; -import org.springframework.retry.support.RetryTemplate; import org.springframework.web.client.HttpClientErrorException.BadRequest; import org.springframework.web.client.HttpClientErrorException.Unauthorized; import org.springframework.web.client.RestTemplate; @@ -152,8 +152,8 @@ public class GpasPseudonymGenerator implements Generator { try { var targetUrl = buildRequestUrl(apiEndpoint); ResponseEntity<String> responseEntity = - retryTemplate.execute(ctx -> - restTemplate.exchange(targetUrl, HttpMethod.POST, requestEntity, String.class)); + retryTemplate.execute( + () -> restTemplate.exchange(targetUrl, HttpMethod.POST, requestEntity, String.class)); if (responseEntity.getStatusCode().is2xxSuccessful()) { log.debug("API request succeeded. Response: {}", responseEntity.getStatusCode()); return responseEntity; diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt index 44fd719..dba0f3c 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt @@ -42,15 +42,10 @@ import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Conditional import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.ConfigurationCondition +import org.springframework.core.retry.* import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration import org.springframework.http.converter.StringHttpMessageConverter import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter -import org.springframework.retry.RetryCallback -import org.springframework.retry.RetryContext -import org.springframework.retry.RetryListener -import org.springframework.retry.policy.SimpleRetryPolicy -import org.springframework.retry.support.RetryTemplate -import org.springframework.retry.support.RetryTemplateBuilder import org.springframework.scheduling.annotation.EnableScheduling import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.security.provisioning.InMemoryUserDetailsManager @@ -189,24 +184,33 @@ class AppConfiguration { @Bean fun retryTemplate(configProperties: AppConfigProperties): RetryTemplate { - return RetryTemplateBuilder() - .notRetryOn(IllegalArgumentException::class.java) - .notRetryOn(HttpClientErrorException.BadRequest::class.java) - .notRetryOn(HttpClientErrorException.UnprocessableContent::class.java) - .exponentialBackoff(2.seconds.toJavaDuration(), 1.25, 5.seconds.toJavaDuration()) - .customPolicy(SimpleRetryPolicy(configProperties.maxRetryAttempts)) - .withListener( - object : RetryListener { - override fun <T : Any, E : Throwable> onError( - context: RetryContext, - callback: RetryCallback<T, E>, - throwable: Throwable, - ) { - logger.warn("Error occured: {}. Retrying {}", throwable.message, context.retryCount) - } - } + val retryPolicy = RetryPolicy.builder() + .excludes( + IllegalArgumentException::class.java, + HttpClientErrorException.BadRequest::class.java, + HttpClientErrorException.UnprocessableContent::class.java ) + .maxRetries(configProperties.maxRetryAttempts.toLong() - 1) + .delay(2.seconds.toJavaDuration()) + .multiplier(1.25) + .maxDelay(5.seconds.toJavaDuration()) .build() + + return RetryTemplate(retryPolicy).apply { + setRetryListener(object : RetryListener { + override fun onRetryableExecution( + retryPolicy: RetryPolicy, + retryable: Retryable<*>, + retryState: RetryState, + ) { + logger.warn( + "Error occured: {}. Retrying {}", + retryState.lastException.message, + retryState.retryCount + ) + } + }) + } } @ConditionalOnProperty(value = ["app.security.enable-tokens"], havingValue = "true") diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppKafkaConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppKafkaConfiguration.kt index aa3e6cb..df23857 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppKafkaConfiguration.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppKafkaConfiguration.kt @@ -37,11 +37,11 @@ import org.springframework.context.ApplicationEventPublisher import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.core.annotation.Order +import org.springframework.core.retry.RetryTemplate import org.springframework.kafka.core.ConsumerFactory import org.springframework.kafka.core.KafkaTemplate import org.springframework.kafka.listener.ContainerProperties import org.springframework.kafka.listener.KafkaMessageListenerContainer -import org.springframework.retry.support.RetryTemplate import reactor.core.publisher.Sinks import tools.jackson.databind.json.JsonMapper diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppRestConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppRestConfiguration.kt index 7965f96..51004ff 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppRestConfiguration.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppRestConfiguration.kt @@ -34,7 +34,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.core.annotation.Order -import org.springframework.retry.support.RetryTemplate +import org.springframework.core.retry.RetryTemplate import org.springframework.web.client.RestTemplate import reactor.core.publisher.Sinks diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppRoutedRestConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppRoutedRestConfiguration.kt index f962a6c..13d7eed 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppRoutedRestConfiguration.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppRoutedRestConfiguration.kt @@ -29,7 +29,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.core.annotation.Order -import org.springframework.retry.support.RetryTemplate +import org.springframework.core.retry.RetryTemplate import org.springframework.web.client.RestTemplate @Configuration diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/KafkaMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/KafkaMtbFileSender.kt index dd988ed..2fb1281 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/KafkaMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/KafkaMtbFileSender.kt @@ -27,8 +27,8 @@ import dev.pcvolkmer.mv64e.model.MvhMetadata import dev.pcvolkmer.mv64e.model.PatientRecord import org.apache.kafka.clients.producer.ProducerRecord import org.slf4j.LoggerFactory +import org.springframework.core.retry.RetryTemplate import org.springframework.kafka.core.KafkaTemplate -import org.springframework.retry.support.RetryTemplate import tools.jackson.databind.json.JsonMapper class KafkaMtbFileSender( @@ -41,7 +41,7 @@ class KafkaMtbFileSender( override fun <T> send(request: MtbFileRequest<T>): MtbFileSender.Response { return try { - return retryTemplate.execute<MtbFileSender.Response, Exception> { + return retryTemplate.execute { val record = ProducerRecord( kafkaProperties.outputTopic, @@ -79,7 +79,7 @@ class KafkaMtbFileSender( val dummyMtbFile = PatientRecord.builder().metadata(MvhMetadata()).build() return try { - return retryTemplate.execute<MtbFileSender.Response, Exception> { + return retryTemplate.execute { val record = ProducerRecord( kafkaProperties.outputTopic, diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/RestDipMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/RestDipMtbFileSender.kt index 1bcca5e..676a2e9 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/RestDipMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/RestDipMtbFileSender.kt @@ -24,18 +24,10 @@ import dev.dnpm.etl.processor.CustomMediaType import dev.dnpm.etl.processor.PatientPseudonym import dev.dnpm.etl.processor.config.RestTargetProperties import dev.dnpm.etl.processor.monitoring.ReportService -import dev.dnpm.etl.processor.monitoring.RequestStatus -import dev.dnpm.etl.processor.monitoring.asRequestStatus -import org.slf4j.LoggerFactory -import org.springframework.http.HttpEntity +import org.springframework.core.retry.RetryTemplate import org.springframework.http.HttpHeaders -import org.springframework.http.HttpMethod import org.springframework.http.MediaType -import org.springframework.retry.support.RetryTemplate -import org.springframework.web.client.RestClientException -import org.springframework.web.client.RestClientResponseException import org.springframework.web.client.RestTemplate -import org.springframework.web.client.exchange import org.springframework.web.util.UriComponentsBuilder class RestDipMtbFileSender( diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt index c88f606..722eed3 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt @@ -27,11 +27,11 @@ import dev.dnpm.etl.processor.monitoring.ReportService import dev.dnpm.etl.processor.monitoring.RequestStatus import dev.dnpm.etl.processor.monitoring.asRequestStatus import org.slf4j.LoggerFactory +import org.springframework.core.retry.RetryTemplate import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod import org.springframework.http.MediaType -import org.springframework.retry.support.RetryTemplate import org.springframework.web.client.RestClientException import org.springframework.web.client.RestClientResponseException import org.springframework.web.client.RestTemplate @@ -52,7 +52,7 @@ abstract class RestMtbFileSender( override fun <T> send(request: MtbFileRequest<T>): MtbFileSender.Response { try { - return retryTemplate.execute<MtbFileSender.Response, Exception> { + return retryTemplate.execute { val headers = getHttpHeaders(request) val entityReq = HttpEntity(request.content, headers) val response = @@ -85,7 +85,7 @@ abstract class RestMtbFileSender( override fun send(request: DeleteRequest): MtbFileSender.Response { try { - return retryTemplate.execute<MtbFileSender.Response, Exception> { + return retryTemplate.execute { val headers = getHttpHeaders(request) val entityReq = HttpEntity(null, headers) restTemplate.delete(deleteUrl(request.patientId), entityReq, String::class.java) diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/RestNngmMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/RestNngmMtbFileSender.kt index 13722d2..dac291f 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/RestNngmMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/RestNngmMtbFileSender.kt @@ -23,9 +23,9 @@ package dev.dnpm.etl.processor.output import dev.dnpm.etl.processor.PatientPseudonym import dev.dnpm.etl.processor.config.RestTargetProperties import dev.dnpm.etl.processor.monitoring.ReportService +import org.springframework.core.retry.RetryTemplate import org.springframework.http.HttpHeaders import org.springframework.http.MediaType -import org.springframework.retry.support.RetryTemplate import org.springframework.web.client.RestTemplate import org.springframework.web.util.UriComponentsBuilder diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/RoutedRestNngmMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/RoutedRestNngmMtbFileSender.kt index 957645e..8c3f3bd 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/RoutedRestNngmMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/RoutedRestNngmMtbFileSender.kt @@ -27,11 +27,11 @@ import dev.dnpm.etl.processor.monitoring.asRequestStatus import dev.pcvolkmer.mv64e.model.MtbDiagnosis import dev.pcvolkmer.mv64e.model.PatientRecord import org.slf4j.LoggerFactory +import org.springframework.core.retry.RetryTemplate import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod import org.springframework.http.MediaType -import org.springframework.retry.support.RetryTemplate import org.springframework.web.client.RestClientResponseException import org.springframework.web.client.RestTemplate import org.springframework.web.client.exchange @@ -67,7 +67,7 @@ class RoutedRestNngmMtbFileSender( override fun send(request: MtbFileRequest<PatientRecord>): MtbFileSender.Response { try { - return retryTemplate.execute<MtbFileSender.Response, Exception> { + return retryTemplate.execute { val entityReq = HttpEntity(request.content, getHttpHeaders()) val response = restTemplate.exchange<String>(sendUrl(), HttpMethod.POST, entityReq) diff --git a/src/main/kotlin/dev/dnpm/etl/processor/pseudonym/GpasSoapPseudonymGenerator.kt b/src/main/kotlin/dev/dnpm/etl/processor/pseudonym/GpasSoapPseudonymGenerator.kt index 589a2d4..d166065 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/pseudonym/GpasSoapPseudonymGenerator.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/pseudonym/GpasSoapPseudonymGenerator.kt @@ -22,7 +22,7 @@ package dev.dnpm.etl.processor.pseudonym import dev.dnpm.etl.processor.config.AppFhirConfig import dev.dnpm.etl.processor.config.GPasConfigProperties -import org.springframework.retry.support.RetryTemplate +import org.springframework.core.retry.RetryTemplate class GpasSoapPseudonymGenerator( private val gpasCfg: GPasConfigProperties, @@ -31,12 +31,12 @@ class GpasSoapPseudonymGenerator( private val appFhirConfig: AppFhirConfig, ) : Generator { override fun generate(id: String): String = - retryTemplate.execute<String, Exception> { + retryTemplate.execute { gpasSoapService.getOrCreatePseudonymFor(id, gpasCfg.patientDomain) } override fun generateGenomDeTan(id: String): String = - retryTemplate.execute<String, Exception> { + retryTemplate.execute { gpasSoapService.createPseudonymsFor(id, gpasCfg.genomDeTanDomain, 1).first() } } diff --git a/src/main/kotlin/dev/dnpm/etl/processor/pseudonym/VfpsPseudonymGenerator.kt b/src/main/kotlin/dev/dnpm/etl/processor/pseudonym/VfpsPseudonymGenerator.kt index 0a616b5..dcfef86 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/pseudonym/VfpsPseudonymGenerator.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/pseudonym/VfpsPseudonymGenerator.kt @@ -1,10 +1,10 @@ package dev.dnpm.etl.processor.pseudonym import dev.dnpm.etl.processor.config.VfpsConfigProperties +import org.springframework.core.retry.RetryTemplate import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.MediaType -import org.springframework.retry.support.RetryTemplate import org.springframework.web.client.RestClientException import org.springframework.web.client.RestTemplate import org.springframework.web.client.postForObject @@ -29,7 +29,7 @@ class VfpsPseudonymGenerator( override fun generate(id: String): String = execute { - retryTemplate.execute<String, Exception> { + retryTemplate.execute { request(configProperties.patientNamespace, "pseudonyms", id) } } |
