summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/commons
diff options
context:
space:
mode:
authorvinal patel <vinal.narendrabhai.patel@ibm.com>2019-02-20 16:02:44 -0500
committervinal patel <vinal.narendrabhai.patel@ibm.com>2019-03-18 17:24:27 -0400
commitc1ddd6bed42f5293c20365e0e4415c4ccefb29e2 (patch)
treeea6e021d5a2afad58100622883bb537907e001d3 /ms/blueprintsprocessor/modules/commons
parentb9859c7a69aece893b6cacce4dd0d4ce2d0badcb (diff)
Ressource resolution using configurable database
Change-Id: I40338a221884d6f4df4c8a7dc3dac1f58f142074 Issue-ID: CCSDK-1092 Signed-off-by: vinal patel <vinal.narendrabhai.patel@ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons')
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt1
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt29
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt105
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt72
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt59
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt55
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt27
7 files changed, 273 insertions, 75 deletions
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
index 276ece139..3e9ec0cef 100644
--- 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
@@ -40,6 +40,7 @@ class DBLibConstants {
//list of database
const val MARIA_DB: String = "maria-db"
+ const val PRIMARY_DB: String = "primary-db"
const val MYSQL_DB: String = "mysql-db"
const val ORACLE_DB: String = "oracle-db"
const val POSTGRES_DB: String = "postgres-db"
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
index a16e55657..ab2c19a40 100644
--- 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
@@ -17,13 +17,36 @@
package org.onap.ccsdk.apps.blueprintsprocessor.db
-open class PrimaryDataSourceProperties {
+open class DBDataSourceProperties {
lateinit var url: String
lateinit var username: String
lateinit var password: String
- lateinit var driverClassName: String
+ open lateinit var driverClassName: String
+
+}
+
+open class PrimaryDataSourceProperties: DBDataSourceProperties() {
+ lateinit var hibernateHbm2ddlAuto: String
+ lateinit var hibernateDDLAuto: String
+ lateinit var hibernateNamingStrategy: String
+ lateinit var hibernateDialect: String
+}
+
+open class MariaDataSourceProperties: DBDataSourceProperties() {
lateinit var hibernateHbm2ddlAuto: String
lateinit var hibernateDDLAuto: String
lateinit var hibernateNamingStrategy: String
+ lateinit var type: String
lateinit var hibernateDialect: String
-} \ No newline at end of file
+ override var driverClassName = DBLibConstants.DRIVER_MARIA_DB
+}
+
+open class MySqlDataSourceProperties: DBDataSourceProperties() {
+ lateinit var hibernateHbm2ddlAuto: String
+ lateinit var hibernateDDLAuto: String
+ lateinit var hibernateNamingStrategy: String
+ lateinit var type: String
+ lateinit var hibernateDialect: String
+ override var driverClassName = DBLibConstants.DRIVER_MYSQL_DB
+}
+
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
new file mode 100644
index 000000000..f93c241d4
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2019 Bell Canada 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 com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
+import org.onap.ccsdk.apps.blueprintsprocessor.db.*
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.stereotype.Service
+
+@Service
+class BluePrintDBLibPropertySevice(private var bluePrintProperties: BluePrintProperties) {
+
+ fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService {
+ val dBConnetionProperties = dBDataSourceProperties(jsonNode)
+ return blueprintDBDataSourceService(dBConnetionProperties)
+ }
+
+ fun JdbcTemplate(selector: String): BluePrintDBLibGenericService {
+ val prefix = "blueprintsprocessor.database.$selector"
+ val dBConnetionProperties = dBDataSourceProperties(prefix)
+ return blueprintDBDataSourceService(dBConnetionProperties)
+ }
+
+ private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties {
+ val type = jsonNode.get("type").textValue()
+ return when (type) {
+ DBLibConstants.MYSQL_DB -> {
+ JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)!!
+ }
+ DBLibConstants.MARIA_DB -> {
+ JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)!!
+ }
+ else -> {
+ throw BluePrintProcessorException("Rest adaptor($type) is not supported")
+ }
+ }
+ }
+
+ private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties {
+ val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
+ return when (type) {
+ DBLibConstants.MARIA_DB -> {
+ mariaDBConnectionProperties(prefix)
+ }
+ DBLibConstants.MYSQL_DB -> {
+ mySqlDBConnectionProperties(prefix)
+ }
+ DBLibConstants.ORACLE_DB -> {
+ TODO("not implemented")
+ }
+ DBLibConstants.POSTGRES_DB -> {
+ TODO("not implemented")
+ }
+ DBLibConstants.PRIMARY_DB -> {
+ primaryDBConnectionProperties(prefix)
+ }
+ else -> {
+ throw BluePrintProcessorException("Rest adaptor($type) is not supported")
+ }
+ }
+ }
+
+ private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService {
+ when (dBConnetionProperties) {
+ is MariaDataSourceProperties -> {
+ return MariaDatabaseConfiguration(dBConnetionProperties)
+ }
+ is MySqlDataSourceProperties -> {
+ return MySqlDatabaseConfiguration(dBConnetionProperties)
+ }
+ else -> {
+ throw BluePrintProcessorException("couldn't get rest service for")
+ }
+ }
+ }
+
+ private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties {
+ return bluePrintProperties.propertyBeanType(prefix, MySqlDataSourceProperties::class.java)
+ }
+
+ private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties {
+ return bluePrintProperties.propertyBeanType(prefix, MariaDataSourceProperties::class.java)
+ }
+
+ private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties {
+ return bluePrintProperties.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java)
+ }
+
+} \ 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/DBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt
deleted file mode 100644
index af7ab0547..000000000
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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 com.fasterxml.jackson.databind.JsonNode
-import org.onap.ccsdk.apps.blueprintsprocessor.db.AbstractDBLibGenericService
-import org.onap.ccsdk.apps.blueprintsprocessor.db.DBLibConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import org.springframework.boot.jdbc.DataSourceBuilder
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
-import org.springframework.stereotype.Service
-
-@Service
-open class DBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate)
- : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) {
-
- fun primaryJdbcTemplate():NamedParameterJdbcTemplate{
- return namedParameterJdbcTemplate()
- }
-
- fun remoteJdbcTemplate(jsonNode: JsonNode): NamedParameterJdbcTemplate {
- val type = jsonNode.get("type").textValue()
- val driverDB: String
-
- return when (type) {
- DBLibConstants.MARIA_DB -> {
- driverDB = DBLibConstants.DRIVER_MARIA_DB
- jdbcTemplate(jsonNode, driverDB)
- }
- DBLibConstants.MYSQL_DB -> {
- driverDB = DBLibConstants.DRIVER_MYSQL_DB
- jdbcTemplate(jsonNode, driverDB)
- }
- DBLibConstants.ORACLE_DB -> {
- driverDB = DBLibConstants.DRIVER_ORACLE_DB
- jdbcTemplate(jsonNode, driverDB)
- }
- DBLibConstants.POSTGRES_DB -> {
- driverDB = DBLibConstants.DRIVER_POSTGRES_DB
- jdbcTemplate(jsonNode, driverDB)
- }
- else -> {
- throw BluePrintProcessorException("Rest adaptor($type) is not supported")
- }
- }
- }
-
- fun jdbcTemplate(jsonNode: JsonNode, driver: String): NamedParameterJdbcTemplate {
- val dataSourceBuilder = DataSourceBuilder
- .create()
- .username(jsonNode.get("username").textValue())
- .password(jsonNode.get("password").textValue())
- .url(jsonNode.get("url").textValue())
- .driverClassName(driver)
- .build()
- return NamedParameterJdbcTemplate(dataSourceBuilder)
- }
-} \ 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/MariaDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt
new file mode 100644
index 000000000..c67fb3397
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2019 Bell Canada 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.BluePrintDBLibGenericService
+import org.onap.ccsdk.apps.blueprintsprocessor.db.MariaDataSourceProperties
+import org.slf4j.LoggerFactory
+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
+
+class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDataSourceProperties) : BluePrintDBLibGenericService {
+
+ override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate {
+ return mariaNamedParameterJdbcTemplate(mariaDataSource())
+ }
+
+ override fun query(sql: String, params: Map<String, Any>): List<Map<String, Any>> {
+ return mariaNamedParameterJdbcTemplate(mariaDataSource()).queryForList(sql, params)
+ }
+
+ override fun update(sql: String, params: Map<String, Any>): Int {
+ return mariaNamedParameterJdbcTemplate(mariaDataSource()).update(sql, params)
+ }
+
+ val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!!
+
+ fun mariaDataSource(): DataSource {
+ val dataSource = DriverManagerDataSource()
+ dataSource.setDriverClassName(mariaDataSourceProperties.driverClassName)
+ dataSource.url = mariaDataSourceProperties.url
+ dataSource.username = mariaDataSourceProperties.username
+ dataSource.password = mariaDataSourceProperties.password
+ return dataSource
+ }
+
+ fun mariaNamedParameterJdbcTemplate(mariaDataSource: DataSource): NamedParameterJdbcTemplate {
+ return NamedParameterJdbcTemplate(mariaDataSource)
+ }
+} \ 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/MySqlDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt
new file mode 100644
index 000000000..2a0dec73e
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2019 Bell Canada 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.BluePrintDBLibGenericService
+import org.onap.ccsdk.apps.blueprintsprocessor.db.MySqlDataSourceProperties
+import org.slf4j.LoggerFactory
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
+import org.springframework.jdbc.datasource.DriverManagerDataSource
+import javax.sql.DataSource
+
+class MySqlDatabaseConfiguration(private val mySqlDataSourceProperties: MySqlDataSourceProperties) : BluePrintDBLibGenericService {
+ override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate {
+ return mySqlNamedParameterJdbcTemplate(mySqlDataSource())
+ }
+
+ override fun query(sql: String, params: Map<String, Any>): List<Map<String, Any>> {
+ return mySqlNamedParameterJdbcTemplate(mySqlDataSource()).queryForList(sql, params)
+ }
+
+ override fun update(sql: String, params: Map<String, Any>): Int {
+ return mySqlNamedParameterJdbcTemplate(mySqlDataSource()).update(sql, params)
+ }
+
+ val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!!
+
+ fun mySqlDataSource(): DataSource {
+ val dataSource = DriverManagerDataSource()
+ dataSource.setDriverClassName(mySqlDataSourceProperties.driverClassName)
+ dataSource.url = mySqlDataSourceProperties.url
+ dataSource.username = mySqlDataSourceProperties.username
+ dataSource.password = mySqlDataSourceProperties.password
+ return dataSource
+ }
+
+ fun mySqlNamedParameterJdbcTemplate(mySqlDataSource: DataSource): NamedParameterJdbcTemplate {
+ return NamedParameterJdbcTemplate(mySqlDataSource)
+ }
+
+
+}
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt
new file mode 100644
index 000000000..5a9265348
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt
@@ -0,0 +1,27 @@
+/*
+ * 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.AbstractDBLibGenericService
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
+import org.springframework.stereotype.Service
+
+@Service
+open class PrimaryDBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate)
+ : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) {
+
+} \ No newline at end of file