Ressource resolution using configurable database 14/79914/7
authorvinal patel <vinal.narendrabhai.patel@ibm.com>
Wed, 20 Feb 2019 21:02:44 +0000 (16:02 -0500)
committervinal patel <vinal.narendrabhai.patel@ibm.com>
Mon, 18 Mar 2019 21:24:27 +0000 (17:24 -0400)
Change-Id: I40338a221884d6f4df4c8a7dc3dac1f58f142074
Issue-ID: CCSDK-1092
Signed-off-by: vinal patel <vinal.narendrabhai.patel@ibm.com>
24 files changed:
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/node_types.json
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json
components/model-catalog/blueprint-model/test-blueprint/golden/Definitions/node_types.json
components/model-catalog/blueprint-model/test-blueprint/golden/Definitions/resources_definition_types.json
components/model-catalog/blueprint-model/test-blueprint/golden/Templates/vf-module-1-mapping.json
components/model-catalog/blueprint-model/test-blueprint/golden/Templates/vfw-interface-mapping.json
components/model-catalog/definition-type/starter-type/node_type/source-processor-db.json [new file with mode: 0644]
components/model-catalog/resource-dictionary/test-dictionary/vf-module-type.json
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt [deleted file]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt [new file with mode: 0644]
ms/controllerblueprints/application/src/main/resources/application-dev.properties
ms/controllerblueprints/application/src/main/resources/application.properties
ms/controllerblueprints/application/src/test/resources/application.properties
ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt
ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java
ms/controllerblueprints/modules/service/src/test/resources/application.properties

index 8f6c44f..68a8ae6 100644 (file)
       },
       "derived_from": "tosca.nodes.ResourceSource"
     },
-    "source-primary-db": {
+    "source-processor-db": {
       "description": "This is Database Resource Source Node Type",
       "version": "1.0.0",
       "properties": {
index eaf45b3..6e3d5e9 100644 (file)
@@ -26,8 +26,8 @@
         "type": "source-input",
         "properties": {}
       },
-      "primary-db": {
-        "type": "source-primary-db",
+      "processor-db": {
+        "type": "source-processor-db",
         "properties": {
           "endpoint-selector": "dynamic-db-source",
           "query": "SELECT artifact_name FROM sdnctl.BLUEPRINT_RUNTIME where artifact_version=\"1.0.0\"",
index b058692..f143e56 100644 (file)
       },
       "derived_from" : "tosca.nodes.ResourceSource"
     },
-    "source-primary-db" : {
+    "source-processor-db" : {
       "description" : "This is Database Resource Source Node Type",
       "version" : "1.0.0",
       "properties" : {
index 446a8a6..15f02a1 100644 (file)
     },
     "updated-by" : "adetalhouet",
     "sources" : {
-      "primary-db" : {
-        "type" : "source-primary-db",
+      "processor-db" : {
+        "type" : "source-processor-db",
         "properties" : {
           "type" : "SQL",
           "query" : "select sdnctl.demo.value as value from sdnctl.demo where sdnctl.demo.id=:vfmoduleid",
index eba259e..b7335b5 100644 (file)
@@ -18,7 +18,7 @@
       "type": "string"
     },
     "dictionary-name": "vf-module-type",
-    "dictionary-source": "primary-db",
+    "dictionary-source": "processor-db",
     "dependencies": [
       "vf-module-number"
     ]
index 149d3eb..c1ebe56 100644 (file)
@@ -55,7 +55,7 @@
       "type": "string"
     },
     "dictionary-name": "vf-module-type",
-    "dictionary-source": "primary-db",
+    "dictionary-source": "processor-db",
     "dependencies": [
       "vf-module-number"
     ]
diff --git a/components/model-catalog/definition-type/starter-type/node_type/source-processor-db.json b/components/model-catalog/definition-type/starter-type/node_type/source-processor-db.json
new file mode 100644 (file)
index 0000000..702748f
--- /dev/null
@@ -0,0 +1,48 @@
+{
+  "description": "This is Database Resource Source Node Type",
+  "version": "1.0.0",
+  "properties": {
+    "type": {
+      "required": true,
+      "type": "string",
+      "constraints": [
+        {
+          "valid_values": [
+            "SQL",
+            "PLSQL"
+          ]
+        }
+      ]
+    },
+    "endpoint-selector": {
+      "required": false,
+      "type": "string"
+    },
+    "query": {
+      "required": true,
+      "type": "string"
+    },
+    "input-key-mapping": {
+      "required": false,
+      "type": "map",
+      "entry_schema": {
+        "type": "string"
+      }
+    },
+    "output-key-mapping": {
+      "required": false,
+      "type": "map",
+      "entry_schema": {
+        "type": "string"
+      }
+    },
+    "key-dependencies": {
+      "required": true,
+      "type": "list",
+      "entry_schema": {
+        "type": "string"
+      }
+    }
+  },
+  "derived_from": "tosca.nodes.ResourceSource"
+}
\ No newline at end of file
index b06057c..9e8c409 100644 (file)
@@ -7,8 +7,8 @@
   },
   "updated-by": "adetalhouet",
   "sources": {
-    "primary-db": {
-      "type": "source-primary-db",
+    "processor-db": {
+      "type": "source-processor-db",
       "properties": {
         "type": "SQL",
         "query": "select sdnctl.demo.value as value from sdnctl.demo where sdnctl.demo.id=:vfmoduleid",
index e38a1cc..a192989 100644 (file)
@@ -19,40 +19,37 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr
 
 import com.fasterxml.jackson.databind.node.JsonNodeFactory
 import com.fasterxml.jackson.databind.node.MissingNode
-import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService
+import com.fasterxml.jackson.databind.node.NullNode
+import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.PrimaryDBLibGenericService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.apps.controllerblueprints.core.checkEqualsOrThrow
-import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty
-import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
-import org.onap.ccsdk.apps.controllerblueprints.core.nullToEmpty
-import org.onap.ccsdk.apps.controllerblueprints.core.returnNotEmptyOrThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.*
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
 import org.springframework.stereotype.Service
+import java.util.*
 
 /**
  * DatabaseResourceAssignmentProcessor
  *
  * @author Kapil Singal
  */
-@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-primary-db")
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService: DBLibGenericService)
+open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropertySevice: BluePrintDBLibPropertySevice, private val primaryDBLibGenericService: PrimaryDBLibGenericService)
     : ResourceAssignmentProcessor() {
 
     private val logger = LoggerFactory.getLogger(DatabaseResourceAssignmentProcessor::class.java)
 
     override fun getName(): String {
-        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-primary-db"
+        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
@@ -60,33 +57,16 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
             validate(resourceAssignment)
 
             // Check if It has Input
-            val value = getFromInput(resourceAssignment)
-            if (value == null || value is MissingNode) {
-                val dName = resourceAssignment.dictionaryName
-                val dSource = resourceAssignment.dictionarySource
-                val resourceDefinition = resourceDictionaries[dName]
-                        ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
-                val resourceSource = resourceDefinition.sources[dSource]
-                        ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
-                val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
-                val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java)
-
-                val sql = checkNotNull(sourceProperties.query) { "failed to get request query for $dName under $dSource properties" }
-                val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
-
-                val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping)
-
-                val resolvedSql = resolveFromInputKeyMapping(sql, resolvedInputKeyMapping)
-
-                logger.info("$dSource dictionary information : ($resolvedSql), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
-                val jdbcTemplate = blueprintDBLibService(sourceProperties)
-
-                val rows = jdbcTemplate.queryForList(resolvedSql, resolvedInputKeyMapping)
-                if (rows.isNullOrEmpty()) {
-                    logger.warn("Failed to get $dSource result for dictionary name ($dName) the query ($resolvedSql)")
+            try {
+                val value = raRuntimeService.getInputValue(resourceAssignment.name)
+                if (value !is NullNode && value !is MissingNode) {
+                    logger.info("processor-db source template key (${resourceAssignment.name}) found from input and value is ($value)")
+                    ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
                 } else {
-                    populateResource(resourceAssignment, sourceProperties, rows)
+                    setValueFromDB(resourceAssignment)
                 }
+            } catch (e: BluePrintProcessorException) {
+                setValueFromDB(resourceAssignment)
             }
 
             // Check the value has populated for mandatory case
@@ -97,12 +77,36 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
         }
     }
 
-    private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): NamedParameterJdbcTemplate {
+    private fun setValueFromDB(resourceAssignment: ResourceAssignment) {
+        val dName = resourceAssignment.dictionaryName
+        val dSource = resourceAssignment.dictionarySource
+        val resourceDefinition = resourceDictionaries[dName]
+                ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
+        val resourceSource = resourceDefinition.sources[dSource]
+                ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+        val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
+        val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java)
+
+        val sql = checkNotNull(sourceProperties.query) { "failed to get request query for $dName under $dSource properties" }
+        val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
+
+        logger.info("$dSource dictionary information : ($sql), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
+        val jdbcTemplate = blueprintDBLibService(sourceProperties)
+
+        val rows = jdbcTemplate.query(sql, populateNamedParameter(inputKeyMapping))
+        if (rows.isNullOrEmpty()) {
+            logger.warn("Failed to get $dSource result for dictionary name ($dName) the query ($sql)")
+        } else {
+            populateResource(resourceAssignment, sourceProperties, rows)
+        }
+    }
+
+    private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): BluePrintDBLibGenericService {
         return if (checkNotEmpty(sourceProperties.endpointSelector)) {
             val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!)
-            dBLibGenericService.remoteJdbcTemplate(dbPropertiesJson)
+            bluePrintDBLibPropertySevice.JdbcTemplate(dbPropertiesJson)
         } else {
-            dBLibGenericService.primaryJdbcTemplate()
+            primaryDBLibGenericService
         }
 
     }
@@ -111,9 +115,20 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
     private fun validate(resourceAssignment: ResourceAssignment) {
         checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined")
         checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
-        checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.dictionarySource) {
-            "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_DB} but it is ${resourceAssignment.dictionarySource}"
+        checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.dictionarySource) {
+            "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PROCESSOR_DB} but it is ${resourceAssignment.dictionarySource}"
+        }
+    }
+
+    private fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> {
+        val namedParameters = HashMap<String, Any>()
+        inputKeyMapping.forEach {
+            val expressionValue = raRuntimeService.getDictionaryStore(it.value).textValue()
+            logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)")
+            namedParameters[it.key] = expressionValue
         }
+        logger.info("Parameter information : ({})", namedParameters)
+        return namedParameters
     }
 
     @Throws(BluePrintProcessorException::class)
@@ -126,7 +141,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
         logger.info("Response processing type($type)")
 
         // Primitive Types
-        when(type) {
+        when (type) {
             in BluePrintTypes.validPrimitiveTypes() -> {
                 val dbColumnValue = rows[0][outputKeyMapping[dName]]
                 logger.info("For template key (${resourceAssignment.name}) setting value as ($dbColumnValue)")
@@ -134,7 +149,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
             }
             in BluePrintTypes.validCollectionTypes() -> {
                 val entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
-                var arrayNode = JsonNodeFactory.instance.arrayNode()
+                val arrayNode = JsonNodeFactory.instance.arrayNode()
                 rows.forEach {
                     if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) {
                         val dbColumnValue = it[outputKeyMapping[dName]]
@@ -157,7 +172,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
             else -> {
                 // Complex Types
                 val row = rows[0]
-                var objectNode = JsonNodeFactory.instance.objectNode()
+                val objectNode = JsonNodeFactory.instance.objectNode()
                 for (mapping in outputKeyMapping.entries) {
                     val dbColumnValue = checkNotNull(row[mapping.key])
                     val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key)
index b3e3e4e..91997e3 100644 (file)
@@ -25,7 +25,6 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfigurati
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration
-import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.*
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
@@ -44,7 +43,7 @@ import org.springframework.test.context.junit4.SpringRunner
 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
     DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
-    CapabilityResourceResolutionProcessor::class, DBLibGenericService::class,
+    CapabilityResourceResolutionProcessor::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
index 905c8e0..d560e8c 100644 (file)
@@ -25,12 +25,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfigurati
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration
-import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.CapabilityResourceResolutionProcessor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.DatabaseResourceAssignmentProcessor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.DefaultResourceResolutionProcessor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.InputResourceResolutionProcessor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.RestResourceResolutionProcessor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.*
 import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
@@ -53,7 +48,7 @@ import kotlin.test.assertTrue
 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
     DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
-    CapabilityResourceResolutionProcessor::class, DBLibGenericService::class,
+    CapabilityResourceResolutionProcessor::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
@@ -70,7 +65,7 @@ class ResourceResolutionServiceTest {
     fun testRegisteredSource() {
         val sources = resourceResolutionService.registeredResourceSources()
         assertNotNull(sources, "failed to get registered sources")
-        assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-primary-db",
+        assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
                 "source-rest")), "failed to get registered sources : $sources")
     }
 
index 276ece1..3e9ec0c 100644 (file)
@@ -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"
index a16e556..ab2c19a 100644 (file)
 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 (file)
index 0000000..f93c241
--- /dev/null
@@ -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 (file)
index af7ab05..0000000
+++ /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 (file)
index 0000000..c67fb33
--- /dev/null
@@ -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 (file)
index 0000000..2a0dec7
--- /dev/null
@@ -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 (file)
index 0000000..5a92653
--- /dev/null
@@ -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
index 1c9029d..3401ece 100755 (executable)
@@ -49,7 +49,7 @@ spring.jpa.hibernate.ddl-auto=none
 spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
 # Load Resource Source Mappings
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
+resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=/etc/blueprints/deploy
 controllerblueprints.blueprintArchivePath=/etc/blueprints/archive
index 0340938..8789c24 100755 (executable)
@@ -52,7 +52,7 @@ spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
 
 # Load Resource Source Mappings
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
+resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=/etc/blueprints/deploy
index e0369ae..8ad9f2c 100755 (executable)
@@ -33,7 +33,7 @@ swagger.contact.url=www.onap.com
 swagger.contact.email=brindasanth@onap.com\r
 \r
 # Load Resource Source Mappings\r
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability\r
+resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability\r
 \r
 # Controller Blueprints Core Configuration\r
 controllerblueprints.blueprintDeployPath=./target/blueprints/deploy\r
index d33a2f0..7536868 100644 (file)
@@ -24,6 +24,8 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict
 object ResourceDictionaryConstants {
     const val SOURCE_INPUT = "input"
     const val SOURCE_DEFAULT = "default"
+    //const val SOURCE_PRIMARY_CONFIG_DATA = "rest"
+    const val SOURCE_PROCESSOR_DB = "processor-db"
     const val SOURCE_PRIMARY_CONFIG_DATA = "primary-config-data"
     const val SOURCE_PRIMARY_DB = "primary-db"
 
index e4ddac1..45fc739 100644 (file)
@@ -59,9 +59,9 @@ public class ResourceDictionaryUtilsTest {
         Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource());
 
         // To Check Assigned Source
-        resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PRIMARY_DB);
+        resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB);
         ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
-        Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.getDictionarySource());
+        Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.getDictionarySource());
 
     }
 
@@ -78,7 +78,7 @@ public class ResourceDictionaryUtilsTest {
         Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource);
 
         // TO check the multiple Source
-        sources.put(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, new NodeTemplate());
+        sources.put(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, new NodeTemplate());
         String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources);
         Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource);
 
index 20450f4..011bad3 100755 (executable)
@@ -20,7 +20,7 @@ logging.level.org.springframework.web=INFO
 logging.level.org.hibernate.SQL=warn
 logging.level.org.hibernate.type.descriptor.sql=debug
 # Load Resource Source Mappings
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
+resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=./target/blueprints/deploy
 controllerblueprints.blueprintArchivePath=./target/blueprints/archive