Skip to content

Commit

Permalink
NOD-690: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fparisitas committed Feb 8, 2024
1 parent 3547363 commit 377f02d
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 86 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ hs_err_pid*
# Helm
/helm/charts/*
**/.terraform/

# Others
**/.DS_Store
17 changes: 17 additions & 0 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ microservice-chart:
APP_LOGGING_LEVEL: 'DEBUG'
DEFAULT_LOGGING_LEVEL: 'INFO'
CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}'
CACHET_TX_NAME: "nodo-dei-pagamenti-cache"

NODO_ORACLE_NEXI_DB_CONFIG_URL: "jdbc:postgresql://ndp.d.db-nodo-pagamenti.com:6432/nodo?sslmode=require&prepareThreshold=0&currentSchema=cfg"
NODO_ORACLE_NEXI_DB_CONFIG_USER: "cfg"
NODO_ORACLE_NEXI_DB_CONFIG_DRIVER: "org.postgresql.Driver"

NODO_POSTGRE_NEXI_DB_CONFIG_URL: "jdbc:postgresql://ndp.d.db-nodo-pagamenti.com:6432/nodo?sslmode=require&prepareThreshold=0&currentSchema=cfg"
NODO_POSTGRE_NEXI_DB_CONFIG_USER: "cfg"
NODO_POSTGRE_NEXI_DB_CONFIG_DRIVER: "org.postgresql.Driver"

NODO_POSTGRE_PAGOPA_DB_CONFIG_URL: "jdbc:postgresql://ndp.d.db-nodo-pagamenti.com:6432/nodo?sslmode=require&prepareThreshold=0&currentSchema=cfg"
NODO_POSTGRE_PAGOPA_DB_CONFIG_USER: "cfg"
NODO_POSTGRE_PAGOPA_DB_CONFIG_DRIVER: "org.postgresql.Driver"

OTEL_SERVICE_NAME: "pagopa-node-cfg-sync"
OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=dev"
Expand All @@ -78,6 +91,10 @@ microservice-chart:
envSecret:
# required
APPLICATIONINSIGHTS_CONNECTION_STRING: 'ai-d-connection-string'
CACHE_TX_CONNECTION_STRING: "nodo-dei-pagamenti-cache-tx-connection-string-key"
NODO_ORACLE_NEXI_DB_CONFIG_PASSWORD: "oracle-db-cfg-password"
NODO_POSTGRE_NEXI_DB_CONFIG_PASSWORD: "postgresql-db-cfg-password"
NODO_POSTGRE_PAGOPA_DB_CONFIG_PASSWORD: "db-cfg-password"
OTEL_EXPORTER_OTLP_HEADERS: elastic-apm-secret-token
keyvault:
name: "pagopa-d-nodo-kv"
Expand Down
3 changes: 2 additions & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ microservice-chart:
APP_LOGGING_LEVEL: 'DEBUG'
DEFAULT_LOGGING_LEVEL: 'INFO'
CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}'

CACHET_TX_NAME: "nodo-dei-pagamenti-cache"
OTEL_SERVICE_NAME: "pagopa-node-cfg-sync"
OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=prod"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317"
Expand All @@ -78,6 +78,7 @@ microservice-chart:
envSecret:
# required
APPLICATIONINSIGHTS_CONNECTION_STRING: 'ai-p-connection-string'
CACHE_TX_CONNECTION_STRING: "nodo-dei-pagamenti-cache-tx-connection-string-key"
OTEL_EXPORTER_OTLP_HEADERS: elastic-apm-secret-token
keyvault:
name: "pagopa-d-nodo-kv"
Expand Down
2 changes: 2 additions & 0 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ microservice-chart:
APP_LOGGING_LEVEL: 'DEBUG'
DEFAULT_LOGGING_LEVEL: 'INFO'
CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}'
CACHET_TX_NAME: "nodo-dei-pagamenti-cache"

OTEL_SERVICE_NAME: "pagopa-node-cfg-sync"
OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=uat"
Expand All @@ -78,6 +79,7 @@ microservice-chart:
envSecret:
# required
APPLICATIONINSIGHTS_CONNECTION_STRING: 'ai-u-connection-string'
CACHE_TX_CONNECTION_STRING: "nodo-dei-pagamenti-cache-tx-connection-string-key"
OTEL_EXPORTER_OTLP_HEADERS: elastic-apm-secret-token
keyvault:
name: "pagopa-d-nodo-kv"
Expand Down
52 changes: 51 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<feign-version>12.1</feign-version>
<postgresql.version>42.5.4</postgresql.version>
<oracle.version>21.4.0.0</oracle.version>
</properties>

<!-- <dependencyManagement>-->
<!-- <dependencies>-->
<!-- <dependency>-->
<!-- <groupId>com.azure.spring</groupId>-->
<!-- <artifactId>spring-cloud-azure-dependencies</artifactId>-->
<!-- <version>4.5.0</version>-->
<!-- <type>pom</type>-->
<!-- <scope>import</scope>-->
<!-- </dependency>-->
<!-- </dependencies>-->
<!-- </dependencyManagement>-->

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -58,12 +73,22 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>${oracle.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
Expand All @@ -73,6 +98,31 @@
<artifactId>caffeine</artifactId>
</dependency>

<!-- &lt;!&ndash; Azure &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.azure.spring</groupId>-->
<!-- <artifactId>spring-cloud-azure-stream-binder-eventhubs</artifactId>-->
<!-- </dependency>-->

<!-- Feign Client -->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>${feign-version}</version>
</dependency>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>${feign-version}</version>
</dependency>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-mock</artifactId>
<version>${feign-version}</version>
</dependency>

<!-- Swagger/OpenAPI -->
<dependency>
<groupId>org.springdoc</groupId>
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/it/gov/pagopa/node/cfg_sync/Application.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
package it.gov.pagopa.node.cfg_sync;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;

@SpringBootApplication
public class Application {
@EnableAutoConfiguration(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class})
@Slf4j
public class Application implements CommandLineRunner {

// private final EventProcessorClient eventProcessorClient;
//
// public Application(EventProcessorClient eventProcessorClient) {
// this.eventProcessorClient = eventProcessorClient;
// }

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Override
public void run(String... args) throws Exception {
// eventProcessorClient.start();
// // Wait for the processor client to be ready
// TimeUnit.SECONDS.sleep(10);
//
// log.info("Stopping and closing the processor");
// eventProcessorClient.stop();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
@Getter
public enum AppError {
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error",
"Something was wrong");
"Something was wrong"),
SERVICE_DISABLED(
HttpStatus.BAD_REQUEST,
"Target service disabled",
"Target service %s disabled");

public final HttpStatus httpStatus;
public final String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@PropertySource(value = "classpath:/application-${spring.profiles.active}.properties", ignoreResourceNotFound = true)
})
@EnableJpaRepositories(
basePackages = "it.gov.pagopa.node.cfg_sync.repository.CacheNodoONexiRepository",
basePackages = "it.gov.pagopa.node.cfg_sync.repository.nexi",
entityManagerFactoryRef = "nodoNexiOEntityManager",
transactionManagerRef = "nodoNexiOTransactionManager"
)
Expand All @@ -32,7 +32,7 @@ public LocalContainerEntityManagerFactoryBean nodoNexiOEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(nodoNexiODataSource());
em.setPackagesToScan("it.gov.pagopa.node.cfg_sync.repository.model.CacheNexiO");
em.setPackagesToScan("it.gov.pagopa.node.cfg_sync.repository.model.nexi");

HibernateJpaVendorAdapter vendorAdapter
= new HibernateJpaVendorAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@PropertySource(value = "classpath:/application-${spring.profiles.active}.properties", ignoreResourceNotFound = true)
})
@EnableJpaRepositories(
basePackages = "it.gov.pagopa.node.cfg_sync.repository.CacheNodoPagoPAPRepository",
basePackages = "it.gov.pagopa.node.cfg_sync.repository.pagopa",
entityManagerFactoryRef = "nodoPagoPAPEntityManager",
transactionManagerRef = "nodoPagoPAPTransactionManager"
)
Expand All @@ -34,7 +34,7 @@ public LocalContainerEntityManagerFactoryBean nodoPagoPAPEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(nodoPagoPAPDataSource());
em.setPackagesToScan("it.gov.pagopa.node.cfg_sync.repository.model.CachePagoPAP");
em.setPackagesToScan("it.gov.pagopa.node.cfg_sync.repository.model.pagopa");

HibernateJpaVendorAdapter vendorAdapter
= new HibernateJpaVendorAdapter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
package it.gov.pagopa.node.cfg_sync.repository.model;public class Cache {
package it.gov.pagopa.node.cfg_sync.repository.model;

import antlr.ANTLRParser;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.time.LocalDateTime;


@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
public class Cache implements Serializable {

@Id
@Column(name="ID", columnDefinition = "VARCHAR", length = 20)
private String id;

private LocalDateTime time;

private byte[] cache;

@Column(name="VERSION", columnDefinition = "VARCHAR", length = 32)
private String version;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package it.gov.pagopa.node.cfg_sync.repository.nexi.model;
package it.gov.pagopa.node.cfg_sync.repository.model.nexi;

import it.gov.pagopa.node.cfg_sync.repository.model.Cache;
import lombok.*;
import lombok.experimental.SuperBuilder;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -11,22 +13,8 @@

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "cache")
public class CacheNexiOracle implements Serializable {

@Id
@Column(name="ID", columnDefinition = "VARCHAR", length = 20)
private String id;

private LocalDateTime time;

private byte[] cache;

@Column(name="VERSION", columnDefinition = "VARCHAR", length = 32)
private String version;
public class CacheNexiOracle extends Cache {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package it.gov.pagopa.node.cfg_sync.repository.pagopa.model;
package it.gov.pagopa.node.cfg_sync.repository.model.pagopa;

import it.gov.pagopa.node.cfg_sync.repository.model.Cache;
import lombok.*;
import lombok.experimental.SuperBuilder;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -11,22 +13,8 @@

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "cache")
public class CachePagoPA implements Serializable {

@Id
@Column(name="ID", columnDefinition = "VARCHAR", length = 20)
private String id;

private LocalDateTime time;

private byte[] cache;

@Column(name="VERSION", columnDefinition = "VARCHAR", length = 32)
private String version;
public class CachePagoPA extends Cache {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.gov.pagopa.node.cfg_sync.repository;
package it.gov.pagopa.node.cfg_sync.repository.nexi;

import it.gov.pagopa.node.cfg_sync.repository.model.CacheNexiOracle;
import it.gov.pagopa.node.cfg_sync.repository.model.nexi.CacheNexiOracle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.gov.pagopa.node.cfg_sync.repository;
package it.gov.pagopa.node.cfg_sync.repository.pagopa;

import it.gov.pagopa.node.cfg_sync.repository.model.CachePagoPA;
import it.gov.pagopa.node.cfg_sync.repository.model.pagopa.CachePagoPA;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import it.gov.pagopa.node.cfg_sync.exception.AppError;
import it.gov.pagopa.node.cfg_sync.exception.AppException;
import it.gov.pagopa.node.cfg_sync.model.TargetRefreshEnum;
import it.gov.pagopa.node.cfg_sync.repository.CacheNodoPagoPAPRepository;
import it.gov.pagopa.node.cfg_sync.repository.model.Cache;
import it.gov.pagopa.node.cfg_sync.repository.model.CachePagoPAP;
import it.gov.pagopa.node.cfg_sync.repository.model.pagopa.CachePagoPA;
import it.gov.pagopa.node.cfg_sync.repository.pagopa.CacheNodoPagoPAPRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -72,13 +72,14 @@ public void syncCache() {
String cacheTimestamp = (String) getHeaderParameter(getType(), headers, HEADER_CACHE_TIMESTAMP);
String cacheVersion = (String) getHeaderParameter(getType(), headers, HEADER_CACHE_VERSION);

CachePagoPAP cache = (CachePagoPAP) composeCache(cacheId, ZonedDateTime.parse(cacheTimestamp).toLocalDateTime(), cacheVersion, response.body().asInputStream().readAllBytes());
CachePagoPA cache = (CachePagoPA) composeCache(cacheId, ZonedDateTime.parse(cacheTimestamp).toLocalDateTime(), cacheVersion, response.body().asInputStream().readAllBytes());
cacheNodoPagoPAPRepository.save(cache);

} catch (FeignException.GatewayTimeout e) {
log.error("SyncService api-config-cache get cache error: Gateway timeout", e);
throw new AppException(AppError.INTERNAL_SERVER_ERROR);
} catch (IOException e) {
}
catch (IOException e) {
log.error("SyncService api-config-cache get cache error", e);
throw new AppException(AppError.INTERNAL_SERVER_ERROR);
}
Expand Down
Loading

0 comments on commit 377f02d

Please sign in to comment.