Changes related to eviction of connections 21/90021/1
authorBenjamin, Max (mb388a) <mb388a@us.att.com>
Mon, 17 Jun 2019 14:51:08 +0000 (10:51 -0400)
committerBenjamin, Max (mb388a) <mb388a@us.att.com>
Mon, 17 Jun 2019 15:03:23 +0000 (11:03 -0400)
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) <mb388a@us.att.com>
22 files changed:
adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java
adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBConfig.java [new file with mode: 0644]
adapters/mso-catalog-db-adapter/src/main/resources/application.yaml
adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/CatalogDBConfig.java [new file with mode: 0644]
adapters/mso-openstack-adapters/src/main/resources/application.yaml
adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java
adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/RequestDBConfig.java
adapters/mso-requests-db-adapter/src/main/resources/application.yaml
asdc-controller/src/main/java/org/onap/so/asdc/CatalogDBConfig.java
asdc-controller/src/main/java/org/onap/so/asdc/RequestDBConfig.java
asdc-controller/src/main/resources/application.yaml
bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/CamundaDBConfig.java [new file with mode: 0644]
bpmn/mso-infrastructure-bpmn/src/main/resources/application.yaml
common/pom.xml
common/src/main/java/org/onap/so/db/connections/DbDnsIpAddress.java [new file with mode: 0644]
common/src/main/java/org/onap/so/db/connections/ScheduledDnsLookup.java [new file with mode: 0644]
common/src/test/java/org/onap/so/db/connections/DbDnsIpAddressTest.java [new file with mode: 0644]
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ApiHandlerApplication.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java
mso-api-handlers/mso-api-handler-infra/src/main/resources/application.yaml
pom.xml

index a0a0756..aa19aed 100644 (file)
@@ -24,12 +24,14 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 @SpringBootApplication(scanBasePackages = {"org.onap.so.adapters.catalogdb", "org.onap.so.db.catalog.client",
         "org.onap.so.logging.jaxrs.filter", "org.onap.so.logging.spring.interceptor", "org.onap.so.client",
-        "org.onap.so.configuration"})
+        "org.onap.so.configuration", "org.onap.so.db"})
 @EnableJpaRepositories("org.onap.so.db.catalog.data.repository")
 @EntityScan("org.onap.so.db.catalog.beans")
+@EnableScheduling
 public class CatalogDBApplication {
 
     private static final String LOGS_DIR = "logs_dir";
@@ -42,6 +44,7 @@ public class CatalogDBApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(CatalogDBApplication.class, args);
+        java.security.Security.setProperty("networkaddress.cache.ttl", "10");
         System.getProperties().setProperty("mso.db", "MARIADB");
         System.getProperties().setProperty("server.name", "Springboot");
         setLogsDir();
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBConfig.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBConfig.java
new file mode 100644 (file)
index 0000000..f7faa1f
--- /dev/null
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.catalogdb;
+
+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.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.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
+@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory",
+        basePackages = {"org.onap.so.db.catalog.data.repository"})
+@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")
+    public DataSource dataSource() {
+        if (mBeanExporter != null) {
+            mBeanExporter.addExcludedBean("dataSource");
+        }
+        HikariConfig hikariConfig = this.catalogDbConfig();
+        return new HikariDataSource(hikariConfig);
+    }
+
+    @Primary
+    @Bean(name = "entityManagerFactory")
+    public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
+            @Qualifier("dataSource") DataSource dataSource) {
+        return builder.dataSource(dataSource).packages("org.onap.so.db.catalog.beans").persistenceUnit("catalogDB")
+                .build();
+    }
+
+    @Primary
+    @Bean(name = "transactionManager")
+    public PlatformTransactionManager transactionManager(
+            @Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
+        return new JpaTransactionManager(entityManagerFactory);
+    }
+
+}
index b1528a0..bcf5429 100644 (file)
@@ -16,11 +16,14 @@ mso:
     
 spring:
   datasource:
-    url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
-    username: ${DB_USERNAME}
-    password: ${DB_PASSWORD}
-    driver-class-name: org.mariadb.jdbc.Driver
-    initialization-mode: never
+     hikari:
+       jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
+       username: ${DB_USERNAME}
+       password: ${DB_PASSWORD}
+       driver-class-name: org.mariadb.jdbc.Driver
+       pool-name: catdb-pool
+       registerMbeans: true
+       
   flyway:
     baseline-on-migrate: false
     url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/CatalogDBConfig.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/CatalogDBConfig.java
new file mode 100644 (file)
index 0000000..299e695
--- /dev/null
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.openstack;
+
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+import org.springframework.beans.factory.annotation.Qualifier;
+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.Primary;
+import org.springframework.context.annotation.Profile;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+@Configuration
+@EnableTransactionManagement
+@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory",
+        basePackages = {"org.onap.so.db.catalog.data.repository"})
+@EnableScheduling
+@Profile({"!test"})
+public class CatalogDBConfig {
+
+    @Bean
+    @ConfigurationProperties(prefix = "spring.datasource.hikari")
+    public HikariConfig catalogDbConfig() {
+        return new HikariConfig();
+    }
+
+    @Primary
+    @Bean(name = "dataSource")
+    public DataSource dataSource() {
+        HikariConfig hikariConfig = this.catalogDbConfig();
+        return new HikariDataSource(hikariConfig);
+    }
+
+    @Primary
+    @Bean(name = "entityManagerFactory")
+    public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
+            @Qualifier("dataSource") DataSource dataSource) {
+        return builder.dataSource(dataSource).packages("org.onap.so.db.catalog.beans").persistenceUnit("catalogDB")
+                .build();
+    }
+
+    @Primary
+    @Bean(name = "transactionManager")
+    public PlatformTransactionManager transactionManager(
+            @Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
+        return new JpaTransactionManager(entityManagerFactory);
+    }
+
+}
index 470bb31..1c4de2d 100644 (file)
@@ -19,11 +19,13 @@ mso:
       retrySequence: 1, 1, 2, 3, 5, 8, 13, 20
 spring:
   datasource:
-    url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
-    username: ${DB_USERNAME}
-    password: ${DB_PASSWORD}
-    driver-class-name: org.mariadb.jdbc.Driver
-    initialization-mode: never
+    hikari:
+      jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
+      username: ${DB_USERNAME}
+      password: ${DB_PASSWORD}
+      driver-class-name: org.mariadb.jdbc.Driver
+      pool-name: catdb-pool
+      registerMbeans: true
   jpa:
       show-sql: false
       hibernate:
index 6dab6c1..85c05de 100644 (file)
@@ -27,6 +27,9 @@ import javax.sql.DataSource;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.EnableMBeanExport;
+import org.springframework.jmx.support.RegistrationPolicy;
+import org.springframework.scheduling.annotation.EnableScheduling;
 import net.javacrumbs.shedlock.core.LockProvider;
 import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
 import net.javacrumbs.shedlock.spring.ScheduledLockConfiguration;
@@ -38,6 +41,8 @@ import net.javacrumbs.shedlock.spring.ScheduledLockConfigurationBuilder;
  */
 
 @SpringBootApplication(scanBasePackages = {"org.onap.so"})
+@EnableScheduling
+@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
 public class MSORequestDBApplication {
 
     private static final String LOGS_DIR = "logs_dir";
@@ -50,6 +55,7 @@ public class MSORequestDBApplication {
 
     public static void main(String... args) {
         SpringApplication.run(MSORequestDBApplication.class, args);
+        java.security.Security.setProperty("networkaddress.cache.ttl", "10");
         setLogsDir();
     }
 
@@ -64,5 +70,4 @@ public class MSORequestDBApplication {
                 .withDefaultLockAtMostFor(Duration.ofMinutes(10)).build();
     }
 
-
 }
index 651cce8..b14e3ce 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.adapters.requestsdb.application;
 
 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;
@@ -32,10 +33,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;
 
 @Profile({"!test"})
 @Configuration
@@ -44,13 +48,25 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
         transactionManagerRef = "requestTransactionManager", basePackages = {"org.onap.so.db.request.data.repository"})
 public class RequestDBConfig {
 
-    @Primary
+    @Autowired(required = false)
+    private MBeanExporter mBeanExporter;
+
+    @Bean
+    @ConfigurationProperties(prefix = "spring.datasource.hikari")
+    public HikariConfig requestDbConfig() {
+        return new HikariConfig();
+    }
+
     @Bean(name = "requestDataSource")
-    @ConfigurationProperties(prefix = "spring.datasource")
     public DataSource dataSource() {
-        return DataSourceBuilder.create().build();
+        if (mBeanExporter != null) {
+            mBeanExporter.addExcludedBean("requestDataSource");
+        }
+        HikariConfig hikariConfig = this.requestDbConfig();
+        return new HikariDataSource(hikariConfig);
     }
 
+
     @Primary
     @Bean(name = "requestEntityManagerFactory")
     public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
index 645a6e9..7234733 100644 (file)
@@ -18,10 +18,13 @@ mso:
 # H2
 spring:
   datasource:
-    jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
-    username: ${DB_USERNAME}
-    password: ${DB_PASSWORD}
-    driver-class-name: org.mariadb.jdbc.Driver
+    hikari:
+      jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
+      username: ${DB_USERNAME}
+      password: ${DB_PASSWORD}
+      driver-class-name: org.mariadb.jdbc.Driver 
+      pool-name: reqdb-pool
+      registerMbeans: true
   flyway:
     baseline-on-migrate: false
     url:  jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
@@ -57,4 +60,4 @@ management:
     export:
       prometheus:
         enabled: true # Whether exporting of metrics to Prometheus is enabled.
-        step: 1m # Step size (i.e. reporting frequency) to use.
\ No newline at end of file
+        step: 1m # Step size (i.e. reporting frequency) to use.
index 3494945..39bb836 100644 (file)
 
 package org.onap.so.asdc;
 
-
 import javax.persistence.EntityManagerFactory;
 import javax.sql.DataSource;
 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;
@@ -36,6 +34,8 @@ 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 +44,17 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @Profile({"!test"})
 public class CatalogDBConfig {
 
+    @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();
+        HikariConfig hikariConfig = this.catalogDbConfig();
+        return new HikariDataSource(hikariConfig);
     }
 
     @Primary
index 8320da0..821b2da 100644 (file)
 
 package org.onap.so.asdc;
 
-
 import javax.persistence.EntityManagerFactory;
 import javax.sql.DataSource;
 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;
@@ -35,6 +33,8 @@ 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 +43,18 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @Profile({"!test"})
 public class RequestDBConfig {
 
+    @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();
+        HikariConfig hikariConfig = this.requestDbConfig();
+        return new HikariDataSource(hikariConfig);
     }
 
-
     @Bean(name = "requestEntityManagerFactory")
     public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
             @Qualifier("requestDataSource") DataSource dataSource) {
@@ -57,7 +62,6 @@ public class RequestDBConfig {
                 .build();
     }
 
-
     @Bean(name = "requestTransactionManager")
     public PlatformTransactionManager transactionManager(
             @Qualifier("requestEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
index 2d0a2ac..beb40e5 100644 (file)
@@ -4,15 +4,13 @@ server:
 
 spring:
   datasource:
-    jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
-    username: ${DB_USERNAME}
-    password: ${DB_PASSWORD}
-    driver-class-name: org.mariadb.jdbc.Driver
-    dbcp2: 
-      initial-size: 5
-      max-total: 20 
-      validation-query: select 1
-      test-on-borrow: true 
+    hikari:
+      jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
+      username: ${DB_USERNAME}
+      password: ${DB_PASSWORD}
+      driver-class-name: org.mariadb.jdbc.Driver
+      pool-name: catdb-pool
+      registerMbeans: true
   jpa:
       show-sql: true
       hibernate:
@@ -23,10 +21,14 @@ spring:
 
 request:
   datasource:
-    jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
-    username: ${DB_USERNAME}
-    password: ${DB_PASSWORD}
-    driver-class-name: org.mariadb.jdbc.Driver  
+    hikari:
+      jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
+      username: ${DB_USERNAME}
+      password: ${DB_PASSWORD}
+      driver-class-name: org.mariadb.jdbc.Driver
+      pool-name: reqdb-pool
+      registerMbeans: true
+      
 #Actuator
 management:
   endpoints:
diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/CamundaDBConfig.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/CamundaDBConfig.java
new file mode 100644 (file)
index 0000000..686b377
--- /dev/null
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure;
+
+
+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.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.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
+@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory",
+        basePackages = {"org.onap.so.db.catalog.data.repository"})
+@Profile({"!test"})
+public class CamundaDBConfig {
+
+    @Autowired(required = false)
+    private MBeanExporter mBeanExporter;
+
+    @Bean
+    @ConfigurationProperties(prefix = "spring.datasource.hikari")
+    public HikariConfig camundaDbConfig() {
+        return new HikariConfig();
+    }
+
+    @Primary
+    @Bean(name = "dataSource")
+    public DataSource dataSource() {
+        if (mBeanExporter != null) {
+            mBeanExporter.addExcludedBean("dataSource");
+        }
+        HikariConfig hikariConfig = this.camundaDbConfig();
+        return new HikariDataSource(hikariConfig);
+    }
+
+    @Primary
+    @Bean(name = "entityManagerFactory")
+    public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
+            @Qualifier("dataSource") DataSource dataSource) {
+        return builder.dataSource(dataSource).packages("org.onap.so.db.catalog.beans").persistenceUnit("catalogDB")
+                .build();
+    }
+
+    @Primary
+    @Bean(name = "transactionManager")
+    public PlatformTransactionManager transactionManager(
+            @Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
+        return new JpaTransactionManager(entityManagerFactory);
+    }
+
+}
index e364981..185db16 100644 (file)
@@ -7,10 +7,13 @@ mso:
     auditInventory: false
 spring: 
   datasource:
-     driver-class-name: org.mariadb.jdbc.Driver 
-     url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/camundabpmn
-     username: ${DB_ADMIN_USERNAME}
-     password: ${DB_ADMIN_PASSWORD}
+    hikari:
+      jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/camundabpmn
+      username: ${DB_ADMIN_USERNAME}
+      password: ${DB_ADMIN_PASSWORD}
+      driver-class-name: org.mariadb.jdbc.Driver
+      pool-name: bpmn-pool
+      registerMbeans: true
   http:
     multipart:
       enabled: false
index 2742afe..316cad1 100644 (file)
   </properties>
 
   <dependencies>
+    <dependency>
+      <groupId>hikari-cp</groupId>
+      <artifactId>hikari-cp</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpclient</artifactId>
diff --git a/common/src/main/java/org/onap/so/db/connections/DbDnsIpAddress.java b/common/src/main/java/org/onap/so/db/connections/DbDnsIpAddress.java
new file mode 100644 (file)
index 0000000..8ee63a4
--- /dev/null
@@ -0,0 +1,20 @@
+package org.onap.so.db.connections;
+
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+@Component
+@Scope("singleton")
+public class DbDnsIpAddress {
+
+    private String ipAddress;
+
+    public String getIpAddress() {
+        return ipAddress;
+    }
+
+    public void setIpAddress(String ipAddress) {
+        this.ipAddress = ipAddress;
+    }
+
+}
diff --git a/common/src/main/java/org/onap/so/db/connections/ScheduledDnsLookup.java b/common/src/main/java/org/onap/so/db/connections/ScheduledDnsLookup.java
new file mode 100644 (file)
index 0000000..14f2f5e
--- /dev/null
@@ -0,0 +1,78 @@
+package org.onap.so.db.connections;
+
+import java.lang.management.ManagementFactory;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Set;
+import javax.management.JMX;
+import javax.management.MBeanServer;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Profile;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import com.zaxxer.hikari.HikariPoolMXBean;
+
+@Component
+@Profile("!test")
+public class ScheduledDnsLookup {
+
+    private static final String JMX_HIKARI_DB_POOL_LOOKUP = "com.zaxxer.hikari:type=Pool (*,*";
+
+    private static final String DB_HOST = "DB_HOST";
+
+    @Autowired
+    private DbDnsIpAddress dnsIpAddress;
+
+    private static Logger logger = LoggerFactory.getLogger(ScheduledDnsLookup.class);
+
+    @Scheduled(fixedRate = 15000)
+    public void performDnsLookup() {
+
+        String dnsUrl = System.getenv(DB_HOST);
+
+        try {
+            if (dnsUrl == null) {
+                logger.error("Database DNS is not provided. Please verify the configuration");
+                return;
+            }
+
+            InetAddress inetAddress = java.net.InetAddress.getByName(dnsUrl);
+            String ipAddress = inetAddress.getHostAddress();
+            String currentIpAddress = dnsIpAddress.getIpAddress();
+            /* This is in initial state */
+            if (currentIpAddress == null) {
+                dnsIpAddress.setIpAddress(ipAddress);
+                return;
+            }
+
+            if ((ipAddress != null) && (!ipAddress.equalsIgnoreCase(currentIpAddress))) {
+                logger.debug("Switched Database IP Address from {} to {}", currentIpAddress, ipAddress);
+                softEvictConnectionPool();
+                dnsIpAddress.setIpAddress(ipAddress);
+            }
+        } catch (UnknownHostException e) {
+            logger.warn("Database DNS %s is not resolvable to an IP Address", dnsUrl);
+        }
+
+    }
+
+    private void softEvictConnectionPool() {
+        try {
+            MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
+            ObjectName queryObj = new ObjectName(JMX_HIKARI_DB_POOL_LOOKUP);
+            Set<ObjectInstance> objects = mBeanServer.queryMBeans(queryObj, null);
+            for (ObjectInstance objectInstance : objects) {
+                ObjectName poolObject = objectInstance.getObjectName();
+                HikariPoolMXBean poolProxy = JMX.newMXBeanProxy(mBeanServer, poolObject, HikariPoolMXBean.class);
+                logger.debug("database connection pool is soft evicted for connections");
+                poolProxy.softEvictConnections();
+            }
+        } catch (Exception e) {
+            logger.warn("Error encountered in evicting DB connection pool", e);
+        }
+    }
+}
diff --git a/common/src/test/java/org/onap/so/db/connections/DbDnsIpAddressTest.java b/common/src/test/java/org/onap/so/db/connections/DbDnsIpAddressTest.java
new file mode 100644 (file)
index 0000000..0dc35a0
--- /dev/null
@@ -0,0 +1,19 @@
+package org.onap.so.db.connections;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+public class DbDnsIpAddressTest {
+
+    @Test
+    public void test() {
+        final String expectedIpAddress = "10.0.75.1";
+
+        DbDnsIpAddress dbDnsIpAddress = new DbDnsIpAddress();
+        dbDnsIpAddress.setIpAddress(expectedIpAddress);
+
+        assertEquals(expectedIpAddress, dbDnsIpAddress.getIpAddress());
+
+    }
+
+}
index bc1972a..5beb481 100644 (file)
 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;
     }
+
 }
index 4d81695..0db63e7 100644 (file)
@@ -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
index 1bc54ff..02cbf2f 100644 (file)
@@ -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) {
index 03934ed..136acfb 100644 (file)
@@ -29,10 +29,13 @@ mso:
                 
 spring:
   datasource:
-    jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
-    username: ${DB_USERNAME}
-    password: ${DB_PASSWORD}
-    driver-class-name: org.mariadb.jdbc.Driver
+    hikari:
+      jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
+      username: ${DB_USERNAME}
+      password: ${DB_PASSWORD}
+      driver-class-name: org.mariadb.jdbc.Driver
+      pool-name: catdb-pool
+      registerMbeans: true
   jpa:
       show-sql: true
       hibernate:
@@ -45,11 +48,13 @@ spring:
                        
 request:
   datasource:
-    jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
-    username: ${DB_USERNAME}
-    password: ${DB_PASSWORD}
-    driver-class-name: org.mariadb.jdbc.Driver
-
+    hikari:
+      jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
+      username: ${DB_USERNAME}
+      password: ${DB_PASSWORD}
+      driver-class-name: org.mariadb.jdbc.Driver
+      pool-name: reqdb-pool
+      registerMbeans: true
 #Actuator
 management:
   endpoints:
diff --git a/pom.xml b/pom.xml
index 1abbeae..7384c5b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -70,6 +70,8 @@
     <camunda.springboot.version>3.2.0</camunda.springboot.version>
     <format.skipValidate>false</format.skipValidate>
     <format.skipExecute>true</format.skipExecute>
+    <hikari.cp.version>2.7.1</hikari.cp.version>
+    <io.fabric8.version>4.1.0</io.fabric8.version>
   </properties>
   <distributionManagement>
     <repository>
         <plugin>
           <groupId>io.fabric8</groupId>
           <artifactId>fabric8-maven-plugin</artifactId>
-          <version>4.1.0</version>
+          <version>${io.fabric8.version}</version>
           <configuration>
             <skip>${docker.skip}</skip>
             <skipBuild>${docker.skip.build}</skipBuild>
             <dockerHost>${docker.newHost}</dockerHost>
             <!-- 1. Update address to your local docker VM. 2. Add IP to your NO_PROXY environment variable -->
             <certPath>${docker.host.cert.path}</certPath>
-            <!-- Add -Ddocker.host.cert.pat="path to your local certs directory" 
-              to maven build command -->
+            <!-- Add -Ddocker.host.cert.pat="path to your local certs directory" to maven build command -->
             <pushRegistry>${dockerPushRepo}</pushRegistry>
             <!-- Update .m2/settings.xml Add server id settings.dockerRepository, username, and password -->
             <pullRegistry>${dockerPullRepo}</pullRegistry>
-            <!-- If docker repo is not public. Update .m2/settings.xml Add server id settings.dockerRepository, username, and password -->
+            <!-- If docker repo is not public. Update .m2/settings.xml Add server id settings.dockerRepository, username, 
+              and password -->
             <images>
               <image>
                 <alias>service</alias>
         <artifactId>snakeyaml</artifactId>
         <version>1.19</version>
       </dependency>
+      <dependency>
+        <groupId>hikari-cp</groupId>
+        <artifactId>hikari-cp</artifactId>
+        <version>${hikari.cp.version}</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
   <profiles>