diff options
author | Jozsef Csongvai <jozsef.csongvai@bell.ca> | 2020-04-16 08:33:36 -0400 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2020-04-20 12:33:20 +0000 |
commit | 508c39cfc1473f081bfad0dbe438d50a5eda1e86 (patch) | |
tree | 3a9a1c5cf5e119f940805f2a5b62e4457058e1ee /ms/blueprintsprocessor | |
parent | 1b8d78599d5919825fca2cb314ec28a7573b3a67 (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
(cherry picked from commit 87bf1928aa4772c3b953a0a5800bec99f23b6e9c)
Diffstat (limited to 'ms/blueprintsprocessor')
3 files changed, 40 insertions, 73 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt index a0fa97b6d..2640b5b85 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt @@ -107,7 +107,7 @@ open class DatabaseResourceAssignmentProcessor( "DatabaseResource ($dSource) dictionary information: " + "Query:($sql), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})" ) - val jdbcTemplate = blueprintDBLibService(sourceProperties) + val jdbcTemplate = blueprintDBLibService(sourceProperties, dSource) val rows = jdbcTemplate.query(sql, populateNamedParameter(inputKeyMapping)) if (rows.isNullOrEmpty()) { @@ -117,12 +117,12 @@ open class DatabaseResourceAssignmentProcessor( } } - private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): BluePrintDBLibGenericService { + private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource, selector: String): BluePrintDBLibGenericService { return if (isNotEmpty(sourceProperties.endpointSelector)) { val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!) bluePrintDBLibPropertyService.JdbcTemplate(dbPropertiesJson) } else { - primaryDBLibGenericService + bluePrintDBLibPropertyService.JdbcTemplate(selector) } } 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) } |