Skip to content

Commit

Permalink
Merge pull request #221 from pagopa/release-uat
Browse files Browse the repository at this point in the history
fix: Release uat
  • Loading branch information
antonioT90 authored Oct 26, 2023
2 parents 4c879a4 + 381ee2d commit ff16831
Show file tree
Hide file tree
Showing 18 changed files with 298 additions and 208 deletions.
3 changes: 2 additions & 1 deletion .grype.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ignore:
# false positive match on reactor-netty packages due to a bug on grype: https://github.com/anchore/grype/issues/431
# Actually we are using netty 4.1.94
# Actually we are using netty 4.1.100
- vulnerability: CVE-2014-3488 # solved in netty 3.9.2
- vulnerability: CVE-2015-2156 # solved in netty 4.1.42
- vulnerability: CVE-2019-16869 # solved in netty 4.1.42
Expand All @@ -15,3 +15,4 @@ ignore:
- vulnerability: CVE-2022-24823 # solved in netty 4.1.77
- vulnerability: CVE-2022-41881 # solved in netty 4.1.86
- vulnerability: CVE-2023-34462 # solved in netty 4.1.94
- vulnerability: CVE-2023-44487 # solved in netty 4.1.100
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Build
#
FROM maven:3.9.4-amazoncorretto-17-al2023@sha256:c7719f952f62e301c6c24b86ef9a2ea1cd0a314a862ed12e51f0ffbc3fbb96b5 AS buildtime
FROM maven:3.9.5-amazoncorretto-17-al2023@sha256:b7f94a5f1b6582a045692e31c2c97ef6f0ed867961669a0adbc2d5f0bbf8bc85 AS buildtime

WORKDIR /build
COPY . .
Expand All @@ -11,7 +11,7 @@ RUN mvn clean package -DskipTests
#
# Docker RUNTIME
#
FROM amazoncorretto:17.0.8-alpine3.18@sha256:34650d7c653af234dad21cd2d89d2f0dbdb1bad54041014932e51b3492e0dec5 AS runtime
FROM amazoncorretto:17.0.9-alpine3.18@sha256:df48bf2e183230040890460ddb4359a10aa6c7aad24bd88899482c52053c7e17 AS runtime

RUN apk add shadow
RUN useradd --uid 10000 runner
Expand All @@ -21,7 +21,7 @@ WORKDIR /app

COPY --from=buildtime /build/target/*.jar /app/app.jar
# The agent is enabled at runtime via JAVA_TOOL_OPTIONS.
ADD https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.16/applicationinsights-agent-3.4.16.jar /app/applicationinsights-agent.jar
ADD https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.17/applicationinsights-agent-3.4.17.jar /app/applicationinsights-agent.jar

RUN chown -R runner:runner /app

Expand Down
50 changes: 29 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.3</version>
<relativePath/>
<!-- lookup parent from repository -->
<version>3.1.5</version>
</parent>

<groupId>it.gov.pagopa</groupId>
<artifactId>idpay-admissibility-assessor</artifactId>
<version>1.2.1</version>
<name>idpay-admissibility-assessor</name>
<version>1.2.1</version>

<properties>
<java.version>17</java.version>
</properties>

<dependencies>
<!--SB STARTER-->
<dependency>
Expand Down Expand Up @@ -67,41 +68,41 @@
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-stream-binder-servicebus</artifactId>
<version>5.4.0</version>
<version>5.5.0</version>
</dependency>

<!--JAX-WS-->
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.0</version>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>jakarta.xml.soap</groupId>
<artifactId>jakarta.xml.soap-api</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>4.0.1</version>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</dependency>

<!--3rd party library-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand All @@ -116,7 +117,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
<version>32.1.3-jre</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
Expand All @@ -131,7 +132,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand All @@ -143,14 +144,14 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<!-- Forced to 2.0 due to https://nvd.nist.gov/vuln/detail/CVE-2022-1471 -->
<version>2.0</version>
<!-- Forced to > 2.0 due to https://nvd.nist.gov/vuln/detail/CVE-2022-1471 -->
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<!-- Forced to 2.0 due to https://nvd.nist.gov/vuln/detail/CVE-2023-34453 -->
<version>1.1.10.3</version>
<!-- Forced to > 1.1.10.3 due to https://nvd.nist.gov/vuln/detail/CVE-2023-34453 -->
<version>1.1.10.5</version>
<scope>test</scope>
</dependency>

Expand All @@ -163,13 +164,11 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -180,7 +179,7 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-wiremock</artifactId>
<version>4.0.2</version>
<version>4.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -197,7 +196,7 @@
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo.spring30x</artifactId>
<version>4.7.0</version>
<version>4.9.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -229,6 +228,15 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-bom</artifactId>
<!-- Forced to 4.1.100 due to https://nvd.nist.gov/vuln/detail/CVE-2023-44487 -->
<version>4.1.100.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import it.gov.pagopa.admissibility.dto.commands.QueueCommandOperationDTO;
import it.gov.pagopa.admissibility.service.AdmissibilityErrorNotifierService;
import it.gov.pagopa.admissibility.service.commands.operations.DeleteInitiativeService;
import it.gov.pagopa.admissibility.service.onboarding.OnboardingContextHolderService;
import it.gov.pagopa.admissibility.utils.CommandConstants;
import it.gov.pagopa.common.reactive.kafka.consumer.BaseKafkaConsumer;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -23,20 +24,29 @@
public class CommandMediatorServiceImpl extends BaseKafkaConsumer<QueueCommandOperationDTO, String> implements CommandMediatorService{

private final Duration commitDelay;
private final Duration beneficiaryRulesBuildDelayMinusCommit;
private final DeleteInitiativeService deleteInitiativeService;
private final OnboardingContextHolderService onboardingContextHolderService;
private final AdmissibilityErrorNotifierService admissibilityErrorNotifierService;
private final ObjectReader objectReader;

public CommandMediatorServiceImpl(@Value("${spring.application.name}") String applicationName,
@Value("${spring.cloud.stream.kafka.bindings.consumerCommands-in-0.consumer.ackTime}") long commitMillis,
@Value("${app.beneficiary-rule.build-delay-duration}") String beneficiaryRulesBuildDelay,

DeleteInitiativeService deleteInitiativeService,
AdmissibilityErrorNotifierService admissibilityErrorNotifierService,
OnboardingContextHolderService onboardingContextHolderService, AdmissibilityErrorNotifierService admissibilityErrorNotifierService,
ObjectMapper objectMapper) {
super(applicationName);
this.commitDelay = Duration.ofMillis(commitMillis);
this.deleteInitiativeService = deleteInitiativeService;
this.onboardingContextHolderService = onboardingContextHolderService;
this.admissibilityErrorNotifierService = admissibilityErrorNotifierService;
this.objectReader = objectMapper.readerFor(QueueCommandOperationDTO.class);

Duration beneficiaryRulesBuildDelayDuration = Duration.parse(beneficiaryRulesBuildDelay).minusMillis(commitMillis);
Duration defaultDurationDelay = Duration.ofMillis(2L);
this.beneficiaryRulesBuildDelayMinusCommit = defaultDurationDelay.compareTo(beneficiaryRulesBuildDelayDuration) >= 0 ? defaultDurationDelay : beneficiaryRulesBuildDelayDuration;
}

@Override
Expand All @@ -47,6 +57,8 @@ protected Duration getCommitDelay() {
@Override
protected void subscribeAfterCommits(Flux<List<String>> afterCommits2subscribe) {
afterCommits2subscribe
.buffer(beneficiaryRulesBuildDelayMinusCommit)
.then(onboardingContextHolderService.refreshKieContainerCacheMiss())
.subscribe(r -> log.info("[ADMISSIBILITY_COMMANDS] Processed offsets committed successfully"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import it.gov.pagopa.admissibility.connector.repository.DroolsRuleRepository;
import it.gov.pagopa.admissibility.connector.repository.InitiativeCountersRepository;
import it.gov.pagopa.admissibility.connector.repository.OnboardingFamiliesRepository;
import it.gov.pagopa.admissibility.service.onboarding.OnboardingContextHolderService;
import it.gov.pagopa.admissibility.utils.AuditUtilities;
import it.gov.pagopa.common.reactive.utils.PerformanceLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
Expand All @@ -20,42 +20,42 @@ public class DeleteInitiativeServiceImpl implements DeleteInitiativeService{
private final InitiativeCountersRepository initiativeCountersRepository;
private final OnboardingFamiliesRepository onboardingFamiliesRepository;
private final AuditUtilities auditUtilities;
private final OnboardingContextHolderService onboardingContextHolderService;
private final int pageSize;
private final long delay;

public DeleteInitiativeServiceImpl(DroolsRuleRepository droolsRuleRepository,
InitiativeCountersRepository initiativeCountersRepository,
OnboardingFamiliesRepository onboardingFamiliesRepository,
AuditUtilities auditUtilities,
OnboardingContextHolderService onboardingContextHolderService,
@Value("${app.delete.paginationSize}") int pageSize,
@Value("${app.delete.delayTime}") long delay) {
this.droolsRuleRepository = droolsRuleRepository;
this.initiativeCountersRepository = initiativeCountersRepository;
this.onboardingFamiliesRepository = onboardingFamiliesRepository;
this.auditUtilities = auditUtilities;
this.onboardingContextHolderService = onboardingContextHolderService;
this.pageSize = pageSize;
this.delay = delay;
}

@Override
public Mono<String> execute(String initiativeId) {
log.info("[DELETE_INITIATIVE] Starting handle delete initiative {}", initiativeId);
return deleteDroolsRule(initiativeId)
.then(deleteInitiativeCounters(initiativeId))
.then(deleteOnboardingFamilies(initiativeId))
return execAndLogTiming("DELETE_DROOLS_RULE", initiativeId, deleteDroolsRule(initiativeId))
.then(execAndLogTiming("DELETE_INITIATIVE_COUNTERS", initiativeId, deleteInitiativeCounters(initiativeId)))
.then(execAndLogTiming("DELETE_ONBOARDING_FAMILIES", initiativeId, deleteOnboardingFamilies(initiativeId)))
.then(Mono.just(initiativeId));
}

private Mono<?> execAndLogTiming(String deleteFlowName, String initiativeId, Mono<?> deleteMono) {
return PerformanceLogger.logTimingFinally(deleteFlowName, deleteMono, initiativeId);
}

private Mono<Void> deleteDroolsRule(String initiativeId) {
return droolsRuleRepository.deleteById(initiativeId)
.doOnSuccess(d -> {
log.info("[DELETE_INITIATIVE] Deleted initiative {} from collection: beneficiary_rule", initiativeId);
auditUtilities.logDeletedDroolsRule(initiativeId);
})
.then(onboardingContextHolderService.refreshKieContainerCacheMiss())
.then();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.common.reactive.mongo.retry;

import it.gov.pagopa.common.reactive.web.ReactiveRequestContextHolder;
import lombok.Generated;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
Expand Down Expand Up @@ -47,6 +48,12 @@ public MongoRequestRateTooLargeAutomaticRetryAspect(
this.maxMillisElapsedBatch = maxMillisElapsedBatch;
}

@Generated
@Pointcut("execution(* org.springframework.data.mongodb.repository.*MongoRepository+.*(..))")
public void inSpringRepositoryClass() {
}

@Generated
@Pointcut("within(*..*Repository*)")
public void inRepositoryClass() {
}
Expand All @@ -59,48 +66,48 @@ public void returnMono() {
public void returnFlux() {
}

@Around("inRepositoryClass() && returnMono()")
@Around("(inRepositoryClass() or inSpringRepositoryClass()) && returnMono()")
public Object decorateMonoRepositoryMethods(ProceedingJoinPoint pjp) throws Throwable {
Mono<?> out = (Mono<?>) pjp.proceed();

return Mono.deferContextual(ctx -> decorateMethod(out, ctx));
String flowName = pjp.getSignature().toShortString();
return Mono.deferContextual(ctx -> decorateMethod(flowName, out, ctx));
}

@Around("inRepositoryClass() && returnFlux()")
@Around("(inRepositoryClass() or inSpringRepositoryClass()) && returnFlux()")
public Object decorateFluxRepositoryMethods(ProceedingJoinPoint pjp) throws Throwable {
@SuppressWarnings("unchecked") // only with Flux the compiler return error when using wildcard, so here we are using Object
Flux<Object> out = (Flux<Object>) pjp.proceed();

return Flux.deferContextual(ctx -> decorateMethod(out, ctx));
String flowName = pjp.getSignature().toShortString();
return Flux.deferContextual(ctx -> decorateMethod(flowName, out, ctx));
}

private <T extends Publisher<?>> T decorateMethod(T out, ContextView ctx) {
private <T extends Publisher<?>> T decorateMethod(String flowName, T out, ContextView ctx) {
Optional<ServerWebExchange> serverWebExchange = ctx.getOrEmpty(ReactiveRequestContextHolder.CONTEXT_KEY);
if (serverWebExchange.isEmpty()) {
if(enabledBatch) {
return invokeWithRetry(out, maxRetryBatch, maxMillisElapsedBatch);
return invokeWithRetry(flowName, out, maxRetryBatch, maxMillisElapsedBatch);
}else {
return out;
}
} else {
MongoRequestRateTooLargeApiRetryable apiRetryableConfig = getRequestRateTooLargeApiRetryableConfig(serverWebExchange.get());
if(apiRetryableConfig!=null){
return invokeWithRetry(out, apiRetryableConfig.maxRetry(), apiRetryableConfig.maxMillisElapsed());
return invokeWithRetry(flowName, out, apiRetryableConfig.maxRetry(), apiRetryableConfig.maxMillisElapsed());
} else if(enabledApi){
return invokeWithRetry(out, maxRetryApi, maxMillisElapsedApi);
return invokeWithRetry(flowName, out, maxRetryApi, maxMillisElapsedApi);
}else {
return out;
}
}
}

@SuppressWarnings("unchecked")
private <T extends Publisher<?>> T invokeWithRetry(T out, long maxRetry, long maxMillisElapsed) {
private <T extends Publisher<?>> T invokeWithRetry(String flowName, T out, long maxRetry, long maxMillisElapsed) {
if(out instanceof Mono<?> mono) {
return (T) MongoRequestRateTooLargeRetryer.withRetry(mono, maxRetry,
return (T) MongoRequestRateTooLargeRetryer.withRetry(flowName, mono, maxRetry,
maxMillisElapsed);
} else {
return (T) MongoRequestRateTooLargeRetryer.withRetry((Flux<?>) out, maxRetry,
return (T) MongoRequestRateTooLargeRetryer.withRetry(flowName, (Flux<?>) out, maxRetry,
maxMillisElapsed);
}
}
Expand Down
Loading

0 comments on commit ff16831

Please sign in to comment.