Fix sub-attribute parsing for accessing resolved values 00/108400/2
authorJozsef Csongvai <jozsef.csongvai@bell.ca>
Mon, 25 May 2020 15:23:21 +0000 (11:23 -0400)
committerKAPIL SINGAL <ks220y@att.com>
Thu, 28 May 2020 12:20:40 +0000 (12:20 +0000)
Added assignment-map attribute to ResourceResolutionComponent.
This attribute will hold a json object with the resolved values
for each artifact-prefix. It will enable accessing any resolved
value, using get_attribute with JsonPath.

Issue-ID: CCSDK-2389
Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
Change-Id: I3441569d9766fbd79703d2f224de448edd56dbb2

components/model-catalog/definition-type/starter-type/node_type/component-resource-resolution.json
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt

index ff1b526..cc20130 100644 (file)
@@ -3,8 +3,14 @@
   "version": "1.0.0",
   "attributes": {
     "assignment-params": {
+      "description": "Holds resolved template, resolution-summary or key-value",
       "required": true,
       "type": "string"
+    },
+    "assignment-map": {
+      "description": "Holds resolved values for each artifact prefix eg. { vdns: { vnf-id: 123 } }",
+      "required": true,
+      "type": "map"
     }
   },
   "capabilities": {
               "required": true,
               "type": "string"
             },
+            "resource-assignment-map" : {
+              "required": true,
+              "type": "string"
+            },
             "status": {
               "required": true,
               "type": "string"
index 3c95ea7..e15705a 100644 (file)
@@ -51,6 +51,7 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
         const val ATTRIBUTE_STATUS = "status"
 
         const val OUTPUT_RESOURCE_ASSIGNMENT_PARAMS = "resource-assignment-params"
+        const val OUTPUT_RESOURCE_ASSIGNMENT_MAP = "resource-assignment-map"
         const val OUTPUT_STATUS = "status"
     }
 
index fd104d3..8c854b8 100644 (file)
@@ -115,6 +115,10 @@ fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType {
                     ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, BluePrintConstants.DATA_TYPE_STRING,
                     true, "Output Response"
                 )
+                property(
+                    ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_MAP, BluePrintConstants.DATA_TYPE_MAP,
+                    true, "Output Resolved Values"
+                )
                 property(
                     ResourceResolutionComponent.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
                     true, "Status of the Component Execution ( success or failure )"
@@ -229,6 +233,13 @@ class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: St
             property(ResourceResolutionComponent.OUTPUT_STATUS, status)
         }
 
+        fun resourceAssignmentMap(resourceAssignmentMap: String) =
+            resourceAssignmentMap(resourceAssignmentMap.asJsonType())
+
+        fun resourceAssignmentMap(resourceAssignmentMap: JsonNode) {
+            property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_MAP, resourceAssignmentMap)
+        }
+
         fun resourceAssignmentParams(resourceAssignmentParams: String) =
             resourceAssignmentParams(resourceAssignmentParams.asJsonType())
 
index b934940..e2a8920 100644 (file)
@@ -23,6 +23,7 @@ object ResourceResolutionConstants {
     const val PREFIX_RESOURCE_RESOLUTION_PROCESSOR = "rr-processor-"
     const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
     const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params"
+    const val OUTPUT_ASSIGNMENT_MAP = "assignment-map"
     const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json"
     const val RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY = "resolution-key"
     const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result"
index dff00c7..a9bfbab 100644 (file)
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.JsonNode
 import kotlinx.coroutines.async
 import kotlinx.coroutines.awaitAll
 import kotlinx.coroutines.coroutineScope
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.OUTPUT_ASSIGNMENT_MAP
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService
@@ -185,6 +186,12 @@ open class ResourceResolutionServiceImpl(
             properties
         )
 
+        bluePrintRuntimeService.setNodeTemplateAttributeValue(
+                nodeTemplateName,
+                OUTPUT_ASSIGNMENT_MAP,
+                ResourceAssignmentUtils.generateAssignmentMap(artifactPrefix, resourceAssignments)
+        )
+
         val resolutionSummary = properties.getOrDefault(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY, false) as Boolean
         val resolvedParamJsonContent =
             ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
index 1be9649..f97c669 100644 (file)
@@ -274,6 +274,13 @@ class ResourceAssignmentUtils {
             return JacksonUtils.getJson(data, includeNull = true)
         }
 
+        fun generateAssignmentMap(
+            artifactPrefix: String,
+            resourceAssignments: List<ResourceAssignment>
+        ): ObjectNode = resourceAssignments.associateBy({ it.name }, { it.property?.value })
+                .let { mutableMapOf(artifactPrefix to it) }
+                .let { JacksonUtils.objectNodeFromObject(it) }
+
         private fun useDefaultValueIfNull(
             resourceAssignment: ResourceAssignment,
             resourceAssignmentName: String
index b4befc2..6734613 100644 (file)
@@ -22,6 +22,7 @@
 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils
 
 import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ObjectNode
 import com.fasterxml.jackson.databind.node.TextNode
 import io.mockk.every
 import io.mockk.spyk
@@ -167,7 +168,7 @@ class ResourceAssignmentUtilsTest {
     }
 
     @Test
-    fun generate() {
+    fun generateResolutionSummaryDataTest() {
         val resourceAssignment = createResourceAssignmentForTest(null)
         val resourceDefinition = ResourceDefinition()
         val nodeTemplate = NodeTemplate().apply {
@@ -206,6 +207,20 @@ class ResourceAssignmentUtilsTest {
         """.replace("\n|\\s".toRegex(), ""), result)
     }
 
+    @Test
+    fun generateAssignmentMapTest() {
+        val artifactPrefix = "vdns"
+        val resourceAssignments = mutableListOf(
+            createResourceAssignmentForTest("abc-123", "vnf-id"),
+            createResourceAssignmentForTest(null, "vf-module-name")
+        )
+
+        val result: ObjectNode = ResourceAssignmentUtils.generateAssignmentMap(artifactPrefix, resourceAssignments)
+
+        assertEquals("abc-123", result["vdns"]["vnf-id"].textValue())
+        assertEquals(JacksonUtils.getJsonNode(null), result["vdns"]["vf-module-name"])
+    }
+
     private fun createResourceAssignmentForTest(resourceValue: String?, resourceName: String = "pnf-id"): ResourceAssignment {
         val valueForTest = if (resourceValue == null) null else TextNode(resourceValue)
         val resourceAssignmentForTest = ResourceAssignment().apply {