aboutsummaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2019-09-19 16:58:46 -0400
committerKAPIL SINGAL <ks220y@att.com>2019-09-19 22:43:33 +0000
commite4a0eef7b713551e075f71b00ff20f2448492c59 (patch)
treeb9ce244e0d6c8e581503e7119c1d978c0a02ce8b /ms
parentfb1b08d5dd94998f4b279a65b9a74604d80ee691 (diff)
Refactoring Resource Resolution Component
Use Case: ---------- Input Value (IV): It can be API Input Value or API Default value If a Resource is marked as Input -> pick IV If a Resource is marked as other than Input -> pick IV -> if IV is not present then resolve it as per DataDictionary Definition ** Return Error if Resource is not resolved using assert : ResourceAssignmentUtils.assertTemplateKeyValueNotNull Issue-ID: CCSDK-1746 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com> Change-Id: Ia3aaaa36d0e32b0b468f016d57ed5d2c4ddf6a32
Diffstat (limited to 'ms')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt72
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt44
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt9
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt9
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt19
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt50
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt281
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt21
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt44
9 files changed, 310 insertions, 239 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
index 0ea71ece7..9867cd658 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
@@ -32,8 +32,8 @@ import org.springframework.stereotype.Service
@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class CapabilityResourceResolutionProcessor(private var componentFunctionScriptingService: ComponentFunctionScriptingService)
- : ResourceAssignmentProcessor() {
+open class CapabilityResourceResolutionProcessor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
+ ResourceAssignmentProcessor() {
private val log = LoggerFactory.getLogger(CapabilityResourceResolutionProcessor::class.java)
@@ -44,57 +44,65 @@ open class CapabilityResourceResolutionProcessor(private var componentFunctionSc
}
override suspend fun processNB(resourceAssignment: ResourceAssignment) {
-
- val dName = resourceAssignment.dictionaryName!!
- val dSource = resourceAssignment.dictionarySource!!
- val resourceDefinition = resourceDefinition(resourceAssignment.dictionaryName!!)
-
- /** Check Resource Assignment has the source definitions, If not get from Resource Definition **/
- val resourceSource = resourceAssignment.dictionarySourceDefinition
+ // Execute only if value is not in Input
+ if (!setFromInput(resourceAssignment)) {
+ val dName = resourceAssignment.dictionaryName!!
+ val dSource = resourceAssignment.dictionarySource!!
+ val resourceDefinition = resourceDefinition(resourceAssignment.dictionaryName!!)
+
+ /** Check Resource Assignment has the source definitions, If not get from Resource Definition **/
+ val resourceSource = resourceAssignment.dictionarySourceDefinition
?: resourceDefinition?.sources?.get(dSource)
?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
- val resourceSourceProps = checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" }
- /**
- * Get the Capability Resource Source Info from Property Definitions.
- */
- val capabilityResourceSourceProperty = JacksonUtils
+ val resourceSourceProps =
+ checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" }
+ /**
+ * Get the Capability Resource Source Info from Property Definitions.
+ */
+ val capabilityResourceSourceProperty = JacksonUtils
.getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java)
- val scriptType = capabilityResourceSourceProperty.scriptType
- val scriptClassReference = capabilityResourceSourceProperty.scriptClassReference
- val instanceDependencies = capabilityResourceSourceProperty.instanceDependencies ?: listOf()
+ val scriptType = capabilityResourceSourceProperty.scriptType
+ val scriptClassReference = capabilityResourceSourceProperty.scriptClassReference
+ val instanceDependencies = capabilityResourceSourceProperty.instanceDependencies ?: listOf()
- componentResourceAssignmentProcessor = scriptInstance(scriptType, scriptClassReference, instanceDependencies)
+ componentResourceAssignmentProcessor =
+ scriptInstance(scriptType, scriptClassReference, instanceDependencies)
- checkNotNull(componentResourceAssignmentProcessor) {
- "failed to get capability resource assignment processor($scriptClassReference)"
- }
+ checkNotNull(componentResourceAssignmentProcessor) {
+ "failed to get capability resource assignment processor($scriptClassReference)"
+ }
- // Assign Current Blueprint runtime and ResourceDictionaries
- componentResourceAssignmentProcessor!!.scriptType = scriptType
- componentResourceAssignmentProcessor!!.raRuntimeService = raRuntimeService
- componentResourceAssignmentProcessor!!.resourceDictionaries = resourceDictionaries
+ // Assign Current Blueprint runtime and ResourceDictionaries
+ componentResourceAssignmentProcessor!!.scriptType = scriptType
+ componentResourceAssignmentProcessor!!.raRuntimeService = raRuntimeService
+ componentResourceAssignmentProcessor!!.resourceDictionaries = resourceDictionaries
- // Invoke componentResourceAssignmentProcessor
- componentResourceAssignmentProcessor!!.executeScript(resourceAssignment)
+ // Invoke componentResourceAssignmentProcessor
+ componentResourceAssignmentProcessor!!.executeScript(resourceAssignment)
+ }
}
override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
raRuntimeService.getBluePrintError()
- .addError("Failed in CapabilityResourceResolutionProcessor : ${runtimeException.message}")
+ .addError("Failed in CapabilityResourceResolutionProcessor : ${runtimeException.message}")
ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, runtimeException.message)
}
suspend fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List<String>)
: ResourceAssignmentProcessor {
- log.info("creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" +
- "instanceDependencies($instanceDependencies)")
+ log.info(
+ "creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" +
+ "instanceDependencies($instanceDependencies)"
+ )
val scriptComponent = componentFunctionScriptingService
- .scriptInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(), scriptType,
- scriptClassReference)
+ .scriptInstance<ResourceAssignmentProcessor>(
+ raRuntimeService.bluePrintContext(), scriptType,
+ scriptClassReference
+ )
return scriptComponent
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
index 5043c9a78..8d21e9a70 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -23,7 +23,10 @@ import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericServ
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
-import org.onap.ccsdk.cds.controllerblueprints.core.*
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants
@@ -40,9 +43,10 @@ import java.util.*
*/
@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-db")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropertySevice: BluePrintDBLibPropertySevice,
- private val primaryDBLibGenericService: PrimaryDBLibGenericService)
- : ResourceAssignmentProcessor() {
+open class DatabaseResourceAssignmentProcessor(
+ private val bluePrintDBLibPropertySevice: BluePrintDBLibPropertySevice,
+ private val primaryDBLibGenericService: PrimaryDBLibGenericService
+) : ResourceAssignmentProcessor() {
private val logger = LoggerFactory.getLogger(DatabaseResourceAssignmentProcessor::class.java)
@@ -53,19 +57,10 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
override suspend fun processNB(resourceAssignment: ResourceAssignment) {
try {
validate(resourceAssignment)
-
// Check if It has Input
- try {
- val value = raRuntimeService.getInputValue(resourceAssignment.name)
- if (ResourceAssignmentUtils.checkIfInputWasProvided(resourceAssignment, value)) {
- ResourceAssignmentUtils.setInputValueIfProvided(resourceAssignment, raRuntimeService, value)
- } else {
- setValueFromDB(resourceAssignment)
- }
- } catch (e: BluePrintProcessorException) {
+ if (!setFromInput(resourceAssignment)) {
setValueFromDB(resourceAssignment)
}
-
// Check the value has populated for mandatory case
ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
} catch (e: Exception) {
@@ -81,12 +76,13 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
/** Check Resource Assignment has the source definitions, If not get from Resource Definition **/
val resourceSource = resourceAssignment.dictionarySourceDefinition
- ?: resourceDefinition?.sources?.get(dSource)
- ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+ ?: resourceDefinition?.sources?.get(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 sourceProperties =
+ JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java)
val sql = checkNotNull(sourceProperties.query) {
"failed to get request query for $dName under $dSource properties"
@@ -130,7 +126,7 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
//placeholder to get the list of DB sources.
//TODO: This will be replaced with a DB
- private fun getListOfDBSources(): Array<String> = arrayOf(ResourceDictionaryConstants.PROCESSOR_DB)
+ private fun getListOfDBSources(): Array<String> = arrayOf(ResourceDictionaryConstants.PROCESSOR_DB)
private fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> {
val namedParameters = HashMap<String, Any>()
@@ -144,7 +140,11 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
}
@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)
@@ -158,8 +158,10 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
"Failed to get database query result into Json node."
}
- val parsedResponseNode = ResourceAssignmentUtils.parseResponseNode(responseNode, resourceAssignment,
- raRuntimeService, outputKeyMapping)
+ val parsedResponseNode = ResourceAssignmentUtils.parseResponseNode(
+ responseNode, resourceAssignment,
+ raRuntimeService, outputKeyMapping
+ )
ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, parsedResponseNode)
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
index 954b60522..9a83b0cc0 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
@@ -17,7 +17,6 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
-import com.fasterxml.jackson.databind.node.MissingNode
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
@@ -44,17 +43,15 @@ open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() {
override suspend fun processNB(resourceAssignment: ResourceAssignment) {
try {
- var value = getFromInput(resourceAssignment)
- if (value == null || value is MissingNode) {
- value = resourceAssignment.property?.defaultValue
+ if (!setFromInput(resourceAssignment)) {
+ val value = resourceAssignment.property?.defaultValue
ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
}
// Check the value has populated for mandatory case
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)
}
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
index f26da141b..a78e7872e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
@@ -17,14 +17,11 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
-import com.fasterxml.jackson.databind.node.MissingNode
-import com.fasterxml.jackson.databind.node.NullNode
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
-import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Service
@@ -45,11 +42,7 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
override suspend fun processNB(resourceAssignment: ResourceAssignment) {
try {
if (isNotEmpty(resourceAssignment.name)) {
- val value = raRuntimeService.getInputValue(resourceAssignment.name)
- // if value is null don't call setResourceDataValue to populate the value
- if (ResourceAssignmentUtils.checkIfInputWasProvided(resourceAssignment, value)) {
- ResourceAssignmentUtils.setInputValueIfProvided(resourceAssignment, raRuntimeService, value)
- }
+ setFromInput(resourceAssignment)
}
// Check the value has populated for mandatory case
ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
index 2a7d19b94..af89bcef6 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
@@ -22,10 +22,7 @@ import com.fasterxml.jackson.databind.JsonNode
import org.apache.commons.collections.MapUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
+import org.onap.ccsdk.cds.controllerblueprints.core.*
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintVelocityTemplateService
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
@@ -48,18 +45,20 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
*/
open fun <T> scriptPropertyInstanceType(name: String): T {
return scriptPropertyInstances as? T
- ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
+ ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
}
- open fun getFromInput(resourceAssignment: ResourceAssignment): JsonNode? {
- var value: JsonNode? = null
+ open fun setFromInput(resourceAssignment: ResourceAssignment): Boolean {
try {
- value = raRuntimeService.getInputValue(resourceAssignment.name)
- ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+ val value = raRuntimeService.getInputValue(resourceAssignment.name)
+ if (value.returnNullIfMissing() != null) {
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+ return true
+ }
} catch (e: BluePrintProcessorException) {
// NoOp - couldn't find value from input
}
- return value
+ return false
}
open fun resourceDefinition(name: String): ResourceDefinition? {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
index ecc2c2be1..dab6ff79f 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
@@ -22,7 +22,10 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.Rest
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
-import org.onap.ccsdk.cds.controllerblueprints.core.*
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.slf4j.LoggerFactory
@@ -37,8 +40,8 @@ import org.springframework.stereotype.Service
*/
@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService)
- : ResourceAssignmentProcessor() {
+open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService) :
+ ResourceAssignmentProcessor() {
private val logger = LoggerFactory.getLogger(RestResourceResolutionProcessor::class.java)
@@ -51,35 +54,31 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
validate(resourceAssignment)
// Check if It has Input
- val value = raRuntimeService.getInputValue(resourceAssignment.name)
- if (ResourceAssignmentUtils.checkIfInputWasProvided(resourceAssignment, value)) {
- ResourceAssignmentUtils.setInputValueIfProvided(resourceAssignment, raRuntimeService, value)
- }
- else {
+ if (!setFromInput(resourceAssignment)) {
val dName = resourceAssignment.dictionaryName!!
val dSource = resourceAssignment.dictionarySource!!
val resourceDefinition = resourceDefinition(dName)
/** Check Resource Assignment has the source definitions, If not get from Resource Definitions **/
val resourceSource = resourceAssignment.dictionarySourceDefinition
- ?: resourceDefinition?.sources?.get(dSource)
- ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+ ?: resourceDefinition?.sources?.get(dSource)
+ ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
val resourceSourceProperties =
- checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
+ checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
val sourceProperties =
- JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
+ JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
val path = nullToEmpty(sourceProperties.path)
val inputKeyMapping =
- checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
+ checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping).toMutableMap()
// Resolving content Variables
val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping)
val urlPath =
- resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
+ resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping)
logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
@@ -96,7 +95,7 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
populateResource(resourceAssignment, sourceProperties, responseBody, path)
} else {
val errMsg =
- "Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath) response_code: ($responseStatusCode)"
+ "Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath) response_code: ($responseStatusCode)"
logger.warn(errMsg)
throw BluePrintProcessorException(errMsg)
}
@@ -105,13 +104,14 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
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)
}
}
- fun blueprintWebClientService(resourceAssignment: ResourceAssignment,
- restResourceSource: RestResourceSource): BlueprintWebClientService {
+ fun blueprintWebClientService(
+ resourceAssignment: ResourceAssignment,
+ restResourceSource: RestResourceSource
+ ): BlueprintWebClientService {
return if (isNotEmpty(restResourceSource.endpointSelector)) {
val restPropertiesJson = raRuntimeService.resolveDSLExpression(restResourceSource.endpointSelector!!)
blueprintRestLibPropertyService.blueprintWebClientService(restPropertiesJson)
@@ -121,8 +121,10 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
}
@Throws(BluePrintProcessorException::class)
- private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource,
- restResponse: String, path: String) {
+ private fun populateResource(
+ resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource,
+ restResponse: String, path: String
+ ) {
val dName = resourceAssignment.dictionaryName
val dSource = resourceAssignment.dictionarySource
val type = nullToEmpty(resourceAssignment.property?.type)
@@ -140,8 +142,10 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
val valueToPrint = ResourceAssignmentUtils.getValueToLog(metadata, responseNode)
logger.info("populating value for output mapping ($outputKeyMapping), from json ($valueToPrint)")
- val parsedResponseNode = ResourceAssignmentUtils.parseResponseNode(responseNode, resourceAssignment,
- raRuntimeService, outputKeyMapping)
+ val parsedResponseNode = ResourceAssignmentUtils.parseResponseNode(
+ responseNode, resourceAssignment,
+ raRuntimeService, outputKeyMapping
+ )
// Set the List of Complex Values
ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, parsedResponseNode)
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
index 7854aa49a..2a3820f07 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
@@ -40,22 +40,28 @@ class ResourceAssignmentUtils {
private val logger = LoggerFactory.getLogger(ResourceAssignmentUtils::class.toString())
suspend fun resourceDefinitions(blueprintBasePath: String): MutableMap<String, ResourceDefinition> {
- val dictionaryFile = normalizedFile(blueprintBasePath, BluePrintConstants.TOSCA_DEFINITIONS_DIR,
- ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES)
+ val dictionaryFile = normalizedFile(
+ blueprintBasePath, BluePrintConstants.TOSCA_DEFINITIONS_DIR,
+ ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES
+ )
checkFileExists(dictionaryFile) { "resource definition file(${dictionaryFile.absolutePath}) is missing" }
return JacksonReactorUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)
}
@Throws(BluePrintProcessorException::class)
- fun setResourceDataValue(resourceAssignment: ResourceAssignment,
- raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) {
+ fun setResourceDataValue(
+ resourceAssignment: ResourceAssignment,
+ raRuntimeService: ResourceAssignmentRuntimeService, value: Any?
+ ) {
// TODO("See if Validation is needed in future with respect to conversion and Types")
return setResourceDataValue(resourceAssignment, raRuntimeService, value.asJsonType())
}
@Throws(BluePrintProcessorException::class)
- fun setResourceDataValue(resourceAssignment: ResourceAssignment,
- raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode) {
+ fun setResourceDataValue(
+ resourceAssignment: ResourceAssignment,
+ raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode
+ ) {
val resourceProp = checkNotNull(resourceAssignment.property) {
"Failed in setting resource value for resource mapping $resourceAssignment"
}
@@ -65,31 +71,39 @@ class ResourceAssignmentUtils {
if (resourceAssignment.dictionaryName.isNullOrEmpty()) {
resourceAssignment.dictionaryName = resourceAssignment.name
- logger.warn("Missing dictionary key, setting with template key (${resourceAssignment.name}) " +
- "as dictionary key (${resourceAssignment.dictionaryName})")
+ logger.warn(
+ "Missing dictionary key, setting with template key (${resourceAssignment.name}) " +
+ "as dictionary key (${resourceAssignment.dictionaryName})"
+ )
}
try {
if (resourceProp.type.isNotEmpty()) {
val metadata = resourceAssignment.property!!.metadata
val valueToPrint = getValueToLog(metadata, value)
- logger.info("Setting Resource Value ($valueToPrint) for Resource Name " +
- "(${resourceAssignment.name}), definition(${resourceAssignment.dictionaryName}) " +
- "of type (${resourceProp.type})")
+ logger.info(
+ "Setting Resource Value ($valueToPrint) for Resource Name " +
+ "(${resourceAssignment.name}), definition(${resourceAssignment.dictionaryName}) " +
+ "of type (${resourceProp.type})"
+ )
setResourceValue(resourceAssignment, raRuntimeService, value)
resourceAssignment.updatedDate = Date()
resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM
resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS
}
} catch (e: Exception) {
- throw BluePrintProcessorException("Failed in setting value for template key " +
- "(${resourceAssignment.name}) and dictionary key (${resourceAssignment.dictionaryName}) of " +
- "type (${resourceProp.type}) with error message (${e.message})", e)
+ throw BluePrintProcessorException(
+ "Failed in setting value for template key " +
+ "(${resourceAssignment.name}) and dictionary key (${resourceAssignment.dictionaryName}) of " +
+ "type (${resourceProp.type}) with error message (${e.message})", e
+ )
}
}
- private fun setResourceValue(resourceAssignment: ResourceAssignment,
- raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode) {
+ private fun setResourceValue(
+ resourceAssignment: ResourceAssignment,
+ raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode
+ ) {
// TODO("See if Validation is needed wrt to type before storing")
raRuntimeService.putResolutionStore(resourceAssignment.name, value)
raRuntimeService.putDictionaryStore(resourceAssignment.dictionaryName!!, value)
@@ -106,28 +120,13 @@ class ResourceAssignmentUtils {
}
@Throws(BluePrintProcessorException::class)
- fun setInputValueIfProvided(resourceAssignment: ResourceAssignment,
- raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode) {
- logger.info("${resourceAssignment.dictionarySource} source template key (${resourceAssignment.name}) " +
- "found from input and value is ($value)")
- try {
- ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
- }
- catch (e: Exception) {
- throw BluePrintProcessorException("Failed to set input value in resource name " +
- "(${resourceAssignment.name}) and dictionary key (${resourceAssignment.dictionaryName}) of " +
- "type (${resourceAssignment.property!!.type}) with error message (${e.message})", e)
- }
-
- }
-
- @Throws(BluePrintProcessorException::class)
fun assertTemplateKeyValueNotNull(resourceAssignment: ResourceAssignment) {
val resourceProp = checkNotNull(resourceAssignment.property) {
"Failed to populate mandatory resource resource mapping $resourceAssignment"
}
if (resourceProp.required != null && resourceProp.required!!
- && (resourceProp.value == null || resourceProp.value!!.returnNullIfMissing() == null)) {
+ && (resourceProp.value == null || resourceProp.value!!.returnNullIfMissing() == null)
+ ) {
logger.error("failed to populate mandatory resource mapping ($resourceAssignment)")
throw BluePrintProcessorException("failed to populate mandatory resource mapping ($resourceAssignment)")
}
@@ -185,7 +184,10 @@ class ResourceAssignmentUtils {
return data
}
- private fun useDefaultValueIfNull(resourceAssignment: ResourceAssignment, resourceAssignmentName: String): JsonNode {
+ private fun useDefaultValueIfNull(
+ resourceAssignment: ResourceAssignment,
+ resourceAssignmentName: String
+ ): JsonNode {
if (resourceAssignment.property?.value == null) {
val defaultValue = "\${$resourceAssignmentName}"
return TextNode(defaultValue)
@@ -197,8 +199,10 @@ class ResourceAssignmentUtils {
fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>,
templateArtifactName: String): ResourceAssignmentRuntimeService {
- val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService(blueprintRuntimeService.id(),
- blueprintRuntimeService.bluePrintContext())
+ val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService(
+ blueprintRuntimeService.id(),
+ blueprintRuntimeService.bluePrintContext()
+ )
resourceAssignmentRuntimeService.createUniqueId(templateArtifactName)
resourceAssignmentRuntimeService.setExecutionContext(blueprintRuntimeService.getExecutionContext() as MutableMap<String, JsonNode>)
@@ -210,7 +214,8 @@ class ResourceAssignmentUtils {
propertyName: String): String {
lateinit var type: String
try {
- val dataTypeProps = checkNotNull(raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties)
+ val dataTypeProps =
+ checkNotNull(raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties)
val propertyDefinition = checkNotNull(dataTypeProps[propertyName])
type = checkNotEmpty(propertyDefinition.type) { "Couldn't get data type ($dataTypeName)" }
@@ -231,11 +236,9 @@ class ResourceAssignmentUtils {
throw BluePrintProcessorException("Couldn't get data dictionary type for dictionary name (${resourceAssignment.name})")
}
val type = resourceAssignment.property!!.type
-
val valueToPrint = getValueToLog(metadata, responseNode)
logger.info("For template key (${resourceAssignment.name}) setting value as ($valueToPrint)")
-
return when (type) {
in BluePrintTypes.validPrimitiveTypes() -> {
parseResponseNodeForPrimitiveTypes(responseNode, outputKeyMapping)
@@ -255,9 +258,11 @@ class ResourceAssignmentUtils {
}
}
+ //TODO: Need to Refactor
private fun parseResponseNodeForPrimitiveTypes(responseNode: JsonNode,
outputKeyMapping: MutableMap<String, String>): JsonNode {
var result: JsonNode? = responseNode
+
if (responseNode.isComplexType()) {
val key = outputKeyMapping.keys.firstOrNull()
var returnNode: JsonNode?
@@ -265,35 +270,29 @@ class ResourceAssignmentUtils {
val arrayNode = responseNode.toList()
val firstElement = if (key.isNullOrEmpty()) {
arrayNode.first()
- }
- else{
+ } else {
arrayNode.firstOrNull { element ->
element.isComplexType() && element.has(outputKeyMapping[key])
}
}
-
returnNode = firstElement
- }
- else{
+ } else {
returnNode = responseNode
}
if (returnNode.isNull() || (returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[key]))) {
if (key.isNullOrEmpty()) {
throw BluePrintProcessorException("Fail to find mapping in the responseNode.")
- }
- else {
+ } else {
throw BluePrintProcessorException("Fail to find response with output key mapping ($key) in result.")
}
}
result = if (returnNode.isComplexType()) {
returnNode[outputKeyMapping[key]]
- }
- else {
+ } else {
responseNode
}
- }
- else {
+ } else {
if (outputKeyMapping.isNotEmpty()) {
throw BluePrintProcessorException("Fail to find key-value in response node to map output-key-mapping.")
}
@@ -301,15 +300,19 @@ class ResourceAssignmentUtils {
return result!!
}
- private fun parseResponseNodeForCollection(responseNode: JsonNode, resourceAssignment: ResourceAssignment,
- raRuntimeService: ResourceAssignmentRuntimeService,
- outputKeyMapping: MutableMap<String, String>): JsonNode {
+ private fun parseResponseNodeForCollection(
+ responseNode: JsonNode, resourceAssignment: ResourceAssignment,
+ raRuntimeService: ResourceAssignmentRuntimeService,
+ outputKeyMapping: MutableMap<String, String>
+ ): JsonNode {
val dName = resourceAssignment.dictionaryName
val metadata = resourceAssignment.property!!.metadata
var resultNode: JsonNode
if ((resourceAssignment.property?.entrySchema?.type).isNullOrEmpty()) {
- throw BluePrintProcessorException("Couldn't get data type for dictionary type " +
- "(${resourceAssignment.property!!.type}) and dictionary name ($dName)")
+ throw BluePrintProcessorException(
+ "Couldn't get data type for dictionary type " +
+ "(${resourceAssignment.property!!.type}) and dictionary name ($dName)"
+ )
}
val entrySchemaType = resourceAssignment.property!!.entrySchema!!.type
@@ -319,22 +322,24 @@ class ResourceAssignmentUtils {
is ArrayNode -> {
val responseArrayNode = responseNode.toList()
for (responseSingleJsonNode in responseArrayNode) {
- val arrayChildNode = parseSingleElementOfArrayResponseNode(entrySchemaType,
- outputKeyMapping, raRuntimeService, responseSingleJsonNode, metadata)
+ val arrayChildNode = parseSingleElementOfArrayResponseNode(
+ entrySchemaType,
+ outputKeyMapping, raRuntimeService, responseSingleJsonNode, metadata
+ )
arrayNode.add(arrayChildNode)
}
resultNode = arrayNode
}
is ObjectNode -> {
val responseArrayNode = responseNode.rootFieldsToMap()
- resultNode = parseObjectResponseNode(entrySchemaType, outputKeyMapping, responseArrayNode, metadata)
+ resultNode =
+ parseObjectResponseNode(entrySchemaType, outputKeyMapping, responseArrayNode, metadata)
}
else -> {
throw BluePrintProcessorException("Key-value response expected to match the responseNode.")
}
}
- }
- else {
+ } else {
when (responseNode) {
is ArrayNode -> {
responseNode.forEach { elementNode ->
@@ -347,7 +352,12 @@ class ResourceAssignmentUtils {
for ((key, responseSingleJsonNode) in responseArrayNode) {
val arrayChildNode = JacksonUtils.objectMapper.createObjectNode()
logKeyValueResolvedResource(metadata, key, responseSingleJsonNode, entrySchemaType)
- JacksonUtils.populateJsonNodeValues(key, responseSingleJsonNode, entrySchemaType, arrayChildNode)
+ JacksonUtils.populateJsonNodeValues(
+ key,
+ responseSingleJsonNode,
+ entrySchemaType,
+ arrayChildNode
+ )
arrayNode.add(arrayChildNode)
}
resultNode = arrayNode
@@ -361,28 +371,50 @@ class ResourceAssignmentUtils {
return resultNode
}
- private fun parseSingleElementOfArrayResponseNode(entrySchemaType: String, outputKeyMapping: MutableMap<String, String>,
- raRuntimeService: ResourceAssignmentRuntimeService,
- responseNode: JsonNode, metadata: MutableMap<String, String>?): ObjectNode {
+ private fun parseSingleElementOfArrayResponseNode(
+ entrySchemaType: String, outputKeyMapping: MutableMap<String, String>,
+ raRuntimeService: ResourceAssignmentRuntimeService,
+ responseNode: JsonNode, metadata: MutableMap<String, String>?
+ ): ObjectNode {
val outputKeyMappingHasOnlyOneElement = checkIfOutputKeyMappingProvideOneElement(outputKeyMapping)
when (entrySchemaType) {
in BluePrintTypes.validPrimitiveTypes() -> {
if (outputKeyMappingHasOnlyOneElement) {
val outputKeyMap = outputKeyMapping.entries.first()
- return parseSingleElementNodeWithOneOutputKeyMapping(responseNode, outputKeyMap.key, outputKeyMap.value, entrySchemaType, metadata)
- }
- else {
+ return parseSingleElementNodeWithOneOutputKeyMapping(
+ responseNode,
+ outputKeyMap.key,
+ outputKeyMap.value,
+ entrySchemaType,
+ metadata
+ )
+ } else {
throw BluePrintProcessorException("Expect one entry in output-key-mapping")
}
}
else -> {
return when {
- checkOutputKeyMappingAllElementsInDataTypeProperties(entrySchemaType, outputKeyMapping, raRuntimeService) -> {
- parseSingleElementNodeWithAllOutputKeyMapping(responseNode, outputKeyMapping, entrySchemaType, metadata)
+ checkOutputKeyMappingAllElementsInDataTypeProperties(
+ entrySchemaType,
+ outputKeyMapping,
+ raRuntimeService
+ ) -> {
+ parseSingleElementNodeWithAllOutputKeyMapping(
+ responseNode,
+ outputKeyMapping,
+ entrySchemaType,
+ metadata
+ )
}
outputKeyMappingHasOnlyOneElement -> {
val outputKeyMap = outputKeyMapping.entries.first()
- parseSingleElementNodeWithOneOutputKeyMapping(responseNode, outputKeyMap.key, outputKeyMap.value, entrySchemaType, metadata)
+ parseSingleElementNodeWithOneOutputKeyMapping(
+ responseNode,
+ outputKeyMap.key,
+ outputKeyMap.value,
+ entrySchemaType,
+ metadata
+ )
}
else -> {
throw BluePrintProcessorException("Output-key-mapping do not map the Data Type $entrySchemaType")
@@ -392,27 +424,31 @@ class ResourceAssignmentUtils {
}
}
- private fun parseObjectResponseNode(entrySchemaType: String, outputKeyMapping: MutableMap<String, String>,
- responseArrayNode: MutableMap<String, JsonNode>, metadata: MutableMap<String, String>?): ObjectNode {
+ private fun parseObjectResponseNode(
+ entrySchemaType: String, outputKeyMapping: MutableMap<String, String>,
+ responseArrayNode: MutableMap<String, JsonNode>, metadata: MutableMap<String, String>?
+ ): ObjectNode {
val outputKeyMappingHasOnlyOneElement = checkIfOutputKeyMappingProvideOneElement(outputKeyMapping)
if (outputKeyMappingHasOnlyOneElement) {
val outputKeyMap = outputKeyMapping.entries.first()
- return parseObjectResponseNodeWithOneOutputKeyMapping(responseArrayNode, outputKeyMap.key, outputKeyMap.value,
- entrySchemaType, metadata)
- }
- else {
+ return parseObjectResponseNodeWithOneOutputKeyMapping(
+ responseArrayNode, outputKeyMap.key, outputKeyMap.value,
+ entrySchemaType, metadata
+ )
+ } else {
throw BluePrintProcessorException("Output-key-mapping do not map the Data Type $entrySchemaType")
}
}
- private fun parseSingleElementNodeWithOneOutputKeyMapping(responseSingleJsonNode: JsonNode, outputKeyMappingKey:
- String, outputKeyMappingValue: String, type: String, metadata: MutableMap<String, String>?): ObjectNode {
+ private fun parseSingleElementNodeWithOneOutputKeyMapping(
+ responseSingleJsonNode: JsonNode, outputKeyMappingKey:
+ String, outputKeyMappingValue: String, type: String, metadata: MutableMap<String, String>?
+ ): ObjectNode {
val arrayChildNode = JacksonUtils.objectMapper.createObjectNode()
val responseKeyValue = if (responseSingleJsonNode.has(outputKeyMappingValue)) {
responseSingleJsonNode.get(outputKeyMappingValue)
- }
- else {
+ } else {
NullNode.getInstance()
}
@@ -422,9 +458,11 @@ class ResourceAssignmentUtils {
return arrayChildNode
}
- private fun parseSingleElementNodeWithAllOutputKeyMapping(responseSingleJsonNode: JsonNode,
- outputKeyMapping: MutableMap<String, String>,
- type: String, metadata: MutableMap<String, String>?): ObjectNode {
+ private fun parseSingleElementNodeWithAllOutputKeyMapping(
+ responseSingleJsonNode: JsonNode,
+ outputKeyMapping: MutableMap<String, String>,
+ type: String, metadata: MutableMap<String, String>?
+ ): ObjectNode {
val arrayChildNode = JacksonUtils.objectMapper.createObjectNode()
outputKeyMapping.map {
val responseKeyValue = if (responseSingleJsonNode.has(it.value)) {
@@ -439,28 +477,31 @@ class ResourceAssignmentUtils {
return arrayChildNode
}
- private fun parseObjectResponseNodeWithOneOutputKeyMapping(responseArrayNode: MutableMap<String, JsonNode>,
- outputKeyMappingKey: String, outputKeyMappingValue: String,
- type: String, metadata: MutableMap<String, String>?): ObjectNode {
+ private fun parseObjectResponseNodeWithOneOutputKeyMapping(
+ responseArrayNode: MutableMap<String, JsonNode>,
+ outputKeyMappingKey: String, outputKeyMappingValue: String,
+ type: String, metadata: MutableMap<String, String>?
+ ): ObjectNode {
val objectNode = JacksonUtils.objectMapper.createObjectNode()
val responseSingleJsonNode = responseArrayNode.filterKeys { key ->
- key == outputKeyMappingValue }.entries.firstOrNull()
+ key == outputKeyMappingValue
+ }.entries.firstOrNull()
if (responseSingleJsonNode == null) {
logKeyValueResolvedResource(metadata, outputKeyMappingKey, NullNode.getInstance(), type)
JacksonUtils.populateJsonNodeValues(outputKeyMappingKey, NullNode.getInstance(), type, objectNode)
- }
- else
- {
+ } else {
logKeyValueResolvedResource(metadata, outputKeyMappingKey, responseSingleJsonNode.value, type)
JacksonUtils.populateJsonNodeValues(outputKeyMappingKey, responseSingleJsonNode.value, type, objectNode)
}
return objectNode
}
- private fun parseResponseNodeForComplexType(responseNode: JsonNode, resourceAssignment: ResourceAssignment,
- raRuntimeService: ResourceAssignmentRuntimeService,
- outputKeyMapping: MutableMap<String, String>): JsonNode {
+ private fun parseResponseNodeForComplexType(
+ responseNode: JsonNode, resourceAssignment: ResourceAssignment,
+ raRuntimeService: ResourceAssignmentRuntimeService,
+ outputKeyMapping: MutableMap<String, String>
+ ): JsonNode {
val entrySchemaType = resourceAssignment.property!!.type
val dictionaryName = resourceAssignment.dictionaryName!!
val metadata = resourceAssignment.property!!.metadata
@@ -468,38 +509,57 @@ class ResourceAssignmentUtils {
if (outputKeyMapping.isNotEmpty()) {
return when {
- checkOutputKeyMappingAllElementsInDataTypeProperties(entrySchemaType, outputKeyMapping, raRuntimeService) -> {
- parseSingleElementNodeWithAllOutputKeyMapping(responseNode, outputKeyMapping, entrySchemaType, metadata)
+ checkOutputKeyMappingAllElementsInDataTypeProperties(
+ entrySchemaType,
+ outputKeyMapping,
+ raRuntimeService
+ ) -> {
+ parseSingleElementNodeWithAllOutputKeyMapping(
+ responseNode,
+ outputKeyMapping,
+ entrySchemaType,
+ metadata
+ )
}
outputKeyMappingHasOnlyOneElement -> {
val outputKeyMap = outputKeyMapping.entries.first()
- parseSingleElementNodeWithOneOutputKeyMapping(responseNode, outputKeyMap.key, outputKeyMap.value,
- entrySchemaType, metadata)
+ parseSingleElementNodeWithOneOutputKeyMapping(
+ responseNode, outputKeyMap.key, outputKeyMap.value,
+ entrySchemaType, metadata
+ )
}
else -> {
throw BluePrintProcessorException("Output-key-mapping do not map the Data Type $entrySchemaType")
}
}
- }
- else {
+ } else {
val childNode = JacksonUtils.objectMapper.createObjectNode()
JacksonUtils.populateJsonNodeValues(dictionaryName, responseNode, entrySchemaType, childNode)
return childNode
}
}
- private fun checkOutputKeyMappingAllElementsInDataTypeProperties(dataTypeName: String, outputKeyMapping: MutableMap<String, String>,
- raRuntimeService: ResourceAssignmentRuntimeService): Boolean {
+ private fun checkOutputKeyMappingAllElementsInDataTypeProperties(
+ dataTypeName: String, outputKeyMapping: MutableMap<String, String>,
+ raRuntimeService: ResourceAssignmentRuntimeService
+ ): Boolean {
val dataTypeProps = raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties
val result = outputKeyMapping.filterKeys { !dataTypeProps!!.containsKey(it) }.keys.firstOrNull()
return result == null
}
- private fun logKeyValueResolvedResource(metadata: MutableMap<String, String>?, key: String, value: JsonNode, type: String) {
+ private fun logKeyValueResolvedResource(
+ metadata: MutableMap<String, String>?,
+ key: String,
+ value: JsonNode,
+ type: String
+ ) {
val valueToPrint = getValueToLog(metadata, value)
- logger.info("For List Type Resource: key ($key), value ($valueToPrint), " +
- "type ({$type})")
+ logger.info(
+ "For List Type Resource: key ($key), value ($valueToPrint), " +
+ "type ({$type})"
+ )
}
private fun checkIfOutputKeyMappingProvideOneElement(outputKeyMapping: MutableMap<String, String>): Boolean {
@@ -509,21 +569,16 @@ class ResourceAssignmentUtils {
fun getValueToLog(metadata: MutableMap<String, String>?, value: Any): Any {
return if (checkIfLogIsProtected(metadata)) {
"*************"
- }
- else{
+ } else {
value
}
}
- fun checkIfInputWasProvided(resourceAssignment: ResourceAssignment, value: JsonNode) : Boolean{
- val defaultValueNode = resourceAssignment.property!!.defaultValue.asJsonType()
- return (value.returnNullIfMissing() != null && value != defaultValueNode)
- }
-
- private fun checkIfLogIsProtected(metadata: MutableMap<String, String>?) : Boolean {
+ private fun checkIfLogIsProtected(metadata: MutableMap<String, String>?): Boolean {
var checkProtected = false
if (metadata != null &&
- metadata.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_LOG_PROTECTED_METADATA)) {
+ metadata.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_LOG_PROTECTED_METADATA)
+ ) {
val protectedMetadata = metadata[ResourceResolutionConstants.RESOURCE_RESOLUTION_LOG_PROTECTED_METADATA]
if (protectedMetadata == "yes" || protectedMetadata == "y") {
checkProtected = true
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt
index e80663094..203b7ea30 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt
@@ -17,7 +17,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.moc
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.ArrayNode
-import com.fasterxml.jackson.databind.node.MissingNode
import org.apache.commons.collections.MapUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.RestResourceSource
@@ -55,8 +54,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe
override suspend fun processNB(executionRequest: ResourceAssignment) {
try {
// Check if It has Input
- val value = getFromInput(executionRequest)
- if (value == null || value is MissingNode) {
+ if (!setFromInput(executionRequest)) {
val dName = executionRequest.dictionaryName
val dSource = executionRequest.dictionarySource
val resourceDefinition = resourceDictionaries[dName]
@@ -66,7 +64,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe
val resourceSourceProperties = resourceSource!!.properties
val sourceProperties =
- JacksonUtils.getInstanceFromMap(resourceSourceProperties!!, RestResourceSource::class.java)
+ JacksonUtils.getInstanceFromMap(resourceSourceProperties!!, RestResourceSource::class.java)
val path = nullToEmpty(sourceProperties.path)
val inputKeyMapping = sourceProperties.inputKeyMapping
@@ -76,7 +74,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe
// Resolving content Variables
val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping)
val urlPath =
- resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
+ resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping)
logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
@@ -98,8 +96,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe
}
} catch (e: Exception) {
ResourceAssignmentUtils.setFailedResourceDataValue(executionRequest, e.message)
- throw BluePrintProcessorException("Failed in template resolutionKey ($executionRequest) assignments with: ${e.message}",
- e)
+ throw BluePrintProcessorException("Failed in template resolutionKey ($executionRequest) assignments with: ${e.message}", e)
}
}
@@ -139,10 +136,12 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe
outputKeyMapping!!.map {
val responseKeyValue = responseSingleJsonNode.get(it.key)
val propertyTypeForDataType = ResourceAssignmentUtils
- .getPropertyType(raRuntimeService, entrySchemaType, it.key)
+ .getPropertyType(raRuntimeService, entrySchemaType, it.key)
- JacksonUtils.populateJsonNodeValues(it.value,
- responseKeyValue, propertyTypeForDataType, arrayChildNode)
+ JacksonUtils.populateJsonNodeValues(
+ it.value,
+ responseKeyValue, propertyTypeForDataType, arrayChildNode
+ )
}
arrayNode.add(arrayChildNode)
}
@@ -157,7 +156,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe
outputKeyMapping!!.map {
val responseKeyValue = responseNode.get(it.key)
val propertyTypeForDataType = ResourceAssignmentUtils
- .getPropertyType(raRuntimeService, entrySchemaType, it.key)
+ .getPropertyType(raRuntimeService, entrySchemaType, it.key)
JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode)
}
// Set the List of Complex Values
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
index f020f2952..98f68ebaa 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
@@ -18,6 +18,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
+import com.fasterxml.jackson.databind.node.NullNode
import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
@@ -48,12 +49,16 @@ import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, ComponentFunctionScriptingService::class,
- BluePrintScriptsServiceImpl::class,
- BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class])
-@TestPropertySource(properties =
-["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
- "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"])
+@ContextConfiguration(
+ classes = [CapabilityResourceResolutionProcessor::class, ComponentFunctionScriptingService::class,
+ BluePrintScriptsServiceImpl::class,
+ BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class]
+)
+@TestPropertySource(
+ properties =
+ ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
+ "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"]
+)
class CapabilityResourceResolutionProcessorTest {
@Autowired
@@ -65,17 +70,21 @@ class CapabilityResourceResolutionProcessorTest {
val componentFunctionScriptingService = mockk<ComponentFunctionScriptingService>()
coEvery {
componentFunctionScriptingService
- .scriptInstance<ResourceAssignmentProcessor>(any(), any(), any())
+ .scriptInstance<ResourceAssignmentProcessor>(any(), any(), any())
} returns MockCapabilityScriptRA()
val raRuntimeService = mockk<ResourceAssignmentRuntimeService>()
every { raRuntimeService.bluePrintContext() } returns mockk<BluePrintContext>()
+ every { raRuntimeService.getInputValue("test-property") } returns NullNode.getInstance()
- val capabilityResourceResolutionProcessor = CapabilityResourceResolutionProcessor(componentFunctionScriptingService)
+ val capabilityResourceResolutionProcessor =
+ CapabilityResourceResolutionProcessor(componentFunctionScriptingService)
capabilityResourceResolutionProcessor.raRuntimeService = raRuntimeService
- val resourceAssignment = BluePrintTypes.resourceAssignment(name = "test-property", dictionaryName = "ra-dict-name",
- dictionarySource = "capability") {
+ val resourceAssignment = BluePrintTypes.resourceAssignment(
+ name = "test-property", dictionaryName = "ra-dict-name",
+ dictionarySource = "capability"
+ ) {
property("string", true, "")
sourceCapability {
definedProperties {
@@ -87,8 +96,10 @@ class CapabilityResourceResolutionProcessorTest {
}
val status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment)
assertTrue(status, "failed to execute capability source")
- assertEquals("assigned-data".asJsonPrimitive(), resourceAssignment.property!!.value,
- "assigned value miss match")
+ assertEquals(
+ "assigned-data".asJsonPrimitive(), resourceAssignment.property!!.value,
+ "assigned value miss match"
+ )
}
}
@@ -97,15 +108,18 @@ class CapabilityResourceResolutionProcessorTest {
runBlocking {
val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python")
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python"
+ )
val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
val resourceDefinition = JacksonUtils
- .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json",
- ResourceDefinition::class.java)!!
+ .readValueFromClassPathFile(
+ "mapping/capability/jython-resource-definitions.json",
+ ResourceDefinition::class.java
+ )!!
val resourceDefinitions: MutableMap<String, ResourceDefinition> = mutableMapOf()
resourceDefinitions[resourceDefinition.name] = resourceDefinition
capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions