From 1a592b9e45f95d694fbf649f41304f148e3c40fe Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 17 Jun 2019 10:51:08 -0400 Subject: Changes related to eviction of connections These are changes related to ASDC controller for evicting database connection pool when ip address changes Included other appllications such as requestDB, CatalogDB, API Handler, BPMN, OpenstackAdapter etc Change-Id: I9a96ea12fb0c10643a204a58d55360bebba326fe Issue-ID: SO-2018 Signed-off-by: Benjamin, Max (mb388a) --- .../so/apihandlerinfra/ApiHandlerApplication.java | 7 +++++-- .../configuration/CatalogDBConfig.java | 21 ++++++++++++++++++--- .../configuration/RequestDBConfig.java | 22 ++++++++++++++++++---- 3 files changed, 41 insertions(+), 9 deletions(-) (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ApiHandlerApplication.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ApiHandlerApplication.java index bc1972a593..5beb4810ec 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ApiHandlerApplication.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ApiHandlerApplication.java @@ -21,17 +21,18 @@ package org.onap.so.apihandlerinfra; import java.util.concurrent.Executor; -import org.springframework.beans.factory.annotation.Autowired; +import org.onap.so.logging.jaxrs.filter.MDCTaskDecorator; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.onap.so.logging.jaxrs.filter.MDCTaskDecorator; @SpringBootApplication(scanBasePackages = {"org.onap"}) @EnableAsync +@EnableScheduling public class ApiHandlerApplication { @Value("${mso.async.core-pool-size}") @@ -53,6 +54,7 @@ public class ApiHandlerApplication { public static void main(String[] args) { SpringApplication.run(ApiHandlerApplication.class, args); + java.security.Security.setProperty("networkaddress.cache.ttl", "10"); System.getProperties().setProperty("mso.db", "MARIADB"); System.getProperties().setProperty("server.name", "Springboot"); setLogsDir(); @@ -69,4 +71,5 @@ public class ApiHandlerApplication { executor.initialize(); return executor; } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java index 4d81695e55..0db63e7493 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java @@ -23,8 +23,8 @@ package org.onap.so.apihandlerinfra.configuration; import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; @@ -32,10 +32,13 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jmx.export.MBeanExporter; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; @Configuration @EnableTransactionManagement @@ -44,11 +47,23 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @Profile({"!test"}) public class CatalogDBConfig { + @Autowired(required = false) + private MBeanExporter mBeanExporter; + + @Bean + @ConfigurationProperties(prefix = "spring.datasource.hikari") + public HikariConfig catalogDbConfig() { + return new HikariConfig(); + } + @Primary @Bean(name = "dataSource") - @ConfigurationProperties(prefix = "spring.datasource") public DataSource dataSource() { - return DataSourceBuilder.create().build(); + if (mBeanExporter != null) { + mBeanExporter.addExcludedBean("dataSource"); + } + HikariConfig hikariConfig = this.catalogDbConfig(); + return new HikariDataSource(hikariConfig); } @Primary diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java index 1bc54ffe7b..02cbf2f3bf 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java @@ -23,18 +23,21 @@ package org.onap.so.apihandlerinfra.configuration; import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jmx.export.MBeanExporter; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; @Configuration @EnableTransactionManagement @@ -43,13 +46,24 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @Profile({"!test"}) public class RequestDBConfig { + @Autowired(required = false) + private MBeanExporter mBeanExporter; + + @Bean + @ConfigurationProperties(prefix = "request.datasource.hikari") + public HikariConfig requestDbConfig() { + return new HikariConfig(); + } + @Bean(name = "requestDataSource") - @ConfigurationProperties(prefix = "request.datasource") public DataSource dataSource() { - return DataSourceBuilder.create().build(); + if (mBeanExporter != null) { + mBeanExporter.addExcludedBean("requestDataSource"); + } + HikariConfig hikariConfig = this.requestDbConfig(); + return new HikariDataSource(hikariConfig); } - @Bean(name = "requestEntityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier("requestDataSource") DataSource dataSource) { -- cgit 1.2.3-korg