Skip to content

Commit

Permalink
Merge pull request #72 from pagopa/PAGOPA-2282
Browse files Browse the repository at this point in the history
[PAGOPA-2282]
  • Loading branch information
cap-ang authored Oct 30, 2024
2 parents a8698c9 + 365f82d commit 0cda337
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 61 deletions.
57 changes: 42 additions & 15 deletions .github/workflows/04_release_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ on:
- dev
- uat
- prod
semver:
version:
required: false
type: choice
description: Select the version
options:
- ''
- skip
- promote
- patch
- skip_or_promote
- new_release
- breaking_change
beta:
Expand All @@ -40,10 +38,6 @@ on:
environment:
required: true
type: string
semver:
required: true
type: string
default: skip

permissions:
packages: write
Expand All @@ -59,14 +53,47 @@ jobs:
name: Setup
runs-on: ubuntu-latest
outputs:
semver: ${{ steps.semver_setup.outputs.semver }}
environment: ${{ steps.semver_setup.outputs.environment }}
semver: ${{ steps.get_semver.outputs.semver }}
environment: ${{ steps.get_env.outputs.environment }}
steps:
- name: Semver setup
id: semver_setup
uses: pagopa/github-actions-template/nodo5-semver-setup@ce252c8501c9242bd6045f7cdd650736b2f38777
with:
semver: ${{ inputs.semver }}
- name: pull request rejected
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged != true
run: |
echo "❌ PR was closed without a merge"
exit 1
# Set Semvar
- run: echo "SEMVER=patch" >> $GITHUB_ENV

- if: ${{ (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'breaking-change')) }}
run: echo "SEMVER=major" >> $GITHUB_ENV

# force semver if dev, !=main or skip release
- if: ${{ inputs.version == 'new_release' }}
run: echo "SEMVER=minor" >> $GITHUB_ENV

- if: ${{ inputs.version == 'breaking_change' }}
run: echo "SEMVER=major" >> $GITHUB_ENV

- if: ${{ github.ref_name != 'main' }}
run: echo "SEMVER=buildNumber" >> $GITHUB_ENV

- if: ${{ inputs.version == 'skip_or_promote' }}
run: echo "SEMVER=skip" >> $GITHUB_ENV

- id: get_semver
name: Set Output
run: echo "semver=${{env.SEMVER}}" >> $GITHUB_OUTPUT

# Set Environment
- run: echo "ENVIRNOMENT=${{ inputs.environment}}" >> $GITHUB_ENV

- if: ${{ inputs.environment == null }}
run: echo "ENVIRNOMENT=dev" >> $GITHUB_ENV

- id: get_env
name: Set Output
run: echo "environment=${{env.ENVIRNOMENT}}" >> $GITHUB_OUTPUT

release:
needs: [setup]
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ You can run your application in dev mode that enables live coding using:
```shell script
./mvnw compile quarkus:dev
```
Otherwise, with quarkus CLI:
```
brew install quarkusio/tap/quarkus
quarkus dev -DskipTests=true
```

> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only
> at http://localhost:8080/q/dev/.
Expand Down
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: pagopa-fdr-chart
description: Flussi di rendicontazioni
type: application
version: "1.30.0"
appVersion: "1.0.23"
version: "1.43.0"
appVersion: "1.0.21-15-PAGOPA-2282"
dependencies:
- name: microservice-chart
version: 3.0.0
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-fdr
tag: 1.0.23
tag: 1.0.21-15-PAGOPA-2282
pullPolicy: Always
readinessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-fdr
tag: 1.0.23
tag: 1.0.21-15-PAGOPA-2282
pullPolicy: Always
readinessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi_internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "FDR - Flussi di rendicontazione (local)",
"description": "Manage FDR ( aka \"Flussi di Rendicontazione\" ) exchanged between PSP and EC",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "1.0.23"
"version": "1.0.21-15-PAGOPA-2282"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi_organization.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "FDR - Flussi di rendicontazione (local)",
"description": "Manage FDR ( aka \"Flussi di Rendicontazione\" ) exchanged between PSP and EC",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "1.0.23"
"version": "1.0.21-15-PAGOPA-2282"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi_psp.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "FDR - Flussi di rendicontazione (local)",
"description": "Manage FDR ( aka \"Flussi di Rendicontazione\" ) exchanged between PSP and EC",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "1.0.23"
"version": "1.0.21-15-PAGOPA-2282"
},
"servers": [
{
Expand Down
44 changes: 44 additions & 0 deletions performance-test/python-test/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
import logging, time
import methods


NUMBER_OF_PAYMENTS = 300
MAX_PAYMENTS_PER_ADD_OPERATION = 100

def main(URL, subkey):
logging.basicConfig(level=logging.INFO)

flow_date = "2024-10-30"
tmstmp = timestamp = int(time.time())
flow_name = f"{flow_date}88888888888-{tmstmp}"

create_url = URL + f"/psps/88888888888/fdrs/{flow_name}"
methods.create_empty_flow(create_url, flow_name, flow_date, NUMBER_OF_PAYMENTS, subkey)


add_url = URL + f"/psps/88888888888/fdrs/{flow_name}/payments/add"
methods.add_payments(add_url, NUMBER_OF_PAYMENTS, MAX_PAYMENTS_PER_ADD_OPERATION, flow_date, subkey)


publish_url = URL + f"/psps/88888888888/fdrs/{flow_name}/publish"
methods.publish_payments(publish_url, subkey)

def get_url(env):
if env == 'dev':
return "https://api.dev.platform.pagopa.it/fdr-psp/service/v1"
elif env == 'uat':
return "https://upload.uat.platform.pagopa.it/fdr-psp/service/v1"
else:
raise ValueError(f"Invalid environment: {env}. Please use 'dev' or 'uat'.")

if __name__ == "__main__":
try:
env = sys.argv[1]
key = sys.argv[2]
url = get_url(env)
main(url, key)
except IndexError:
print("Usage: python3 main.py <environment> <sukey> \ni.e. python3 main.py dev your-key")
except ValueError as e:
print(e)
106 changes: 106 additions & 0 deletions performance-test/python-test/methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import random
import json, logging, requests, time


def create_empty_flow(url, flow_name, flow_date, total_payments, key):

headers = {
"Ocp-Apim-Subscription-Key": key
}
request = {
"fdr": flow_name,
"fdrDate": f"{flow_date}T12:00:00.000Z",
"sender": {
"type": "LEGAL_PERSON",
"id": "SELBIT2B",
"pspId": "88888888888",
"pspName": "Bank",
"pspBrokerId": "88888888888",
"channelId": "88888888888_01",
"password": "PLACEHOLDER"
},
"receiver": {
"id": "APPBIT2B",
"organizationId": "15376371009",
"organizationName": "PagoPA"
},
"regulation": "SEPA - Bonifico xzy",
"regulationDate": f"{flow_date}T12:00:00.000Z",
"bicCodePouringBank": "UNCRITMMXXX",
"totPayments": total_payments,
"sumPayments": total_payments * 10
}
logging.info(f"\nSend request to: [{url}]\nRequest: [{request}]")
start_time = time.time()
response = requests.post(url=url,
data=json.dumps(request),
headers=headers)
end_time = time.time()
logging.info(f"=====\nElapsed time: [{(end_time - start_time):.3f} sec] Status Code: [{response.status_code}]\nResponse: {response.json()}\n==================")



def add_payments(url, total_payments, max_per_add, date, key):

headers = {
"Ocp-Apim-Subscription-Key": key
}

total_amount = total_payments * 10
payments = generate_payments(total_payments, total_amount, date)
request = []

total_requests = int(total_payments / max_per_add)
for req_idx in range(total_requests):
extracted_payments = {
"payments": payments[(req_idx * max_per_add):(req_idx * max_per_add + max_per_add)]
}
request = json.dumps(extracted_payments)
logging.info(f"\nSend request to: [{url}]\nRequest: [TOO LONG]")
start_time = time.time()
response = requests.put(url=url,
data=request,
headers=headers)
end_time = time.time()
logging.info(f"=====\nElapsed time: [{(end_time - start_time):.3f} sec] Status Code: [{response.status_code}]\nResponse: {response.json()}\n==================")


def publish_payments(url, key):
headers = {
"Ocp-Apim-Subscription-Key": key
}
logging.info(f"\nSend request to: [{url}]")
start_time = time.time()
response = requests.post(url=url,
headers=headers)
end_time = time.time()
logging.info(f"=====\nElapsed time: [{(end_time - start_time):.3f} sec] Status Code: [{response.status_code}]\nResponse: {response.json()}\n==================")


#########
# UTILS #
#########
def generate_payments(number_of_payments, total_amount, date):

payments = []
iuvs = set()
for idx in range(number_of_payments):
iuv = get_random_numeric_string(15)
if iuv not in iuvs:
iuvs.add(iuv)
payments.append({
"index": idx + 1,
"iuv": iuv,
"iur": get_random_numeric_string(11),
"pay": total_amount / number_of_payments,
"idTransfer": 1,
"payStatus": "EXECUTED",
"payDate": f"{date}T12:00:00.000Z"
})
else:
idx -= 1
return payments

def get_random_numeric_string(size, dataset = "0123456789"):
random_string = ''.join(random.choices(dataset, k=size))
return random_string
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>it.gov.pagopa</groupId>
<artifactId>pagopa-fdr</artifactId>
<version>1.0.23</version>
<version>1.0.21-15-PAGOPA-2282</version>
<properties>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
<lombok.version>1.18.26</lombok.version>
Expand Down Expand Up @@ -131,6 +131,10 @@
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import io.quarkus.panache.common.Sort;
import it.gov.pagopa.fdr.repository.fdr.model.PaymentStatusEnumEntity;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bson.codecs.pojo.annotations.BsonProperty;
import org.bson.types.ObjectId;
import org.eclipse.microprofile.faulttolerance.Retry;

@Data
@EqualsAndHashCode(callSuper = true)
Expand Down Expand Up @@ -67,6 +69,8 @@ public static PanacheQuery<PanacheMongoEntityBase> findByFdrAndPspId(String fdr,
Parameters.with("fdr", fdr).and("pspId", pspId).map());
}

// https://quarkus.io/guides/smallrye-fault-tolerance
@Retry(delay = 500, delayUnit = ChronoUnit.MILLIS)
public static long deleteByFdrAndIndexes(String fdr, List<Long> indexList) {
return delete(
"ref_fdr = :fdr and index in :indexes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.quarkus.mongodb.panache.common.MongoEntity;
import io.quarkus.panache.common.Parameters;
import io.quarkus.panache.common.Sort;
import io.smallrye.mutiny.Uni;
import it.gov.pagopa.fdr.repository.fdr.model.PaymentStatusEnumEntity;
import java.time.Instant;
import java.util.List;
Expand Down Expand Up @@ -99,22 +100,7 @@ public static PanacheQuery<PanacheMongoEntityBase> findByPspAndIuvIur(
return find(query, sort, params);
}

// public static PanacheQuery<PanacheMongoEntityBase> findByFdrAndPspId(
// String fdr, String pspId, Sort sort) {
// return find(
// "ref_fdr = :fdr and ref_fdr_sender_psp_id = :pspId",
// sort,
// Parameters.with("fdr", fdr).and("pspId", pspId).map());
// }
//
// public static long deleteByFdrAndPspId(String fdr, String pspId) {
// return delete(
// "ref_fdr = :fdr and ref_fdr_sender_psp_id = :pspId",
// Parameters.with("fdr", fdr).and("pspId", pspId).map());
// }
//
public static void persistFdrPaymentPublishEntities(
List<FdrPaymentPublishEntity> fdrPaymentPublishEntities) {
public static void persistFdrPaymentPublishEntities(List<FdrPaymentPublishEntity> fdrPaymentPublishEntities) {
persist(fdrPaymentPublishEntities);
}
}
Loading

0 comments on commit 0cda337

Please sign in to comment.