Skip to content
Snippets Groups Projects
Commit da06c410 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

rename datasources

parent fc585fb8
No related branches found
No related tags found
No related merge requests found
...@@ -9,20 +9,20 @@ You need to configure a few things using some environment variables. ...@@ -9,20 +9,20 @@ You need to configure a few things using some environment variables.
Environment variables: Environment variables:
* DB_URL: JDBC URL to connect to the portal database, for example "jdbc:postgresql://db:5432/portal" * PORTAL_DB_URL: JDBC URL to connect to the portal database, for example "jdbc:postgresql://db:5432/portal"
* DB_SERVER: optional, address of the portal database server, for example DB_SERVER="db:5432". Used to wait for the database to be up and running. * PORTAL_DB_SERVER: optional, address of the portal database server, for example DB_SERVER="db:5432". Used to wait for the database to be up and running.
* DB_USER: User to use when connecting to the portal database * PORTAL_DB_USER: User to use when connecting to the portal database
* DB_PASSWORD: Password to use when connecting to the portal database * PORTAL_DB_PASSWORD: Password to use when connecting to the portal database
* META_DB_URL: JDBC URL to connect to the metadata database * META_DB_URL: JDBC URL to connect to the metadata database
* META_DB_SERVER: optional, address of the metadata database server. Used to wait for the database to be up and running. * META_DB_SERVER: optional, address of the metadata database server. Used to wait for the database to be up and running.
* META_DB_USER: User to use when connecting to the metadata database * META_DB_USER: User to use when connecting to the metadata database
* META_DB_PASSWORD: Password to use when connecting to the metadata database * META_DB_PASSWORD: Password to use when connecting to the metadata database
* ADNI_DB_URL: JDBC URL to connect to the adni database * SCIENCE_DB_URL: JDBC URL to connect to the science database
* ADNI_DB_SERVER: optional, address of the adni database server. Used to wait for the database to be up and running. * SCIENCE_DB_SERVER: optional, address of the science database server. Used to wait for the database to be up and running.
* ADNI_DB_USER: User to use when connecting to the adni database * SCIENCE_DB_USER: User to use when connecting to the science database
* ADNI_DB_PASSWORD: Password to use when connecting to the adni database * SCIENCE_DB_PASSWORD: Password to use when connecting to the science database
* CONTEXT_PATH: context path appended to all services running in this container. Default to "/services" * CONTEXT_PATH: context path appended to all services running in this container. Default to "/services"
......
...@@ -2,20 +2,20 @@ ...@@ -2,20 +2,20 @@
# See http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html # See http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
spring: spring:
datasource: portalDatasource:
url: {{ default .Env.DB_URL "jdbc:postgresql://172.22.0.1:5432/portal" }} url: {{ default .Env.PORTAL_DB_URL "jdbc:postgresql://172.22.0.1:5432/portal" }}
username: {{ default .Env.DB_USER "portal" }} username: {{ default .Env.PORTAL_DB_USER "portal" }}
password: {{ .Env.DB_PASSWORD }} password: {{ .Env.PORTAL_DB_PASSWORD }}
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
metaDatasource: metaDatasource:
url: {{ default .Env.META_DB_URL "jdbc:postgresql://172.22.0.1:5432/portal" }} url: {{ default .Env.META_DB_URL "jdbc:postgresql://172.22.0.1:5432/portal" }}
username: {{ default .Env.META_DB_USER "portal" }} username: {{ default .Env.META_DB_USER "portal" }}
password: {{ .Env.META_DB_PASSWORD }} password: {{ .Env.META_DB_PASSWORD }}
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
adniDatasource: scienceDatasource:
url: {{ default .Env.ADNI_DB_URL "jdbc:postgresql://172.22.0.1:5433/adni" }} url: {{ default .Env.SCIENCE_DB_URL "jdbc:postgresql://172.22.0.1:5433/science" }}
username: {{ default .Env.ADNI_DB_USER "adni" }} username: {{ default .Env.SCIENCE_DB_USER "science" }}
password: {{ .Env.ADNI_DB_PASSWORD }} password: {{ .Env.SCIENCE_DB_PASSWORD }}
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
jpa: jpa:
hibernate: hibernate:
......
...@@ -7,7 +7,7 @@ fi ...@@ -7,7 +7,7 @@ fi
if [ ! -z "$META_DB_SERVER" ]; then if [ ! -z "$META_DB_SERVER" ]; then
OPTS="$OPTS -wait tcp://$META_DB_SERVER -timeout 60s" OPTS="$OPTS -wait tcp://$META_DB_SERVER -timeout 60s"
fi fi
if [ ! -z "$ADNI_DB_SERVER" ]; then if [ ! -z "$SCIENCE_DB_SERVER" ]; then
OPTS="$OPTS -wait tcp://$ADNI_DB_SERVER -timeout 60s" OPTS="$OPTS -wait tcp://$SCIENCE_DB_SERVER -timeout 60s"
fi fi
dockerize $OPTS java -jar backend.jar dockerize $OPTS java -jar backend.jar
...@@ -23,14 +23,14 @@ import javax.sql.DataSource; ...@@ -23,14 +23,14 @@ import javax.sql.DataSource;
*/ */
@Configuration @Configuration
@EnableJpaRepositories(value = "eu.hbp.mip.repositories", entityManagerFactoryRef = "entityManagerFactory") @EnableJpaRepositories(value = "eu.hbp.mip.repositories")
@EntityScan(basePackages = "eu.hbp.mip.model") @EntityScan(basePackages = "eu.hbp.mip.model")
public class PersistenceConfiguration { public class PersistenceConfiguration {
@Primary @Primary
@Bean(name = "datasource") @Bean(name = "portalDatasource")
@ConfigurationProperties(prefix="spring.datasource") @ConfigurationProperties(prefix="spring.portalDatasource")
public DataSource dataSource() { public DataSource portalDataSource() {
return DataSourceBuilder.create().build(); return DataSourceBuilder.create().build();
} }
...@@ -40,9 +40,9 @@ public class PersistenceConfiguration { ...@@ -40,9 +40,9 @@ public class PersistenceConfiguration {
return DataSourceBuilder.create().build(); return DataSourceBuilder.create().build();
} }
@Bean(name = "adniDatasource") @Bean(name = "scienceDatasource")
@ConfigurationProperties(prefix="spring.adniDatasource") @ConfigurationProperties(prefix="spring.scienceDatasource")
public DataSource adniDataSource() { public DataSource scienceDataSource() {
return DataSourceBuilder.create().build(); return DataSourceBuilder.create().build();
} }
...@@ -55,16 +55,16 @@ public class PersistenceConfiguration { ...@@ -55,16 +55,16 @@ public class PersistenceConfiguration {
@Bean @Bean
@Autowired @Autowired
@Qualifier("adniJdbcTemplate") @Qualifier("scienceJdbcTemplate")
public JdbcTemplate adniJdbcTemplate() { public JdbcTemplate scienceJdbcTemplate() {
return new JdbcTemplate(adniDataSource()); return new JdbcTemplate(scienceDataSource());
} }
@Bean(name = "entityManagerFactory") @Bean(name = "entityManagerFactory")
@DependsOn("flyway") @DependsOn("flyway")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource()); em.setDataSource(portalDataSource());
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter); em.setJpaVendorAdapter(vendorAdapter);
return em; return em;
...@@ -74,7 +74,7 @@ public class PersistenceConfiguration { ...@@ -74,7 +74,7 @@ public class PersistenceConfiguration {
public Flyway migrations() { public Flyway migrations() {
Flyway flyway = new Flyway(); Flyway flyway = new Flyway();
flyway.setBaselineOnMigrate(true); flyway.setBaselineOnMigrate(true);
flyway.setDataSource(dataSource()); flyway.setDataSource(portalDataSource());
return flyway; return flyway;
} }
......
...@@ -35,8 +35,8 @@ public class RequestsApi { ...@@ -35,8 +35,8 @@ public class RequestsApi {
private static final Logger LOGGER = Logger.getLogger(RequestsApi.class); private static final Logger LOGGER = Logger.getLogger(RequestsApi.class);
@Autowired @Autowired
@Qualifier("adniJdbcTemplate") @Qualifier("scienceJdbcTemplate")
private JdbcTemplate adniJdbcTemplate; private JdbcTemplate scienceJdbcTemplate;
@ApiOperation(value = "Post a request", response = Dataset.class) @ApiOperation(value = "Post a request", response = Dataset.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") })
...@@ -87,7 +87,7 @@ public class RequestsApi { ...@@ -87,7 +87,7 @@ public class RequestsApi {
{ {
List<Object> currentVarData = new LinkedList<>(); List<Object> currentVarData = new LinkedList<>();
String sqlQuery = "SELECT " + varCode + " FROM adni_merge"; String sqlQuery = "SELECT " + varCode + " FROM adni_merge";
for (Map resultMap : adniJdbcTemplate.queryForList(sqlQuery)) for (Map resultMap : scienceJdbcTemplate.queryForList(sqlQuery))
{ {
String strValue = String.valueOf(resultMap.get(varCode)); String strValue = String.valueOf(resultMap.get(varCode));
try { try {
......
...@@ -36,8 +36,8 @@ public class StatsApi { ...@@ -36,8 +36,8 @@ public class StatsApi {
ArticleRepository articleRepository; ArticleRepository articleRepository;
@Autowired @Autowired
@Qualifier("adniJdbcTemplate") @Qualifier("scienceJdbcTemplate")
private JdbcTemplate adniJdbcTemplate; private JdbcTemplate scienceJdbcTemplate;
@ApiOperation(value = "Get general statistics", response = GeneralStats.class) @ApiOperation(value = "Get general statistics", response = GeneralStats.class)
@ApiResponses(value = {@ApiResponse(code = 200, message = "Found"), @ApiResponse(code = 404, message = "Not found") }) @ApiResponses(value = {@ApiResponse(code = 200, message = "Found"), @ApiResponse(code = 404, message = "Not found") })
...@@ -56,9 +56,9 @@ public class StatsApi { ...@@ -56,9 +56,9 @@ public class StatsApi {
private Long countVariables() private Long countVariables()
{ {
Long count = adniJdbcTemplate.queryForObject( Long count = scienceJdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " + "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " +
"WHERE table_schema = 'public' AND table_name = 'adni_merge'", Long.class); // TODO: compute from adni_merge DB "WHERE table_schema = 'public' AND table_name = 'adni_merge'", Long.class);
return count; return count;
} }
......
...@@ -26,7 +26,7 @@ GATEWAY_IP=$(docker inspect portal-db-test | grep \"Gateway\":\ \" | sed 's/.*Ga ...@@ -26,7 +26,7 @@ GATEWAY_IP=$(docker inspect portal-db-test | grep \"Gateway\":\ \" | sed 's/.*Ga
docker run --name portal-backend-test -p 8080:8080 \ docker run --name portal-backend-test -p 8080:8080 \
-e "AUTHENTICATION=0" \ -e "AUTHENTICATION=0" \
-e "DB_URL=jdbc:postgresql://$GATEWAY_IP:5433/postgres" \ -e "PORTAL_DB_URL=jdbc:postgresql://$GATEWAY_IP:5433/postgres" \
-e "META_DB_URL=jdbc:postgresql://$GATEWAY_IP:5432/postgres" \ -e "META_DB_URL=jdbc:postgresql://$GATEWAY_IP:5432/postgres" \
-d hbpmip/portal-backend -d hbpmip/portal-backend
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment