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 ee7d9fa commit 1f187ce
Show file tree
Hide file tree
Showing 29 changed files with 408 additions and 260 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ hs_err_pid*

# Others
**/.DS_Store
/docker/local-dbs/postgres-data/
15 changes: 15 additions & 0 deletions docker/local-dbs/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.9'
services:
postgres:
image: postgres:14
container_name: postgres_nexi
ports:
- 5432:5432
volumes:
- ./postgres-data:/var/lib/postgresql/data
- ./postgres/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
environment:
- POSTGRES_DB=nodo
- POSTGRES_USER=cfg
- POSTGRES_PASSWORD=password
- POSTGRES_ROOT_PASSWORD=root
6 changes: 6 additions & 0 deletions docker/local-dbs/postgres/create_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE "cache" (
id varchar(20) NOT NULL,
"time" timestamp NOT NULL,
"cache" bytea NOT NULL,
"version" varchar(32) NULL
);
4 changes: 4 additions & 0 deletions docker/local-dbs/run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

rm -rf postgres-data
docker-compose up -d --remove-orphans --force-recreate
79 changes: 27 additions & 52 deletions src/main/java/it/gov/pagopa/node/cfgsync/Application.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
//package it.gov.pagopa.node.cfg_sync;
//
//import com.azure.messaging.eventhubs.EventData;
//import com.azure.messaging.eventhubs.EventHubProducerClient;
//import com.azure.messaging.eventhubs.EventProcessorClient;
//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;
//
//import java.util.Collections;
//import java.util.concurrent.TimeUnit;
//
//@SpringBootApplication
//@EnableAutoConfiguration(exclude = {
// DataSourceAutoConfiguration.class,
// DataSourceTransactionManagerAutoConfiguration.class,
// HibernateJpaAutoConfiguration.class})
//@Slf4j
//public class Application implements CommandLineRunner {
//
//// private final EventHubProducerClient eventHubProducerClient;
// private final EventProcessorClient eventProcessorClient;
//
// public Application(//EventHubProducerClient eventHubProducerClient,
// EventProcessorClient eventProcessorClient) {
//// this.eventHubProducerClient = eventHubProducerClient;
// 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);
//
//// eventHubProducerClient.send(Collections.singletonList(new EventData("Hello World")));
//// log.info("Successfully sent a message to Event Hubs.");
//// eventHubProducerClient.close();
// log.info("Stopping and closing the processor");
// eventProcessorClient.stop();
// }
//
//}
package it.gov.pagopa.node.cfgsync;

import com.azure.messaging.eventhubs.EventProcessorClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@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();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
@Service
public interface StandInManagerClient {

@RequestLine("GET /cache/refresh")
@RequestLine("GET /stations")
@Headers({
"Content-Type: application/json",
"Ocp-Apim-Subscription-Key: {subscriptionKey}"
})
Response refresh(@Param String subscriptionKey);
Response getCache(@Param String subscriptionKey);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package it.gov.pagopa.node.cfgsync.client.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class StandInManagerResponse {

private List<String> stations;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class SyncCacheController {
public ResponseEntity<RefreshResponse> cache(@PathVariable TargetRefreshEnum target) {

log.debug("Sync {} configuration", target.label);
CacheServiceFactory.getService(target).syncCache();
CacheServiceFactory.getService(target).sync();

String requestId = UUID.randomUUID().toString();
ZonedDateTime timestamp = ZonedDateTime.now();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
@PropertySource(value = "classpath:/application-${spring.profiles.active}.properties", ignoreResourceNotFound = true)
})
@EnableJpaRepositories(
basePackages = "it.gov.pagopa.node.cfgsync.repository.nexi",
basePackages = "it.gov.pagopa.node.cfgsync.repository.nexioracle",
entityManagerFactoryRef = "nodoNexiOEntityManager",
transactionManagerRef = "nodoNexiOTransactionManager"
)
public class NodoONexiConfiguration {
public class NodoNexiOConfiguration {
@Autowired
private Environment env;

Expand All @@ -32,7 +32,7 @@ public LocalContainerEntityManagerFactoryBean nodoNexiOEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(nodoNexiODataSource());
em.setPackagesToScan("it.gov.pagopa.node.cfgsync.repository.model.nexi");
em.setPackagesToScan("it.gov.pagopa.node.cfgsync.repository.model");

HibernateJpaVendorAdapter vendorAdapter
= new HibernateJpaVendorAdapter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package it.gov.pagopa.node.cfgsync.repository.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.util.HashMap;

@Configuration
@PropertySources({
@PropertySource("classpath:/application.properties"),
@PropertySource(value = "classpath:/application-${spring.profiles.active}.properties", ignoreResourceNotFound = true)
})
@EnableJpaRepositories(
basePackages = "it.gov.pagopa.node.cfgsync.repository.nexipostgre",
entityManagerFactoryRef = "nodoNexiPEntityManager",
transactionManagerRef = "nodoNexiPTransactionManager"
)
public class NodoNexiPConfiguration {

@Autowired
private Environment env;

@Bean
public LocalContainerEntityManagerFactoryBean nodoNexiPEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(nodoNexiPDataSource());
em.setPackagesToScan("it.gov.pagopa.node.cfgsync.repository.model");

HibernateJpaVendorAdapter vendorAdapter
= new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto",
env.getProperty("hibernate.hbm2ddl.auto"));
properties.put("hibernate.dialect",
env.getProperty("hibernate.dialect"));
em.setJpaPropertyMap(properties);

return em;
}

@Bean
public DataSource nodoNexiPDataSource() {
DriverManagerDataSource dataSource
= new DriverManagerDataSource();
dataSource.setDriverClassName(
env.getProperty("db.nodo.nexi.postgre.datasource.driverClassName"));
dataSource.setUrl(env.getProperty("db.nodo.nexi.postgre.datasource.url"));
dataSource.setUsername(env.getProperty("db.nodo.nexi.postgre.datasource.username"));
dataSource.setPassword(env.getProperty("db.nodo.nexi.postgre.datasource.password"));

return dataSource;
}

@Bean
public PlatformTransactionManager nodoNexiPTransactionManager() {
JpaTransactionManager transactionManager
= new JpaTransactionManager();
transactionManager.setEntityManagerFactory(
nodoNexiPEntityManager().getObject());

return transactionManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public LocalContainerEntityManagerFactoryBean nodoPagoPAPEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(nodoPagoPAPDataSource());
em.setPackagesToScan("it.gov.pagopa.node.cfgsync.repository.model.pagopa");
em.setPackagesToScan("it.gov.pagopa.node.cfgsync.repository.model");

HibernateJpaVendorAdapter vendorAdapter
= new HibernateJpaVendorAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

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


@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
public class Cache implements Serializable {
@Entity
@Table(name = "cache")
public class ConfigCache implements Serializable {

@Id
@Column(name="ID", columnDefinition = "VARCHAR", length = 20)
Expand Down
Loading

0 comments on commit 1f187ce

Please sign in to comment.