summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-03-22 16:06:26 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-22 16:06:26 +0000
commit7aa46ace9b3b47b1c03debefdbc68ccf954537fd (patch)
tree583f2e17e4acb78a4ffc8c3bc0912f292d4cd430 /ms/blueprintsprocessor/functions
parent49fc96a20d98a32e5bfbf88bf3595d09e419c7bd (diff)
parent12e91a2cad984eb491a3083139db80b10d544f30 (diff)
Merge "Ressource resolution using configurable database"
Diffstat (limited to 'ms/blueprintsprocessor/functions')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt105
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt3
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt11
3 files changed, 64 insertions, 55 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
index e38a1cca..a192989e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -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)
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 b3e3e4ed..91997e34 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,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"])
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 905c8e0b..d560e8c3 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,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")
}