aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2022-08-26 23:44:34 +0200
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2022-09-01 15:51:43 +0200
commit77891f46278488702aeed2fe970861a2f1b9a1a7 (patch)
treeef7976148875cd0df95c6c711725501416825352 /ms/blueprintsprocessor
parent54fdb67b49134fe357a6415fba761bab2588a197 (diff)
Templating constants added to ResourceAssignment
Fixed values of inputs for resource assignment allow to build data dictionaries that are generic. Along with templating of outputs mapping, path, url and payload sdnc and aai dictionary entry may be one for support of all the attributes of specified object like for instance generic vnf one. Issue-ID: CCSDK-3716 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> Change-Id: I1817303e997a4dfb7dda9c32d9ac690ec723b3d8
Diffstat (limited to 'ms/blueprintsprocessor')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt16
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt16
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt20
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt18
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt6
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt19
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt3
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt3
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/resource-dict/src/test/resources/validation/success.json7
9 files changed, 63 insertions, 45 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt
index 71cf6ceea..9388c280a 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt
@@ -68,14 +68,18 @@ open class IpAssignResolutionCapability : ResourceAssignmentProcessor() {
as MutableMap<String, String>
// Get the values from runtime store
- val resolvedKeyValues = resolveInputKeyMappingVariables(inputKeyMapping)
- log.info("\nResolved Input Key mappings: \n{}", resolvedKeyValues)
-
- resolvedKeyValues?.map { KeyIdentifier(it.key, it.value) }
- ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+ val resolvedInputKeyMapping = resolveInputKeyMappingVariables(
+ inputKeyMapping,
+ resourceAssignment.templatingConstants
+ ).toMutableMap()
+ log.info("\nResolved Input Key mappings: \n$resolvedInputKeyMapping")
+
+ resolvedInputKeyMapping.map { KeyIdentifier(it.key, it.value) }.let {
+ resourceAssignment.keyIdentifiers.addAll(it)
+ }
// Generate the payload using already resolved value
- val generatedPayload = generatePayload(resolvedKeyValues, groupResourceAssignments)
+ val generatedPayload = generatePayload(resolvedInputKeyMapping, groupResourceAssignments)
log.info("\nIP Assign mS Request Payload: \n{}", generatedPayload.asJsonType().toPrettyString())
resourceSourceProperties["resolved-payload"] = JacksonUtils.jsonNode(generatedPayload)
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt
index 139d8232f..bc6983bd1 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt
@@ -69,14 +69,18 @@ open class NamingResolutionCapability : ResourceAssignmentProcessor() {
log.info("\nResolving Input Key mappings: \n{}", inputKeyMapping)
// Get the values from runtime store
- val resolvedKeyValues = resolveInputKeyMappingVariables(inputKeyMapping)
- log.info("\nResolved Input Key mappings: \n{}", resolvedKeyValues)
-
- resolvedKeyValues?.map { KeyIdentifier(it.key, it.value) }
- ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+ val resolvedInputKeyMapping = resolveInputKeyMappingVariables(
+ inputKeyMapping,
+ resourceAssignment.templatingConstants
+ ).toMutableMap()
+ log.info("\nResolved Input Key mappings: \n$resolvedInputKeyMapping")
+
+ resolvedInputKeyMapping.map { KeyIdentifier(it.key, it.value) }.let {
+ resourceAssignment.keyIdentifiers.addAll(it)
+ }
// Generate the payload using already resolved value
- val generatedPayload = generatePayload(resolvedKeyValues, groupResourceAssignments)
+ val generatedPayload = generatePayload(resolvedInputKeyMapping, groupResourceAssignments)
log.info("\nNaming mS Request Payload: \n{}", generatedPayload.asJsonType().toPrettyString())
resourceSourceProperties["resolved-payload"] = JacksonUtils.jsonNode(generatedPayload)
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 25d19cff5..6072a9233 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
@@ -17,6 +17,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
+import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService
import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDBLibGenericService
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertyService
@@ -100,10 +101,15 @@ open class DatabaseResourceAssignmentProcessor(
"failed to get input-key-mappings for $dName under $dSource properties"
}
- sourceProperties.inputKeyMapping
- ?.mapValues { raRuntimeService.getResolutionStore(it.value) }
- ?.map { KeyIdentifier(it.key, it.value) }
- ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+ val resolvedInputKeyMapping = resolveInputKeyMappingVariables(
+ inputKeyMapping,
+ resourceAssignment.templatingConstants
+ ).toMutableMap()
+ logger.info("\nResolved Input Key mappings: \n$resolvedInputKeyMapping")
+
+ resolvedInputKeyMapping.map { KeyIdentifier(it.key, it.value) }.let {
+ resourceAssignment.keyIdentifiers.addAll(it)
+ }
logger.info(
"DatabaseResource ($dSource) dictionary information: " +
@@ -111,7 +117,7 @@ open class DatabaseResourceAssignmentProcessor(
)
val jdbcTemplate = blueprintDBLibService(sourceProperties, dSource)
- val rows = jdbcTemplate.query(sql, populateNamedParameter(inputKeyMapping))
+ val rows = jdbcTemplate.query(sql, populateNamedParameter(resolvedInputKeyMapping))
if (rows.isEmpty()) {
logger.warn("Emptyset from dictionary-source($dSource) for dictionary name ($dName) the query ($sql).")
}
@@ -145,10 +151,10 @@ open class DatabaseResourceAssignmentProcessor(
.resourceSourceMappings.filterValues { it == "source-db" }.keys.toTypedArray()
}
- open fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> {
+ open fun populateNamedParameter(inputKeyMapping: Map<String, JsonNode>): Map<String, Any> {
val namedParameters = HashMap<String, Any>()
inputKeyMapping.forEach {
- val expressionValue = raRuntimeService.getResolutionStore(it.value).textValue()
+ val expressionValue = it.value.textValue()
logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)")
namedParameters[it.key] = expressionValue
}
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 e96083f95..fb9997c47 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
@@ -19,7 +19,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
import com.fasterxml.jackson.databind.JsonNode
-import org.apache.commons.collections.MapUtils
+import com.fasterxml.jackson.databind.node.TextNode
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
@@ -32,7 +32,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintVelocityTem
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
import org.slf4j.LoggerFactory
-import java.util.HashMap
abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssignment, Boolean> {
@@ -93,15 +92,12 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
return if (resourceDictionaries.containsKey(name)) resourceDictionaries[name] else null
}
- open fun resolveInputKeyMappingVariables(inputKeyMapping: Map<String, String>): Map<String, JsonNode> {
- val resolvedInputKeyMapping = HashMap<String, JsonNode>()
- if (MapUtils.isNotEmpty(inputKeyMapping)) {
- for ((key, value) in inputKeyMapping) {
- val resultValue = raRuntimeService.getResolutionStore(value)
- resolvedInputKeyMapping[key] = resultValue
- }
- }
- return resolvedInputKeyMapping
+ open fun resolveInputKeyMappingVariables(
+ inputKeyMapping: Map<String, String>,
+ templatingConstants: Map<String, String>?
+ ): Map<String, JsonNode> {
+ val const = templatingConstants?.mapValues { TextNode(it.value) as JsonNode }
+ return inputKeyMapping.mapValues { const?.get(it.value) ?: raRuntimeService.getResolutionStore(it.value) }
}
open suspend fun resolveFromInputKeyMapping(valueToResolve: String, keyMapping: MutableMap<String, JsonNode>):
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 479be6923..c53c56806 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
@@ -81,7 +81,11 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
val inputKeyMapping =
checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
- val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping).toMutableMap()
+ val resolvedInputKeyMapping = resolveInputKeyMappingVariables(
+ inputKeyMapping,
+ resourceAssignment.templatingConstants
+ ).toMutableMap()
+ logger.info("\nResolved Input Key mappings: \n$resolvedInputKeyMapping")
resolvedInputKeyMapping.map { KeyIdentifier(it.key, it.value) }.let {
resourceAssignment.keyIdentifiers.addAll(it)
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 f9a41cead..d161f64ec 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
@@ -16,7 +16,6 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock
import com.fasterxml.jackson.databind.JsonNode
-import org.apache.commons.collections.MapUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.RestResourceSource
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.RestResourceResolutionProcessor
@@ -24,7 +23,6 @@ import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientSer
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.slf4j.LoggerFactory
-import java.util.HashMap
class MockRestResourceResolutionProcessor(
private val blueprintRestLibPropertyService:
@@ -33,15 +31,14 @@ class MockRestResourceResolutionProcessor(
private val logger = LoggerFactory.getLogger(MockRestResourceResolutionProcessor::class.java)
- override fun resolveInputKeyMappingVariables(inputKeyMapping: Map<String, String>): Map<String, JsonNode> {
- val resolvedInputKeyMapping = HashMap<String, JsonNode>()
- if (MapUtils.isNotEmpty(inputKeyMapping)) {
-
- resolvedInputKeyMapping["service-instance-id"] = "10".asJsonPrimitive()
- resolvedInputKeyMapping["vnf_name"] = "vnf1".asJsonPrimitive()
- resolvedInputKeyMapping["vnf-id"] = "123456".asJsonPrimitive()
- }
- return resolvedInputKeyMapping
+ override fun resolveInputKeyMappingVariables(
+ inputKeyMapping: Map<String, String>,
+ templatingConstants: Map<String, String>?
+ ): Map<String, JsonNode> {
+ this.raRuntimeService.putResolutionStore("service-instance-id", "10".asJsonPrimitive())
+ this.raRuntimeService.putResolutionStore("vnf_name", "vnf1".asJsonPrimitive())
+ this.raRuntimeService.putResolutionStore("vnf-id", "123456".asJsonPrimitive())
+ return super.resolveInputKeyMappingVariables(inputKeyMapping, templatingConstants)
}
override fun getName(): String {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt
index 56ce3f65d..75c12a0f2 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt
@@ -97,8 +97,9 @@ class RestResourceResolutionProcessorTest {
runBlocking {
val resourceAssignment = ResourceAssignment().apply {
name = "vnf_name"
- dictionaryName = "vnf_name"
+ dictionaryName = "vnf_parameter"
dictionarySource = "sdnc"
+ templatingConstants = mutableMapOf("parameter-name" to "vnf_name")
property = PropertyDefinition().apply {
type = "string"
required = true
diff --git a/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
index f92548612..50330fa68 100644
--- a/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
@@ -83,6 +83,9 @@ open class ResourceAssignment {
@JsonProperty("dependencies")
var dependencies: MutableList<String>? = null
+ @JsonProperty("templating-constants")
+ var templatingConstants: MutableMap<String, String>? = null
+
@JsonProperty("version")
var version: Int = 0
diff --git a/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/test/resources/validation/success.json b/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/test/resources/validation/success.json
index 79925bfac..23d2a0d95 100644
--- a/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/test/resources/validation/success.json
+++ b/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/test/resources/validation/success.json
@@ -79,8 +79,11 @@
"type": "string",
"required": true
},
- "dictionary-name": "vnf-name",
- "dictionary-source": "input",
+ "templating-constants": {
+ "parameter-name": "vnf-name"
+ },
+ "dictionary-name": "vnf-param",
+ "dictionary-source": "sdnc",
"dependencies": []
},
{