From deaf9619fe1d127f04e9e56c99a8b32d67a55cc3 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Fri, 5 Jul 2024 10:34:03 +0200 Subject: [PATCH] logging debug --- .java-version | 2 +- README.md | 5 ++ docker/run_docker.sh | 42 ++++----- .../notice/functions/ManageNoticeErrors.java | 87 ++++++++++--------- .../impl/PaymentNoticeBlobClientImpl.java | 15 ++-- 5 files changed, 80 insertions(+), 71 deletions(-) diff --git a/.java-version b/.java-version index b4de394..03b6389 100644 --- a/.java-version +++ b/.java-version @@ -1 +1 @@ -11 +17.0 diff --git a/README.md b/README.md index 8b13789..00039f5 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ +# How to Run +``` +mvn clean package +mvn azure-functions:run +``` diff --git a/docker/run_docker.sh b/docker/run_docker.sh index aa50bd4..490bf25 100644 --- a/docker/run_docker.sh +++ b/docker/run_docker.sh @@ -10,7 +10,7 @@ then echo "No environment specified: local is used." fi -pip3 install yq +#pip3 install yq if [ "$ENV" = "local" ]; then image="service-local:latest" @@ -45,23 +45,23 @@ for line in $(echo $secret | jq -r '. | to_entries[] | select(.key) | "\(.key)=\ done -stack_name=$(cd .. && basename "$PWD") -docker compose -p "${stack_name}" up -d --remove-orphans --force-recreate --build -#docker build -t receipt-pdf-generator ../ -# docker run -d -p 60486:80 --name="${stack_name}" receipt-pdf-generator - -# waiting the containers -printf 'Waiting for the service' -attempt_counter=0 -max_attempts=50 -until [ $(curl -s -o /dev/null -w "%{http_code}" http://localhost:60486/info) -eq 200 ]; do - if [ ${attempt_counter} -eq ${max_attempts} ];then - echo "Max attempts reached" - exit 1 - fi - - printf '.' - attempt_counter=$((attempt_counter+1)) - sleep 5 -done -echo 'Service Started' +#stack_name=$(cd .. && basename "$PWD") +#docker compose -p "${stack_name}" up -d --remove-orphans --force-recreate --build +##docker build -t receipt-pdf-generator ../ +## docker run -d -p 60486:80 --name="${stack_name}" receipt-pdf-generator +# +## waiting the containers +#printf 'Waiting for the service' +#attempt_counter=0 +#max_attempts=50 +#until [ $(curl -s -o /dev/null -w "%{http_code}" http://localhost:60486/info) -eq 200 ]; do +# if [ ${attempt_counter} -eq ${max_attempts} ];then +# echo "Max attempts reached" +# exit 1 +# fi +# +# printf '.' +# attempt_counter=$((attempt_counter+1)) +# sleep 5 +#done +#echo 'Service Started' diff --git a/src/main/java/it/gov/pagopa/print/payment/notice/functions/ManageNoticeErrors.java b/src/main/java/it/gov/pagopa/print/payment/notice/functions/ManageNoticeErrors.java index 44e0469..4402c49 100644 --- a/src/main/java/it/gov/pagopa/print/payment/notice/functions/ManageNoticeErrors.java +++ b/src/main/java/it/gov/pagopa/print/payment/notice/functions/ManageNoticeErrors.java @@ -1,11 +1,13 @@ - package it.gov.pagopa.print.payment.notice.functions; import com.fasterxml.jackson.core.JsonProcessingException; import com.microsoft.azure.functions.ExecutionContext; import com.microsoft.azure.functions.HttpStatus; import com.microsoft.azure.functions.OutputBinding; -import com.microsoft.azure.functions.annotation.*; +import com.microsoft.azure.functions.annotation.Cardinality; +import com.microsoft.azure.functions.annotation.EventHubOutput; +import com.microsoft.azure.functions.annotation.EventHubTrigger; +import com.microsoft.azure.functions.annotation.FunctionName; import it.gov.pagopa.print.payment.notice.functions.client.PaymentNoticeGenerationRequestErrorClient; import it.gov.pagopa.print.payment.notice.functions.client.impl.PaymentNoticeGenerationRequestErrorClientImpl; import it.gov.pagopa.print.payment.notice.functions.entity.PaymentGenerationRequestStatus; @@ -24,7 +26,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; /** * Azure Functions with Azure Queue trigger. @@ -39,11 +40,11 @@ public class ManageNoticeErrors { private final Integer maxRetriesOnErrors; - private String ERROR_STRING = "[{}] error recovering error data with id {}"; + private final String ERROR_STRING = "[{}] error recovering error data with id {}"; public ManageNoticeErrors() { this.noticeFolderService = new NoticeFolderServiceImpl(); - this.maxRetriesOnErrors = Integer.parseInt(System.getenv("MAX_RETRIES_ON_ERRORS")); + this.maxRetriesOnErrors = Integer.parseInt(System.getenv("MAX_RETRIES_ON_ERRORS")); this.paymentNoticeGenerationRequestErrorClient = PaymentNoticeGenerationRequestErrorClientImpl.getInstance(); } @@ -58,13 +59,13 @@ public ManageNoticeErrors() { /** * This function will be invoked when a EH trigger occurs - * + *

* The function will manage errors coming from the generation service, or compression function - * + *

* In both cases it will be checked if the error does exist, recovering the latest attempt, and updating * the number of attempts. Whenever the number of attempts exceeds the configured limit, no more actions * will follow. - * + *

* The retries will be sent on the dedicated channel for the specific type of error managed */ @FunctionName("ManageNoticeErrorsProcess") @@ -98,36 +99,36 @@ public void processNoticeErrors( paymentNoticeErrors.forEach(error -> { PaymentNoticeGenerationRequestError paymentNoticeGenerationRequestError = null; - try { - if (error.getId() != null) { - - paymentNoticeGenerationRequestError = - paymentNoticeGenerationRequestErrorClient.findOne(error.getId()).orElseThrow(() -> - new PaymentNoticeManagementException("Request error not found", - HttpStatus.INTERNAL_SERVER_ERROR.value())); - } else { - paymentNoticeGenerationRequestError = PaymentNoticeGenerationRequestError.builder() - .folderId(error.getFolderId()) - .errorId(error.getErrorId()) - .numberOfAttempts(error.getNumberOfAttempts()) - .compressionError(error.isCompressionError()) - .data(error.getData()) - .errorCode(error.getErrorCode()) - .errorDescription(error.getErrorDescription()) - .build(); - paymentNoticeGenerationRequestError.setId( - paymentNoticeGenerationRequestErrorClient.save(paymentNoticeGenerationRequestError)); - } - } catch (Exception e) { - logger.error(ERROR_STRING, - context.getFunctionName(), error.getFolderId(), e); + try { + if(error.getId() != null) { + + paymentNoticeGenerationRequestError = + paymentNoticeGenerationRequestErrorClient.findOne(error.getId()).orElseThrow(() -> + new PaymentNoticeManagementException("Request error not found", + HttpStatus.INTERNAL_SERVER_ERROR.value())); + } else { + paymentNoticeGenerationRequestError = PaymentNoticeGenerationRequestError.builder() + .folderId(error.getFolderId()) + .errorId(error.getErrorId()) + .numberOfAttempts(error.getNumberOfAttempts()) + .compressionError(error.isCompressionError()) + .data(error.getData()) + .errorCode(error.getErrorCode()) + .errorDescription(error.getErrorDescription()) + .build(); + paymentNoticeGenerationRequestError.setId( + paymentNoticeGenerationRequestErrorClient.save(paymentNoticeGenerationRequestError)); } + } catch (Exception e) { + logger.error(ERROR_STRING, + context.getFunctionName(), error.getFolderId(), e); + } - if (paymentNoticeGenerationRequestError != null && + if(paymentNoticeGenerationRequestError != null && error.getNumberOfAttempts() < maxRetriesOnErrors) { - if (error.isCompressionError() && + if(error.isCompressionError() && !"UNKNOWN".equals(paymentNoticeGenerationRequestError.getFolderId())) { addRequestsToRetry(paymentNoticeGenerationRequestList, context, error, paymentNoticeGenerationRequestError); } else { @@ -160,20 +161,20 @@ private void addRequestsToRetry(List { - if (!blobItem.isPrefix() && blobItem.getName().contains(".pdf")) { + if(!blobItem.isPrefix() && blobItem.getName().contains(".pdf")) { + logger.info("Get blob client. Request {}", folderId); final BlobClient blobClient = blobContainerClient.getBlobClient(blobItem.getName()); final String[] splitName = blobItem.getName().split(delimiter, 2); @@ -92,7 +93,7 @@ public BlobStorageResponse compressFolder(String folderId) { CompletableFuture future = CompletableFuture.runAsync(() -> { try (ByteArrayOutputStream fileOutputStream = new ByteArrayOutputStream()) { - if (blobClient.exists()) { + if(blobClient.exists()) { blobClient.downloadStream(fileOutputStream); zipStream.putNextEntry(new ZipEntry(finalSingleFileName)); zipStream.write(fileOutputStream.toByteArray()); @@ -103,6 +104,8 @@ public BlobStorageResponse compressFolder(String folderId) { } catch (IOException e) { throw new RuntimeException("Error processing file: " + finalSingleFileName, e); } + logger.info("Download completed. Request {}", folderId); + }); futures.add(future);