From 29337c1bcfa93c60b1952e3e5f6fb988d498faa6 Mon Sep 17 00:00:00 2001 From: Lorenzo Catalano Date: Fri, 19 Jan 2024 14:57:14 +0100 Subject: [PATCH] wip --- .../standinmanager/service/ConfigService.java | 7 +- .../service/StationMonitorService.java | 15 +- .../resources/application-local.properties | 17 +-- src/main/resources/openapi_config.json | 130 ++++++++---------- 4 files changed, 79 insertions(+), 90 deletions(-) diff --git a/src/main/java/it/gov/pagopa/standinmanager/service/ConfigService.java b/src/main/java/it/gov/pagopa/standinmanager/service/ConfigService.java index e9e6635c..4209b113 100644 --- a/src/main/java/it/gov/pagopa/standinmanager/service/ConfigService.java +++ b/src/main/java/it/gov/pagopa/standinmanager/service/ConfigService.java @@ -1,7 +1,6 @@ package it.gov.pagopa.standinmanager.service; import it.gov.pagopa.standinmanager.config.model.ConfigDataV1; -import java.util.ArrayList; import lombok.extern.slf4j.Slf4j; import org.openapitools.client.api.CacheApi; import org.springframework.beans.factory.annotation.Autowired; @@ -24,6 +23,10 @@ public ConfigDataV1 getCache() { public void loadCache() { log.info("loadCache from cache api"); - configData = cacheApi.cache(false, new ArrayList<>()); + try { + configData = cacheApi.cache(); + }catch(Exception e){ + log.error("Can not get cache",e); + } } } diff --git a/src/main/java/it/gov/pagopa/standinmanager/service/StationMonitorService.java b/src/main/java/it/gov/pagopa/standinmanager/service/StationMonitorService.java index aed3d64c..c3a5b5a2 100644 --- a/src/main/java/it/gov/pagopa/standinmanager/service/StationMonitorService.java +++ b/src/main/java/it/gov/pagopa/standinmanager/service/StationMonitorService.java @@ -33,11 +33,16 @@ public void checkStations() { ZonedDateTime now = ZonedDateTime.now(); log.info("checkStations [{}]", now); ConfigDataV1 cache = configService.getCache(); - List stations = cosmosStationRepository.getStations(); - stations.stream().map(s-> Pair.of(s,cache.getStations().get(s.getStation()))) - .filter(s->s.getRight()!=null) - .map(s -> checkStation(now, s.getRight(), s.getLeft())) - .collect(Collectors.toList()); + if(cache!=null){ + List stations = cosmosStationRepository.getStations(); + stations.stream().map(s-> Pair.of(s,cache.getStations().get(s.getStation()))) + .filter(s->s.getRight()!=null) + .map(s -> checkStation(now, s.getRight(), s.getLeft())) + .collect(Collectors.toList()); + }else{ + log.warn("Can not run,cache is null"); + } + } @Async diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index afc87de9..d0339f9f 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,3 +1,4 @@ +server.port=8087 # Info info.properties.environment=local # Logging @@ -11,18 +12,18 @@ spring.datasource.username=cfg spring.datasource.password=password api-config-cache.base-path=https://api.dev.platform.pagopa.it/api-config-cache/o/v1 -api-config-cache.api-key= +api-config-cache.api-key=${API_CONFIG_CACHE_API_KEY} dataexplorer.url=http://localhost:8880 dataexplorer.clientId= dataexplorer.appKey= dataexplorer.dbName=NetDefaultDB -cosmos.endpoint=https://pagopa-d-weu-nodo-standin-cosmos-account.documents.azure.com:443/ -cosmos.key= +cosmos.endpoint=${COSMOS_STANDIN_URL} +cosmos.key=${COSMOS_STANDIN_KEY} forwarder.url=https://api.dev.platform.pagopa.it/pagopa-node-forwarder/api/v1/forward -forwarder.key= +forwarder.key=${FORWARDER_KEY} adder.slot.minutes=5 adder.slot.fault.threshold=1 @@ -34,14 +35,14 @@ remover.range.fault.limit=6 aws.region=weu aws.ses.user=noreply@pagopa.it -aws.mailto=ciao@gmail.com +aws.mailto=test@pagopa.it excludedStations="" -config.refresh.cron= ${CONFIG_REFRESH_CRON} +config.refresh.cron= */10 * * * * * nodo.monitor.cron= - nodo.calc.cron= - -station.monitor.cron= */10 * * * * * -station.calc.cron= */10 * * * * * +station.monitor.cron= - +station.calc.cron= - logging.level.it.gov.pagopa.standinmanager.service=DEBUG \ No newline at end of file diff --git a/src/main/resources/openapi_config.json b/src/main/resources/openapi_config.json index 1e7a5543..928dc807 100644 --- a/src/main/resources/openapi_config.json +++ b/src/main/resources/openapi_config.json @@ -4,7 +4,7 @@ "title" : "API-Config Cacher", "description" : "Generate cache for regarding Nodo dei Pagamenti configuration", "termsOfService" : "https://www.pagopa.gov.it/", - "version" : "0.8.1" + "version" : "0.8.6" }, "servers" : [ { "url" : "http://localhost:8080" @@ -22,47 +22,30 @@ } } ], "paths" : { - "/stakeholders/node/cache/schemas/v1" : { + "/stakeholders/standin/cache/schemas/v1" : { "get" : { "tags" : [ "Cache" ], "summary" : "Get selected key of cache v1 config", "operationId" : "cache", - "parameters" : [ { - "name" : "refresh", - "in" : "query", - "description" : "to force the refresh of the cache", - "required" : false, - "schema" : { - "type" : "boolean" - } - }, { - "name" : "keys", - "in" : "query", - "required" : false, - "schema" : { - "type" : "array", - "items" : { - "type" : "string", - "enum" : [ "creditorInstitutions", "creditorInstitutionBrokers", "stations", "creditorInstitutionStations", "encodings", "creditorInstitutionEncodings", "ibans", "creditorInstitutionInformations", "psps", "pspBrokers", "paymentTypes", "pspChannelPaymentTypes", "plugins", "pspInformationTemplates", "pspInformations", "channels", "cdsServices", "cdsSubjects", "cdsSubjectServices", "cdsCategories", "configurations", "ftpServers", "languages", "gdeConfigurations", "metadataDict" ] - } - } - } ], "responses" : { - "403" : { - "description" : "Forbidden" - }, - "200" : { - "description" : "OK", + "400" : { + "description" : "Bad Request", "content" : { "application/json" : { "schema" : { - "$ref" : "#/components/schemas/ConfigDataV1" + "$ref" : "#/components/schemas/ProblemJson" } } } }, - "400" : { - "description" : "Bad Request", + "401" : { + "description" : "Unauthorized" + }, + "403" : { + "description" : "Forbidden" + }, + "500" : { + "description" : "Service unavailable", "content" : { "application/json" : { "schema" : { @@ -74,15 +57,12 @@ "429" : { "description" : "Too many requests" }, - "401" : { - "description" : "Unauthorized" - }, - "500" : { - "description" : "Service unavailable", + "200" : { + "description" : "OK", "content" : { "application/json" : { "schema" : { - "$ref" : "#/components/schemas/ProblemJson" + "$ref" : "#/components/schemas/ConfigDataV1" } } } @@ -93,18 +73,12 @@ } ] } }, - "/stakeholders/node/cache/schemas/v1/id" : { + "/stakeholders/standin/cache/schemas/v1/id" : { "get" : { "tags" : [ "Cache" ], "summary" : "Get last v1 cache version", "operationId" : "idV1", "responses" : { - "404" : { - "description" : "Not Found" - }, - "403" : { - "description" : "Forbidden" - }, "400" : { "description" : "Bad Request", "content" : { @@ -115,28 +89,34 @@ } } }, - "429" : { - "description" : "Too many requests" + "401" : { + "description" : "Unauthorized" }, - "200" : { - "description" : "OK", + "403" : { + "description" : "Forbidden" + }, + "404" : { + "description" : "Not Found" + }, + "500" : { + "description" : "Service unavailable", "content" : { "application/json" : { "schema" : { - "$ref" : "#/components/schemas/CacheVersion" + "$ref" : "#/components/schemas/ProblemJson" } } } }, - "401" : { - "description" : "Unauthorized" + "429" : { + "description" : "Too many requests" }, - "500" : { - "description" : "Service unavailable", + "200" : { + "description" : "OK", "content" : { "application/json" : { "schema" : { - "$ref" : "#/components/schemas/ProblemJson" + "$ref" : "#/components/schemas/CacheVersion" } } } @@ -150,6 +130,28 @@ }, "components" : { "schemas" : { + "ProblemJson" : { + "type" : "object", + "properties" : { + "title" : { + "type" : "string", + "description" : "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable" + }, + "status" : { + "maximum" : 600, + "minimum" : 100, + "type" : "integer", + "description" : "The HTTP status code generated by the origin server for this occurrence of the problem.", + "format" : "int32", + "example" : 200 + }, + "detail" : { + "type" : "string", + "description" : "A human readable explanation specific to this occurrence of the problem.", + "example" : "There was an error processing the request" + } + } + }, "BrokerCreditorInstitution" : { "required" : [ "broker_code", "enabled", "extended_fault_bean" ], "type" : "object", @@ -995,28 +997,6 @@ } } }, - "ProblemJson" : { - "type" : "object", - "properties" : { - "title" : { - "type" : "string", - "description" : "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable" - }, - "status" : { - "maximum" : 600, - "minimum" : 100, - "type" : "integer", - "description" : "The HTTP status code generated by the origin server for this occurrence of the problem.", - "format" : "int32", - "example" : 200 - }, - "detail" : { - "type" : "string", - "description" : "A human readable explanation specific to this occurrence of the problem.", - "example" : "There was an error processing the request" - } - } - }, "CacheVersion" : { "required" : [ "version" ], "type" : "object",