summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/commons/db-lib
diff options
context:
space:
mode:
authorJozsef Csongvai <jozsef.csongvai@bell.ca>2020-04-16 08:33:36 -0400
committerJozsef Csongvai <jozsef.csongvai@bell.ca>2020-04-16 08:33:36 -0400
commit87bf1928aa4772c3b953a0a5800bec99f23b6e9c (patch)
tree5aabbe00a74577f7eb119b1a94c8de4e903ce263 /ms/blueprintsprocessor/modules/commons/db-lib
parent3a27f2fee05ef874181ea818f28329c2567e52c5 (diff)
Fix default behavior for DatabaseResourceAssignmentProcessor
If a data-dictionary did not declare an endpoint-selector, it would default to primary cds-db instead of using data-dictionary source to look up database configuration. Processor-db configurations were not used because of this. Also improved error messages and some refactoring. Issue-ID: CCSDK-2315 Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca> Change-Id: I7122e1334951db4eec5b9ae8b01c1f66596636f6
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/db-lib')
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt2
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt105
2 files changed, 37 insertions, 70 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
index 0d737f4ca..637031972 100644
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
@@ -66,7 +66,7 @@ class DBLibConstants {
// list of database
const val MARIA_DB: String = "maria-db"
- const val PRIMARY_DB: String = "processor-db"
+ const val PROCESSOR_DB: String = "processor-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/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
index 35baf9314..e686e8396 100644
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
@@ -20,10 +20,11 @@ import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService
import org.onap.ccsdk.cds.blueprintsprocessor.db.DBDataSourceProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.MARIA_DB
+import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.MYSQL_DB
+import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants.Companion.PROCESSOR_DB
import org.onap.ccsdk.cds.blueprintsprocessor.db.MariaDataSourceProperties
import org.onap.ccsdk.cds.blueprintsprocessor.db.MySqlDataSourceProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.springframework.stereotype.Service
@@ -31,79 +32,45 @@ import org.springframework.stereotype.Service
@Service
class BluePrintDBLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) {
- fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService {
- val dBConnetionProperties = dBDataSourceProperties(jsonNode)
- return blueprintDBDataSourceService(dBConnetionProperties)
- }
+ fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService =
+ blueprintDBDataSourceService(dBDataSourceProperties(jsonNode))
- fun JdbcTemplate(selector: String): BluePrintDBLibGenericService {
- val prefix = "blueprintsprocessor.db.$selector"
- val dBConnetionProperties = dBDataSourceProperties(prefix)
- return blueprintDBDataSourceService(dBConnetionProperties)
- }
+ fun JdbcTemplate(selector: String): BluePrintDBLibGenericService =
+ blueprintDBDataSourceService(dBDataSourceProperties("blueprintsprocessor.db.$selector"))
- 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(jsonNode: JsonNode): DBDataSourceProperties =
+ when (val type = jsonNode.get("type").textValue()) {
+ MYSQL_DB -> JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)
+ MARIA_DB -> JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)
+ else -> {
+ throw BluePrintProcessorException(
+ "DB type ($type) is not supported. Valid types: $MARIA_DB, $MYSQL_DB")
+ }
+ }!!
- private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties {
- val type = bluePrintPropertiesService.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")
+ private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties =
+ bluePrintPropertiesService.propertyBeanType("$prefix.type", String::class.java).let {
+ return when (it) {
+ MARIA_DB, PROCESSOR_DB -> mariaDBConnectionProperties(prefix)
+ MYSQL_DB -> mySqlDBConnectionProperties(prefix)
+ else -> {
+ throw BluePrintProcessorException(
+ "DB type ($it) is not supported. Valid types: $MARIA_DB, $MYSQL_DB, $PROCESSOR_DB")
+ }
+ }
}
- 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)
+ private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService =
+ when (dBConnetionProperties) {
+ is MariaDataSourceProperties -> MariaDatabaseConfiguration(dBConnetionProperties)
+ is MySqlDataSourceProperties -> MySqlDatabaseConfiguration(dBConnetionProperties)
+ else -> throw BluePrintProcessorException(
+ "Failed to create db configuration for ${dBConnetionProperties.url}")
}
- else -> {
- throw BluePrintProcessorException("couldn't get rest service for")
- }
- }
- }
-
- private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties {
- return bluePrintPropertiesService.propertyBeanType(prefix, MySqlDataSourceProperties::class.java)
- }
- private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties {
- return bluePrintPropertiesService.propertyBeanType(prefix, MariaDataSourceProperties::class.java)
- }
+ private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties =
+ bluePrintPropertiesService.propertyBeanType(prefix, MySqlDataSourceProperties::class.java)
- private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties {
- return bluePrintPropertiesService.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java)
- }
+ private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties =
+ bluePrintPropertiesService.propertyBeanType(prefix, MariaDataSourceProperties::class.java)
}