Ressource resolution using configurable database 78/78878/11
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>
Wed, 6 Mar 2019 19:22:36 +0000 (14:22 -0500)
Change-Id: I8589e4db45ba3d5bcb906f25bcc76b5136159608
Issue-ID: CCSDK-1092
Signed-off-by: vinal patel <vinal.narendrabhai.patel@ibm.com>
15 files changed:
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Environments/source-db.properties [new file with mode: 0644]
components/model-catalog/resource-dictionary/starter-dictionary/service-instance-id.json
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt [moved from ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceResolutionProcessor.kt with 68% similarity]
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.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/functions/resource-resolution/src/test/resources/application-test.properties
ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
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/primary/DBLibGenericService.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt [deleted file]
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt

index 138260f..6025dbd 100644 (file)
       "userId" : {
         "get_input": "rest-user-name"
       }
+    },
+    "dynamic-db-source": {
+      "type" : "maria-db",
+      "url" : "jdbc:mysql://localhost:3306/sdnctl",
+      "username" : "sdnctl",
+      "password" : {
+        "get_attribute": [
+          "BPP",
+          "dynamic-db-source.password"
+        ]
+      }
     }
   },
   "topology_template": {
index ace1a94..eaf45b3 100644 (file)
       "input": {
         "type": "source-input",
         "properties": {}
+      },
+      "primary-db": {
+        "type": "source-primary-db",
+        "properties": {
+          "endpoint-selector": "dynamic-db-source",
+          "query": "SELECT artifact_name FROM sdnctl.BLUEPRINT_RUNTIME where artifact_version=\"1.0.0\"",
+          "input-key-mapping": {
+          },
+          "output-key-mapping": {
+            "service-instance-id": "artifact_name"
+          },
+          "key-dependencies" : []
+        }
       }
     }
   },
diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Environments/source-db.properties b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Environments/source-db.properties
new file mode 100644 (file)
index 0000000..49a7eb4
--- /dev/null
@@ -0,0 +1 @@
+dynamic-db-source.password=sdnctl
\ No newline at end of file
index 37b9868..cb97043 100755 (executable)
     "input" : {
       "type" : "source-input",
       "properties" : { }
+    },
+    "any-db": {
+      "type": "source-primary-db",
+      "properties": {
+        "query": "SELECT artifact_name FROM BLUEPRINT_RUNTIME where artifact_version=\"1.0.0\"",
+        "input-key-mapping": {
+        },
+        "output-key-mapping": {
+          "service-instance-id": "artifact_name"
+        }
+      }
+    },
+    "primary-db": {
+      "type": "source-primary-db",
+      "properties": {
+        "query": "SELECT artifact_name FROM BLUEPRINT_RUNTIME where artifact_version=\"1.0.0\"",
+        "input-key-mapping": {
+        },
+        "output-key-mapping": {
+          "service-instance-id": "artifact_name"
+        }
+      }
     }
   }
 }
\ No newline at end of file
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
 import com.fasterxml.jackson.databind.node.JsonNodeFactory
-import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.PrimaryDBLibGenericService
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource
 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.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.*
 
 /**
- * PrimaryDataResourceResolutionProcessor
+ * DatabaseResourceAssignmentProcessor
  *
  * @author Kapil Singal
  */
 @Service("rr-processor-source-primary-db")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class PrimaryDataResourceResolutionProcessor(private val primaryDBLibGenericService: PrimaryDBLibGenericService)
+open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService: DBLibGenericService)
     : ResourceAssignmentProcessor() {
 
-    private val logger = LoggerFactory.getLogger(PrimaryDataResourceResolutionProcessor::class.java)
+    private val logger = LoggerFactory.getLogger(DatabaseResourceAssignmentProcessor::class.java)
 
     override fun getName(): String {
         return "rr-processor-source-primary-db"
@@ -62,26 +58,22 @@ open class PrimaryDataResourceResolutionProcessor(private val primaryDBLibGeneri
                 logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)")
                 ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
             } catch (e: BluePrintProcessorException) {
-                // Else, get from DB
                 val dName = resourceAssignment.dictionaryName
                 val dSource = resourceAssignment.dictionarySource
                 val resourceDefinition = resourceDictionaries[dName]
-                    ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $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)
+                        ?: 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 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 = primaryDBLibGenericService.query(sql, populateNamedParameter(inputKeyMapping))
+                val rows = jdbcTemplate.queryForList(sql, populateNamedParameter(inputKeyMapping))
                 if (rows.isNullOrEmpty()) {
                     logger.warn("Failed to get $dSource result for dictionary name ($dName) the query ($sql)")
                 } else {
@@ -93,16 +85,24 @@ open class PrimaryDataResourceResolutionProcessor(private val primaryDBLibGeneri
             ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
         } catch (e: Exception) {
             ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
-            throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}",
-                e)
+            throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e)
         }
     }
 
+    private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): NamedParameterJdbcTemplate {
+        return if (checkNotEmpty(sourceProperties.endpointSelector!!)) {
+            val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!)
+            dBLibGenericService.remoteJdbcTemplate(dbPropertiesJson)
+        } else {
+            dBLibGenericService.primaryJdbcTemplate()
+        }
+
+    }
+
     @Throws(BluePrintProcessorException::class)
     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})")
+        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}"
         }
@@ -111,35 +111,32 @@ open class PrimaryDataResourceResolutionProcessor(private val primaryDBLibGeneri
     private fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> {
         val namedParameters = HashMap<String, Any>()
         inputKeyMapping.forEach {
-            val expressionValue = raRuntimeService.getDictionaryStore(it.value)
+            val expressionValue = raRuntimeService.getDictionaryStore(it.value).textValue()
             logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)")
-            namedParameters[it.key] = expressionValue.asText()
+            namedParameters[it.key] = expressionValue
         }
         logger.info("Parameter information : ({})", namedParameters)
         return namedParameters
     }
 
     @Throws(BluePrintProcessorException::class)
-    private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: DatabaseResourceSource,
-                                 rows: List<Map<String, Any>>) {
+    private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: DatabaseResourceSource, rows: List<Map<String, Any>>) {
         val dName = resourceAssignment.dictionaryName
         val dSource = resourceAssignment.dictionarySource
         val type = nullToEmpty(resourceAssignment.property?.type)
 
-        val outputKeyMapping =
-            checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" }
+        val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" }
         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)")
                 ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, dbColumnValue)
             }
             in BluePrintTypes.validCollectionTypes() -> {
-                val entrySchemaType =
-                    returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+                val entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
                 var arrayNode = JsonNodeFactory.instance.arrayNode()
                 rows.forEach {
                     if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) {
@@ -150,12 +147,8 @@ open class PrimaryDataResourceResolutionProcessor(private val primaryDBLibGeneri
                         val arrayChildNode = JsonNodeFactory.instance.objectNode()
                         for (mapping in outputKeyMapping.entries) {
                             val dbColumnValue = checkNotNull(it[mapping.key])
-                            val propertyTypeForDataType =
-                                ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, mapping.key)
-                            JacksonUtils.populatePrimitiveValues(mapping.key,
-                                dbColumnValue,
-                                propertyTypeForDataType,
-                                arrayChildNode)
+                            val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, mapping.key)
+                            JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, arrayChildNode)
                         }
                         arrayNode.add(arrayChildNode)
                     }
@@ -170,12 +163,8 @@ open class PrimaryDataResourceResolutionProcessor(private val primaryDBLibGeneri
                 var objectNode = JsonNodeFactory.instance.objectNode()
                 for (mapping in outputKeyMapping.entries) {
                     val dbColumnValue = checkNotNull(row[mapping.key])
-                    val propertyTypeForDataType =
-                        ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key)
-                    JacksonUtils.populatePrimitiveValues(mapping.key,
-                        dbColumnValue,
-                        propertyTypeForDataType,
-                        objectNode)
+                    val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key)
+                    JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, objectNode)
                 }
                 logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)")
                 ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode)
index ed6b09f..66519f9 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
+import com.fasterxml.jackson.databind.node.MissingNode
 import com.fasterxml.jackson.databind.node.NullNode
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
@@ -47,7 +48,7 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
             if (checkNotEmpty(resourceAssignment.name)) {
                 val value = raRuntimeService.getInputValue(resourceAssignment.name)
                 // if value is null don't call setResourceDataValue to populate the value
-                if (value != null && value !is NullNode) {
+                if (value !is MissingNode && value !is NullNode) {
                     logger.info("input source template key (${resourceAssignment.name}) found from input and value is ($value)")
                     ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
                 }
index 4daa46e..e42d708 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
-import com.fasterxml.jackson.databind.node.ArrayNode
-import com.fasterxml.jackson.databind.node.JsonNodeFactory
-import com.fasterxml.jackson.databind.node.NullNode
-import com.fasterxml.jackson.databind.node.ObjectNode
+import com.fasterxml.jackson.databind.node.*
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.RestResourceSource
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
@@ -56,7 +53,7 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
 
             // Check if It has Input
             val value = raRuntimeService.getInputValue(resourceAssignment.name)
-            if (value != null && value !is NullNode) {
+            if (value !is MissingNode && value !is NullNode) {
                 logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)")
                 ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
             } else {
index c3b1018..b3e3e4e 100644 (file)
@@ -25,7 +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.PrimaryDBLibGenericService
+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
@@ -43,8 +43,8 @@ import org.springframework.test.context.junit4.SpringRunner
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
-    PrimaryDataResourceResolutionProcessor::class, RestResourceResolutionProcessor::class,
-    CapabilityResourceResolutionProcessor::class, PrimaryDBLibGenericService::class,
+    DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
+    CapabilityResourceResolutionProcessor::class, DBLibGenericService::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
index 6d2d3f2..fcf8f46 100644 (file)
@@ -25,7 +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.PrimaryDBLibGenericService
+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.config.BluePrintLoadConfiguration
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
@@ -48,8 +48,8 @@ import kotlin.test.assertTrue
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
-    PrimaryDataResourceResolutionProcessor::class, RestResourceResolutionProcessor::class,
-    CapabilityResourceResolutionProcessor::class, PrimaryDBLibGenericService::class,
+    DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
+    CapabilityResourceResolutionProcessor::class, DBLibGenericService::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
index e2785c8..3f37d1b 100644 (file)
@@ -35,4 +35,9 @@ blueprintsprocessor.restclient.primary-config-data.token=sampletoken
 
 # Python executor
 blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
-blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
\ No newline at end of file
+blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
+
+
+# CBA examples for tests cases
+controllerblueprints.loadBlueprintsExamplesPath=./../../../../components/model-catalog/blueprint-model/test-blueprint
+controllerblueprints.loadBluePrintPaths=./../../../../components/model-catalog/blueprint-model/test-blueprint
\ No newline at end of file
index c4fe4ea..6a7b4c2 100644 (file)
@@ -19,6 +19,7 @@
     "resource-assignment-request": {\r
       "resource-assignment-properties": {\r
         "request-id": "1234",\r
+        "profile_name": "1.0.0",\r
         "service-instance-id": "siid_1234",\r
         "vnf-id": "vnf_1234",\r
         "action-name": "assign-activate",\r
index 0bdee9b..276ece1 100644 (file)
@@ -37,5 +37,19 @@ open class BluePrintDBLibConfiguration(private var bluePrintProperties: BluePrin
 class DBLibConstants {
     companion object {
         const val PREFIX_DB_PRIMARY: String = "blueprintsprocessor.db.primary"
+
+        //list of database
+        const val MARIA_DB: String = "maria-db"
+        const val MYSQL_DB: String = "mysql-db"
+        const val ORACLE_DB: String = "oracle-db"
+        const val POSTGRES_DB: String = "postgres-db"
+
+        //List of database drivers
+        const val DRIVER_MARIA_DB = "org.mariadb.jdbc.Driver"
+        const val DRIVER_MYSQL_DB = "com.mysql.jdbc.Driver"
+        const val DRIVER_ORACLE_DB = "oracle.jdbc.driver.OracleDriver"
+        const val DRIVER_POSTGRES_DB = "org.postgresql.Driver"
+
+
     }
 }
\ 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
new file mode 100644 (file)
index 0000000..af7ab05
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt
deleted file mode 100644 (file)
index 0e0f1e9..0000000
+++ /dev/null
@@ -1,28 +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 org.onap.ccsdk.apps.blueprintsprocessor.db.AbstractDBLibGenericService
-import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
-import org.springframework.stereotype.Service
-
-@Service
-open class PrimaryDBLibGenericService(private val primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate)
-    : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) {
-
-}
\ No newline at end of file
index fa5e164..c34a769 100644 (file)
@@ -97,12 +97,9 @@ class BluePrintMetadataUtils {
 
             val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
 
-            val context: MutableMap<String, JsonNode> = hashMapOf()
-            context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()
-            context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()
-
             val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
-            bluePrintRuntimeService.setExecutionContext(context)
+            bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH, blueprintBasePath.asJsonPrimitive())
+            bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive())
 
             return bluePrintRuntimeService
         }
@@ -110,12 +107,10 @@ class BluePrintMetadataUtils {
         fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
 
             val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath)
-            val context: MutableMap<String, JsonNode> = hashMapOf()
-            context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive()
-            context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive()
 
             val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
-            bluePrintRuntimeService.setExecutionContext(context)
+            bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH, blueprintBasePath.asJsonPrimitive())
+            bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive())
 
             return bluePrintRuntimeService
         }
@@ -123,6 +118,10 @@ class BluePrintMetadataUtils {
         fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
             val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
             val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
+            executionContext.forEach{
+                bluePrintRuntimeService.put(it.key,it.value)
+            }
+
             bluePrintRuntimeService.setExecutionContext(executionContext)
             return bluePrintRuntimeService
         }