summaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-03-06 21:03:25 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-06 21:03:25 +0000
commit62919a6dfa67efce97c09325b2f75a33f3bc4518 (patch)
treed4981b77ced1c64f3fabb373c959cd615f37de95 /ms
parent5fb3b435cae97ebe1d2766a515edda016b246f64 (diff)
parent4a53e10178116152fd5f945d0a544775f5ab2cb1 (diff)
Merge "Ressource resolution using configurable database"
Diffstat (limited to 'ms')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt (renamed from ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceResolutionProcessor.kt)83
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt3
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt6
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt6
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties7
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json1
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt14
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt72
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt28
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt17
10 files changed, 145 insertions, 92 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
index 3922c376..8f0f626c 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -18,35 +18,31 @@
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)
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
index ed6b09fc..66519f93 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
@@ -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)
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
index c3b10184..b3e3e4ed 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
@@ -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"])
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
index 6d2d3f2d..fcf8f46c 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
@@ -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"])
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties
index e2785c8a..3f37d1b9 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties
@@ -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
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
index c4fe4eab..6a7b4c2a 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
@@ -19,6 +19,7 @@
"resource-assignment-request": {
"resource-assignment-properties": {
"request-id": "1234",
+ "profile_name": "1.0.0",
"service-instance-id": "siid_1234",
"vnf-id": "vnf_1234",
"action-name": "assign-activate",
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
index 0bdee9be..276ece13 100644
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
@@ -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
index 00000000..af7ab054
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt
@@ -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
index 0e0f1e9c..00000000
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt
+++ /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
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
index fa5e1647..c34a769e 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
@@ -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
}