Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopareceiptpdfdatastore
description: Microservice description
type: application
version: 0.153.0
appVersion: 1.17.7
version: 0.156.0
appVersion: 1.17.7-3-PIDM-1661-fix-helpdesk-cron-oom
dependencies:
- name: microservice-chart
version: 8.0.2
Expand Down
3 changes: 2 additions & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: "pagopa-receipt-pdf-datastore"
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-datastore
tag: "1.17.7"
tag: "1.17.7-3-PIDM-1661-fix-helpdesk-cron-oom"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand Down Expand Up @@ -125,6 +125,7 @@ microservice-chart: &microservice-chart
MAX_DATE_DIFF_NOTIFY_MILLIS: "1800000" # 30min
RECOVER_FAILED_MASSIVE_MAX_DAYS: "0"
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0"
MASSIVE_OPERATION_MAX_PROCESSABLE_ITEMS: "5000"
ECOMMERCE_FILTER_ENABLED: "false"
ENABLE_CART: "true"
AUTHENTICATED_CHANNELS: "IO,CHECKOUT,WISP,CHECKOUT_CART"
Expand Down
11 changes: 6 additions & 5 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: "pagopa-receipt-pdf-datastore"
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-datastore
tag: "1.17.7"
tag: "1.17.7-3-PIDM-1661-fix-helpdesk-cron-oom"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand Down Expand Up @@ -117,14 +117,15 @@ microservice-chart: &microservice-chart
RECOVER_NOT_NOTIFY_CART_SCHEDULE: "0 30 */2 * * *"
RECOVER_FAILED_CRON: "0 0 */2 * * *"
RECOVER_CART_FAILED_CRON: "0 0 */2 * * *"
FAILED_AUTORECOVER_ENABLED: "false"
FAILED_CART_AUTORECOVER_ENABLED: "false"
NOT_NOTIFIED_AUTORECOVER_ENABLED: "false"
NOT_NOTIFIED_CART_AUTORECOVER_ENABLED: "false"
FAILED_AUTORECOVER_ENABLED: "true"
FAILED_CART_AUTORECOVER_ENABLED: "true"
NOT_NOTIFIED_AUTORECOVER_ENABLED: "true"
NOT_NOTIFIED_CART_AUTORECOVER_ENABLED: "true"
MAX_DATE_DIFF_MILLIS: "1800000" # 30min
MAX_DATE_DIFF_NOTIFY_MILLIS: "1800000" # 30min
RECOVER_FAILED_MASSIVE_MAX_DAYS: "0"
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0"
MASSIVE_OPERATION_MAX_PROCESSABLE_ITEMS: "5000"
ECOMMERCE_FILTER_ENABLED: "false"
ENABLE_CART: "true"
AUTHENTICATED_CHANNELS: "IO,CHECKOUT,WISP,CHECKOUT_CART"
Expand Down
3 changes: 2 additions & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: "pagopa-receipt-pdf-datastore"
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-datastore
tag: "1.17.7"
tag: "1.17.7-3-PIDM-1661-fix-helpdesk-cron-oom"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand Down Expand Up @@ -125,6 +125,7 @@ microservice-chart: &microservice-chart
MAX_DATE_DIFF_NOTIFY_MILLIS: "1800000" # 30min
RECOVER_FAILED_MASSIVE_MAX_DAYS: "0"
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0"
MASSIVE_OPERATION_MAX_PROCESSABLE_ITEMS: "5000"
ECOMMERCE_FILTER_ENABLED: "false"
ENABLE_CART: "true"
AUTHENTICATED_CHANNELS: "IO,CHECKOUT,WISP,CHECKOUT_CART"
Expand Down
8 changes: 4 additions & 4 deletions integration-test/src/features/receipt_pdf_helpdesk.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ Feature: All about payment events to recover managed by Azure functions receipt-

Scenario: recoverFailedReceipt API retrieve a receipt in status FAILED and updates its status
Given a receipt with eventId "receipt-datastore-helpdesk-int-test-id-2" and status "FAILED" stored into receipt datastore
And a biz event with id "receipt-datastore-helpdesk-int-test-id-2" and status "DONE" stored on biz-events datastore
And a biz event with id "receipt-datastore-helpdesk-int-test-id-2" and status DONE stored on biz-events datastore
When recoverFailedReceipt API is called with eventId "receipt-datastore-helpdesk-int-test-id-2"
Then the api response has a 200 Http status
And the receipt with eventId "receipt-datastore-helpdesk-int-test-id-2" is recovered from datastore
And the receipt has not status "FAILED"

Scenario: recoverFailedReceiptMassive API retrieve all the receipts in status FAILED and updates their status
Given a list of 5 receipts in status "FAILED" stored into receipt datastore starting from eventId "receipt-datastore-helpdesk-int-test-id-3"
And a list of 5 biz events in status "DONE" stored into biz-events datastore starting from eventId "receipt-datastore-helpdesk-int-test-id-3"
And a list of 5 biz events in status DONE stored into biz-events datastore starting from eventId "receipt-datastore-helpdesk-int-test-id-3"
When recoverFailedReceiptMassive API is called with status "FAILED" as query param
Then the api response has a 200 Http status
And the list of receipt is recovered from datastore and no receipt in the list has status "FAILED"

Scenario: recoverNotNotifiedReceipt API retrieve a receipt in status IO_ERROR_TO_NOTIFY and updates its status
Given a receipt with eventId "receipt-datastore-helpdesk-int-test-id-4" and status "IO_ERROR_TO_NOTIFY" stored into receipt datastore
And a biz event with id "receipt-datastore-helpdesk-int-test-id-4" and status "DONE" stored on biz-events datastore
And a biz event with id "receipt-datastore-helpdesk-int-test-id-4" and status DONE stored on biz-events datastore
When recoverNotNotifiedReceipt API is called with eventId "receipt-datastore-helpdesk-int-test-id-4"
Then the api response has a 200 Http status
And the receipt with eventId "receipt-datastore-helpdesk-int-test-id-4" is recovered from datastore
And the receipt has not status "IO_ERROR_TO_NOTIFY"

Scenario: recoverNotNotifiedReceiptMassive API retrieve all the receipts in status IO_ERROR_TO_NOTIFY and updates their status
Given a list of 5 receipts in status "IO_ERROR_TO_NOTIFY" stored into receipt datastore starting from eventId "receipt-datastore-helpdesk-int-test-id-5"
And a list of 5 biz events in status "DONE" stored into biz-events datastore starting from eventId "receipt-datastore-helpdesk-int-test-id-5"
And a list of 5 biz events in status DONE stored into biz-events datastore starting from eventId "receipt-datastore-helpdesk-int-test-id-5"
When recoverNotNotifiedReceiptMassive API is called with status "IO_ERROR_TO_NOTIFY" as query param
Then the api response has a 200 Http status
And the list of receipt is recovered from datastore and no receipt in the list has status "IO_ERROR_TO_NOTIFY"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ Given('a receipt with eventId {string} and status {string} stored into receipt d
assert.strictEqual(receiptsStoreResponse.statusCode, 201);
});

Given('a biz event with id {string} and status {string} stored on biz-events datastore', async function (id, status) {
Given('a biz event with id {string} and status DONE stored on biz-events datastore', async function (id) {
helpdesk_eventId = id;
// prior cancellation to avoid dirty cases
await deleteDocumentFromBizEventsDatastore(helpdesk_eventId);

let bizEventStoreResponse = await createDocumentInBizEventsDatastore(helpdesk_eventId, status);
let bizEventStoreResponse = await createDocumentInBizEventsDatastore(helpdesk_eventId);
assert.strictEqual(bizEventStoreResponse.statusCode, 201);
});

Expand Down Expand Up @@ -180,13 +180,13 @@ Given("a list of {int} receipts in status {string} stored into receipt datastore
}
});

Given("a list of {int} biz events in status {string} stored into biz-events datastore starting from eventId {string}", async function (numberOfEvents, status, startingId) {
Given("a list of {int} biz events in status DONE stored into biz-events datastore starting from eventId {string}", async function (numberOfEvents, startingId) {
for (let i = 0; i < numberOfEvents; i++) {
let nextEventId = `${startingId}-${i}`;
// prior cancellation to avoid dirty cases
await deleteDocumentFromBizEventsDatastore(nextEventId);

let bizEventStoreResponse = await createDocumentInBizEventsDatastore(nextEventId, status);
let bizEventStoreResponse = await createDocumentInBizEventsDatastore(nextEventId);
assert.strictEqual(bizEventStoreResponse.statusCode, 201);
}
});
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "Receipts Datastore Helpdesk",
"description": "Microservice for exposing REST APIs about receipts datastore helpdesk.",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "1.17.7"
"version": "1.17.7-3-PIDM-1661-fix-helpdesk-cron-oom"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>it.gov.pagopa.receipt</groupId>
<artifactId>receipt-pdf-datastore</artifactId>
<version>1.17.7</version>
<version>1.17.7-3-PIDM-1661-fix-helpdesk-cron-oom</version>
<packaging>jar</packaging>

<name>pagopa-receipt-pdf-datastore</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void processBizEventToReceipt(
containerName = "cart-for-receipts",
connection = "COSMOS_RECEIPTS_CONN_STRING")
OutputBinding<List<CartForReceipt>> cartDocumentdb,
final ExecutionContext context) {
final ExecutionContext context
) {

int itemsDone = 0;
List<Receipt> receiptFailed = new ArrayList<>();
Expand Down Expand Up @@ -121,7 +122,7 @@ public void processBizEventToReceipt(
logger.debug("[{}] function called at {} for event with id {} and status {}",
context.getFunctionName(), LocalDateTime.now(), bizEvent.getId(), bizEvent.getEventStatus());

Integer totalNotice = getTotalNotice(bizEvent, logger);
Integer totalNotice = getTotalNotice(bizEvent);
if (totalNotice == 1) {

Receipt receipt = createReceipt(bizEvent, this.bizEventToReceiptService, logger);
Expand Down Expand Up @@ -200,7 +201,7 @@ private boolean isInvalid(BizEvent bizEvent) {
}

private boolean isBizEventAlreadyProcessed(ExecutionContext context, BizEvent bizEvent) {
Integer totalNotice = getTotalNotice(bizEvent, logger);
Integer totalNotice = getTotalNotice(bizEvent);
if (totalNotice == 1) {
try {
Receipt receipt = this.bizEventToReceiptService.getReceipt(bizEvent.getId());
Expand All @@ -211,11 +212,10 @@ private boolean isBizEventAlreadyProcessed(ExecutionContext context, BizEvent bi
// the receipt does not exist
}
} else {
String transactionId = bizEvent.getTransactionDetails().getTransaction().getTransactionId();
try {
String transactionId = bizEvent.getTransactionDetails().getTransaction().getTransactionId();
CartForReceipt cart = this.bizEventToReceiptService.getCartForReceipt(transactionId);
if (isBizEventInCart(cart, bizEvent.getId())
) {
if (isBizEventInCart(cart, bizEvent.getId())) {
logger.debug("[{}] event with id {} discarded because already processed, cart-for-receipts already exist with id {}",
context.getFunctionName(), bizEvent.getId(), transactionId);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosContainer;
import com.azure.cosmos.CosmosDatabase;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.util.CosmosPagedIterable;
import com.azure.cosmos.models.PartitionKey;
import it.gov.pagopa.receipt.pdf.datastore.client.BizEventCosmosClient;
import it.gov.pagopa.receipt.pdf.datastore.entity.event.BizEvent;
import it.gov.pagopa.receipt.pdf.datastore.exception.BizEventNotFoundException;
Expand Down Expand Up @@ -55,18 +56,10 @@ public BizEvent getBizEventDocument(String bizEventId) throws BizEventNotFoundEx
CosmosDatabase cosmosDatabase = this.cosmosClient.getDatabase(databaseId);
CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerId);

//Build query
String query = String.format("SELECT * FROM c WHERE c.id = '%s'",
bizEventId);

//Query the container
CosmosPagedIterable<BizEvent> queryResponse = cosmosContainer
.queryItems(query, new CosmosQueryRequestOptions(), BizEvent.class);

if (queryResponse.iterator().hasNext()) {
return queryResponse.iterator().next();
} else {
throw new BizEventNotFoundException("Document not found in the defined container");
try {
return cosmosContainer.readItem(bizEventId, new PartitionKey(bizEventId), BizEvent.class).getItem();
} catch (CosmosException e) {
throw new BizEventNotFoundException("Document not found in the defined container", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosContainer;
import com.azure.cosmos.CosmosDatabase;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.implementation.PreconditionFailedException;
import com.azure.cosmos.models.CosmosItemRequestOptions;
import com.azure.cosmos.models.CosmosItemResponse;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.FeedResponse;
import com.azure.cosmos.models.PartitionKey;
import com.microsoft.azure.functions.HttpStatus;
import it.gov.pagopa.receipt.pdf.datastore.client.CartReceiptsCosmosClient;
import it.gov.pagopa.receipt.pdf.datastore.entity.cart.CartForReceipt;
import it.gov.pagopa.receipt.pdf.datastore.entity.cart.CartStatusType;
Expand All @@ -20,7 +23,6 @@
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Optional;

public class CartReceiptsCosmosClientImpl implements CartReceiptsCosmosClient {

Expand Down Expand Up @@ -65,8 +67,14 @@ public static CartReceiptsCosmosClientImpl getInstance() {

@Override
public CartForReceipt getCartItem(String cartId) throws CartNotFoundException {
return getDocumentByFilter(cartForReceiptContainerName, "cartId", cartId, CartForReceipt.class)
.orElseThrow(() -> new CartNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG));
CosmosDatabase cosmosDatabase = this.cosmosClient.getDatabase(databaseId);
CosmosContainer cosmosContainer = cosmosDatabase.getContainer(cartForReceiptContainerName);

try {
return cosmosContainer.readItem(cartId, new PartitionKey(cartId), CartForReceipt.class).getItem();
} catch (CosmosException e) {
throw new CartNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG);
}
}

/**
Expand All @@ -88,8 +96,17 @@ public CosmosItemResponse<CartForReceipt> updateCart(CartForReceipt receipt) thr
*/
@Override
public CartReceiptError getCartReceiptError(String cartId) throws CartNotFoundException {
return getDocumentByFilter(cartReceiptsMessageErrorsContainerName, "id", cartId, CartReceiptError.class)
.orElseThrow(() -> new CartNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG));
CosmosDatabase cosmosDatabase = this.cosmosClient.getDatabase(databaseId);
CosmosContainer cosmosContainer = cosmosDatabase.getContainer(cartReceiptsMessageErrorsContainerName);

CosmosItemResponse<CartReceiptError> response =
cosmosContainer.readItem(cartId, new PartitionKey(cartId), CartReceiptError.class);

if (response.getStatusCode() == HttpStatus.OK.value()) {
return response.getItem();
}

throw new CartNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG);
}

/**
Expand Down Expand Up @@ -158,24 +175,6 @@ public Iterable<FeedResponse<CartForReceipt>> getGeneratedCartReceiptDocuments(
* PRIVATE METHODS
*/

private <T> Optional<T> getDocumentByFilter(
String containerId,
String propertyName,
String propertyValue,
Class<T> classType
) {
CosmosDatabase cosmosDatabase = this.cosmosClient.getDatabase(databaseId);
CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerId);

String query = String.format("SELECT * FROM c WHERE c.%s = '%s'", propertyName, propertyValue);

// use stream() to convert iterable and find first element
return cosmosContainer
.queryItems(query, new CosmosQueryRequestOptions(), classType)
.stream()
.findFirst();
}

private Iterable<FeedResponse<CartForReceipt>> executePagedQuery(
String containerName,
String query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public RecoverFailedCartReceipt() {
* <li> check cart receipt {@link CartStatusType}-> if it is no among the processable ones, error</li>
* <li> try to retrieve the list of biz events -> if it doesn't find it, error</li>
* <li> check that the biz events are valid: {@link BizEventToReceiptUtils#isBizEventInvalid(BizEvent)} -> if invalid, error</li>
* <li> check that the biz events are valid: {@link BizEventToReceiptUtils#getTotalNotice(BizEvent, Logger)} == biz event list size -> if not, error</li>
* <li> check that the biz events are valid: {@link BizEventToReceiptUtils#getTotalNotice(BizEvent)} == biz event list size -> if not, error</li>
* <li> recreate the receipt from the biz</li>
* <li> if everything is OK, it updates the receipt on the cosmos</li>
* <li> if everything is OK, send it to the queue</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public RecoverFailedReceipt() {
* <ul>
* <li>try to retrieve the biz event -> if it doesn't find it, error</li>
* <li>check that it's a valid biz: {@link BizEventToReceiptUtils#isBizEventInvalid(BizEvent)} -> if invalid, error</li>
* <li>check that it's not a cart biz: {@link BizEventToReceiptUtils#getTotalNotice(BizEvent, Logger)} == 1 -> if cart, error</li>
* <li>check that it's not a cart biz: {@link BizEventToReceiptUtils#getTotalNotice(BizEvent)} == 1 -> if cart, error</li>
* <li>check that the receipt is in one of the 3 manageable states -> if not, error</li>
* <li>recreate the receipt from the biz: {@link BizEventToReceiptUtils#createReceipt(BizEvent, BizEventToReceiptService, Logger)} </li>
* <li>if everything is OK, it updates the receipt on the cosmos. {@link BizEventToReceiptService#handleSaveReceipt(Receipt)}</li>
Expand Down
Loading
Loading