Templating constants added to ResourceAssignment 63/130463/6
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Fri, 26 Aug 2022 21:44:34 +0000 (23:44 +0200)
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Thu, 1 Sep 2022 13:51:43 +0000 (15:51 +0200)
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

components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json
components/model-catalog/definition-type/starter-type/data_type/datatype-resource-assignment.json
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt
ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
ms/blueprintsprocessor/modules/blueprints/resource-dict/src/test/resources/validation/success.json

index 98f7726..7572101 100644 (file)
       }
     }
   },
+  "vnf_parameter": {
+    "tags": "vnf_parameter",
+    "name": "vnf_parameter",
+    "property": {
+      "description": "vnf_parameter",
+      "type": "string"
+    },
+    "updated-by": "Rajewski, Lukasz <lukasz.rajewski@t-mobile.pl>",
+    "sources": {
+      "sdnc": {
+        "type": "source-rest",
+        "properties": {
+          "verb": "GET",
+          "type": "JSON",
+          "url-path": "/config/GENERIC-RESOURCE-API:services/service/$service-instance-id/service-data/vnfs/vnf/$vnf-id/vnf-data/vnf-topology/vnf-parameters-data/param/$parameter-name",
+          "path": "/param/0/value",
+          "input-key-mapping": {
+            "service-instance-id": "service-instance-id",
+            "vnf-id": "vnf-id",
+            "parameter-name": "parameter-name"
+          },
+          "output-key-mapping": {
+            "vnf_name": "value"
+          },
+          "key-dependencies": [
+            "service-instance-id",
+            "vnf-id"
+          ]
+        }
+      }
+    }
+  },
   "aai-get-resource": {
     "tags": "aai-get",
     "name": "aai-get-resource",
index 8fa595a..67c3e3c 100644 (file)
                        "required": false,
                        "type": "string"
                },
+               "templating-constants": {
+                       "required": false,
+                       "type": "map",
+                       "entry_schema": {
+                               "type": "string"
+                       }
+               },
                "dependencies": {
                        "required": true,
                        "type": "list",
index 71cf6ce..9388c28 100644 (file)
@@ -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)
index 139d823..bc6983b 100644 (file)
@@ -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)
index 25d19cf..6072a92 100644 (file)
@@ -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
         }
index e96083f..fb9997c 100644 (file)
@@ -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>):
index 479be69..c53c568 100644 (file)
@@ -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)
index f9a41ce..d161f64 100644 (file)
@@ -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 {
index 56ce3f6..75c12a0 100644 (file)
@@ -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
index 79925bf..23d2a0d 100644 (file)
       "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": []
   },
   {