Add Primary Data Source Configuration
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Thu, 6 Dec 2018 21:46:19 +0000 (16:46 -0500)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Thu, 6 Dec 2018 21:46:19 +0000 (16:46 -0500)
Change-Id: I338f8564c20ebc2c139c80806468be8f8d3bb7e4
Issue-ID: CCSDK-698
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
13 files changed:
ms/blueprintsprocessor/.gitignore
ms/blueprintsprocessor/application/pom.xml
ms/blueprintsprocessor/application/src/main/resources/application.properties
ms/blueprintsprocessor/application/src/test/resources/application.properties
ms/blueprintsprocessor/modules/commons/db-lib/pom.xml
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibGenericService.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/service/PrimaryDBLibGenericService.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/logback-test.xml [new file with mode: 0644]

index 983e231..f72f78a 100644 (file)
@@ -25,6 +25,7 @@
 **/.springBeans
 **/.directory
 
+**/transaction.log
 **/*versionsBackup
 **/blackDuckHub*
 **/*.jsonld
\ No newline at end of file
index 4e652d5..796cde6 100644 (file)
             <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
             <artifactId>selfservice-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.powermock</groupId>
             <artifactId>powermock-api-mockito2</artifactId>
index cb8ca92..81b9976 100644 (file)
 #\r
 # Blueprint Processor File Execution and Handling Properties\r
 blueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy\r
-blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive
\ No newline at end of file
+blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive\r
+# Primary Database Configuration\r
+blueprintsprocessor.db.primary.url=jdbc:mysql://localhost:3306/sdnctl\r
+blueprintsprocessor.db.primary.username=sdnctl\r
+blueprintsprocessor.db.primary.password=sdnctl\r
+blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver\r
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=validate\r
+blueprintsprocessor.db.primary.hibernateDDLAuto=none\r
+blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy\r
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
\ No newline at end of file
index fdd755e..f896ee0 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-blueprintsprocessor.blueprintDeployPath=/opt
-blueprintsprocessor.blueprintArchivePath=/opt
\ No newline at end of file
+# Blueprint Processor File Execution and Handling Properties
+blueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy
+blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive
+# Primary Database Configuration
+blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
+blueprintsprocessor.db.primary.username=sa
+blueprintsprocessor.db.primary.password=
+blueprintsprocessor.db.primary.driverClassName=org.h2.Driver
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop
+blueprintsprocessor.db.primary.hibernateDDLAuto=update
+blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
\ No newline at end of file
index 5f5b89d..4b11f83 100644 (file)
@@ -33,7 +33,6 @@
             <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
             <artifactId>core</artifactId>
         </dependency>
-
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jpa</artifactId>
             <groupId>javax.validation</groupId>
             <artifactId>validation-api</artifactId>
         </dependency>
-
         <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.mariadb.jdbc</groupId>
+            <artifactId>mariadb-java-client</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-testing</artifactId>
             <scope>test</scope>
         </dependency>
-
     </dependencies>
 
 </project>
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
new file mode 100644 (file)
index 0000000..0bdee9b
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db
+
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
+import org.springframework.boot.context.properties.EnableConfigurationProperties
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan
+@EnableConfigurationProperties
+open class BluePrintDBLibConfiguration(private var bluePrintProperties: BluePrintProperties) {
+
+    @Bean("primary-database-properties")
+    open fun getPrimaryProperties(): PrimaryDataSourceProperties {
+        return bluePrintProperties.propertyBeanType(DBLibConstants.PREFIX_DB_PRIMARY,
+                PrimaryDataSourceProperties::class.java)
+    }
+}
+
+class DBLibConstants {
+    companion object {
+        const val PREFIX_DB_PRIMARY: String = "blueprintsprocessor.db.primary"
+    }
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt
new file mode 100644 (file)
index 0000000..a16e556
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db
+
+
+open class PrimaryDataSourceProperties {
+    lateinit var url: String
+    lateinit var username: String
+    lateinit var password: String
+    lateinit var driverClassName: String
+    lateinit var hibernateHbm2ddlAuto: String
+    lateinit var hibernateDDLAuto: String
+    lateinit var hibernateNamingStrategy: String
+    lateinit var hibernateDialect: String
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibGenericService.kt
new file mode 100644 (file)
index 0000000..86420f9
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db
+
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
+
+interface BluePrintDBLibGenericService {
+
+    fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate
+
+    fun query(sql: String, params: Map<String, Any>): List<Map<String, Any>>
+
+    fun update(sql: String, params: Map<String, Any>): Int
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt
new file mode 100644 (file)
index 0000000..bf76e21
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary
+
+import org.onap.ccsdk.apps.blueprintsprocessor.db.PrimaryDataSourceProperties
+import org.slf4j.LoggerFactory
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.context.annotation.Primary
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
+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 java.util.*
+import javax.sql.DataSource
+
+@Configuration
+@EnableJpaRepositories(
+        basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor.db.primary"],
+        entityManagerFactoryRef = "primaryEntityManager",
+        transactionManagerRef = "primaryTransactionManager"
+)
+open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: PrimaryDataSourceProperties) {
+    val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!!
+
+    @Primary
+    @Bean("primaryEntityManager")
+    open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean {
+        val em = LocalContainerEntityManagerFactoryBean()
+        em.dataSource = primaryDataSource()
+        em.setPackagesToScan(
+                "org.onap.ccsdk.apps.blueprintsprocessor.db.primary")
+
+        val vendorAdapter = HibernateJpaVendorAdapter()
+        em.jpaVendorAdapter = vendorAdapter
+        val properties = HashMap<String, Any>()
+        properties["hibernate.hbm2ddl.auto"] = primaryDataSourceProperties.hibernateHbm2ddlAuto
+        properties["hibernate.dialect"] = primaryDataSourceProperties.hibernateDialect
+        em.jpaPropertyMap = properties
+        return em
+    }
+
+    @Primary
+    @Bean("primaryDataSource")
+    open fun primaryDataSource(): DataSource {
+        val dataSource = DriverManagerDataSource()
+        dataSource.setDriverClassName(primaryDataSourceProperties.driverClassName)
+        dataSource.url = primaryDataSourceProperties.url
+        dataSource.username = primaryDataSourceProperties.username
+        dataSource.password = primaryDataSourceProperties.password
+        return dataSource
+    }
+
+    @Primary
+    @Bean("primaryTransactionManager")
+    open fun primaryTransactionManager(): PlatformTransactionManager {
+        val transactionManager = JpaTransactionManager()
+        transactionManager.entityManagerFactory = primaryEntityManager().getObject()
+        log.info("Initialised Primary Transaction Manager for url ${primaryDataSourceProperties.url}")
+        return transactionManager
+    }
+
+    @Bean("primaryNamedParameterJdbcTemplate")
+    open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate {
+        return NamedParameterJdbcTemplate(primaryDataSource)
+    }
+
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/service/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/service/PrimaryDBLibGenericService.kt
new file mode 100644 (file)
index 0000000..87f32ef
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.service
+
+import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
+import org.springframework.stereotype.Service
+
+@Service
+class PrimaryDBLibGenericService(private val primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate)
+    : BluePrintDBLibGenericService {
+
+    override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate {
+        return primaryNamedParameterJdbcTemplate
+    }
+
+    override fun query(sql: String, params: Map<String, Any>): List<Map<String, Any>> {
+        return primaryNamedParameterJdbcTemplate.queryForList(sql, params)
+    }
+
+    override fun update(sql: String, params: Map<String, Any>): Int {
+        return primaryNamedParameterJdbcTemplate.update(sql, params)
+    }
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt
new file mode 100644 (file)
index 0000000..aa48c8e
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+import javax.sql.DataSource
+import kotlin.test.assertNotNull
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [BlueprintPropertyConfiguration::class, BluePrintProperties::class,
+    BluePrintDBLibConfiguration::class])
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+class PrimaryDatabaseConfigurationTest {
+
+    @Autowired
+    lateinit var primaryDataSource: DataSource
+
+    @Test
+    fun testPrimaryDatabaseConfiguration() {
+        assertNotNull(primaryDataSource, " failed to create primary data source")
+    }
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties
new file mode 100644 (file)
index 0000000..672ff80
--- /dev/null
@@ -0,0 +1,24 @@
+# suppress inspection "UnusedProperty" for whole file
+#
+# Copyright © 2017-2018 AT&T Intellectual Property.
+#
+# 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.
+#
+blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
+blueprintsprocessor.db.primary.username=sa
+blueprintsprocessor.db.primary.password=
+blueprintsprocessor.db.primary.driverClassName=org.h2.Driver
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop
+blueprintsprocessor.db.primary.hibernateDDLAuto=update
+blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/logback-test.xml
new file mode 100644 (file)
index 0000000..f9ec9fe
--- /dev/null
@@ -0,0 +1,35 @@
+<!--\r
+  ~ Copyright © 2017-2018 AT&T Intellectual Property.\r
+  ~\r
+  ~ Licensed under the Apache License, Version 2.0 (the "License");\r
+  ~ you may not use this file except in compliance with the License.\r
+  ~ You may obtain a copy of the License at\r
+  ~\r
+  ~     http://www.apache.org/licenses/LICENSE-2.0\r
+  ~\r
+  ~ Unless required by applicable law or agreed to in writing, software\r
+  ~ distributed under the License is distributed on an "AS IS" BASIS,\r
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  ~ See the License for the specific language governing permissions and\r
+  ~ limitations under the License.\r
+  -->\r
+\r
+<configuration>\r
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">\r
+        <!-- encoders are assigned the type\r
+             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->\r
+        <encoder>\r
+            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>\r
+        </encoder>\r
+    </appender>\r
+\r
+    <logger name="org.springframework.test" level="warn"/>\r
+    <logger name="org.springframework" level="warn"/>\r
+    <logger name="org.hibernate" level="info"/>\r
+    <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>\r
+\r
+    <root level="warn">\r
+        <appender-ref ref="STDOUT"/>\r
+    </root>\r
+\r
+</configuration>\r