summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
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
commit68d8bda8229f89c9d120489baa7b1b228e0340fb (patch)
tree541878170b73f9adcf5fb2ea0a4aa0c5c46f7773 /ms/blueprintsprocessor/functions
parent71f072fe0759de0dedc3cfcdfeb245d25a08dc22 (diff)
parenta05206ba8a23eb4fbd6ae5cff382c583219887d5 (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.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
6 files changed, 51 insertions, 55 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 3922c3760..8f0f626cd 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 ed6b09fcd..66519f93d 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 c3b101840..b3e3e4ed3 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 6d2d3f2df..fcf8f46c8 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 e2785c8a3..3f37d1b9e 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 c4fe4eab5..6a7b4c2a2 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",