From 696e0d2a4db883e0534dea0d94148eb8ec35e5f2 Mon Sep 17 00:00:00 2001 From: Jozsef Csongvai Date: Mon, 25 May 2020 11:23:21 -0400 Subject: Fix sub-attribute parsing for accessing resolved values 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 Change-Id: I3441569d9766fbd79703d2f224de448edd56dbb2 --- .../node_type/component-resource-resolution.json | 10 ++++++++++ .../resource/resolution/ResourceResolutionComponent.kt | 1 + .../resolution/ResourceResolutionComponentDSL.kt | 11 +++++++++++ .../resource/resolution/ResourceResolutionConstants.kt | 1 + .../resource/resolution/ResourceResolutionService.kt | 7 +++++++ .../resolution/utils/ResourceAssignmentUtils.kt | 7 +++++++ .../resolution/utils/ResourceAssignmentUtilsTest.kt | 17 ++++++++++++++++- 7 files changed, 53 insertions(+), 1 deletion(-) diff --git a/components/model-catalog/definition-type/starter-type/node_type/component-resource-resolution.json b/components/model-catalog/definition-type/starter-type/node_type/component-resource-resolution.json index ff1b5260e..cc2013076 100644 --- a/components/model-catalog/definition-type/starter-type/node_type/component-resource-resolution.json +++ b/components/model-catalog/definition-type/starter-type/node_type/component-resource-resolution.json @@ -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": { @@ -77,6 +83,10 @@ "required": true, "type": "string" }, + "resource-assignment-map" : { + "required": true, + "type": "string" + }, "status": { "required": true, "type": "string" diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt index 3c95ea7bb..e15705a7e 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt @@ -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" } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt index fd104d3ad..8c854b840 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt @@ -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()) diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt index b934940b1..e2a8920f5 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt @@ -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" diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index dff00c7eb..a9bfbab32 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -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()) 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 1be9649b9..f97c669d6 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 @@ -274,6 +274,13 @@ class ResourceAssignmentUtils { return JacksonUtils.getJson(data, includeNull = true) } + fun generateAssignmentMap( + artifactPrefix: String, + resourceAssignments: List + ): ObjectNode = resourceAssignments.associateBy({ it.name }, { it.property?.value }) + .let { mutableMapOf(artifactPrefix to it) } + .let { JacksonUtils.objectNodeFromObject(it) } + private fun useDefaultValueIfNull( resourceAssignment: ResourceAssignment, resourceAssignmentName: String diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt index b4befc26d..6734613fc 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt @@ -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 { -- cgit 1.2.3-korg