From 5e1e26053d13c9e693762c69b43eff3093c34d29 Mon Sep 17 00:00:00 2001 From: ottero Date: Tue, 28 May 2019 09:25:45 +0000 Subject: Returning null for unresolved variables When Blueprints Processor was not able to evaluate a variable, it would set its value to null. The expected behaviour would be to set the value to the default repres- entation in the formal notation as defined by Apache Velocity, which is a dollar followed by the name of the variable between curly braces. For example, if the value of the variable pnf-id could not be evaluated in runtime, its value would be defined as the string "${pnf-id}". The problem happened during evaluation of the variables that would be later sent to the template-meshing code for processing. The fix was to add a check before the value was assigned to the varia- ble; if the was not null, the assignment will happen normally. Otherwi- se, if the evaluation resolves to null, the variable receives the defa- ult value (string "${}"). Besides the tests that were put in place to test the code changed for this fix, two tests were added to the existing test case of the templa- te meshing code, to act as regression test. Change-Id: I635afb1eba4c0d45b821811f0119fa6c87ea9542 Issue-ID: CCSDK-1358 Signed-off-by: ottero --- .../resource/resolution/utils/ResourceAssignmentUtils.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin') 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 656e86169..1a943d110 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 @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.NullNode import com.fasterxml.jackson.databind.node.ObjectNode +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.ResourceResolutionConstants import org.onap.ccsdk.cds.controllerblueprints.core.* @@ -122,7 +123,7 @@ class ResourceAssignmentUtils { if (isNotEmpty(it.name) && it.property != null) { val rName = it.name val type = nullToEmpty(it.property?.type).toLowerCase() - val value = it.property?.value + val value = useDefaultValueIfNull(it, rName) logger.info("Generating Resource name ($rName), type ($type), value ($value)") root.set(rName, value) } @@ -136,6 +137,15 @@ class ResourceAssignmentUtils { return result } + private fun useDefaultValueIfNull(resourceAssignment: ResourceAssignment, resourceAssignmentName: String): JsonNode { + if (resourceAssignment.property?.value == null) { + val defaultValue = "\${$resourceAssignmentName}" + return TextNode(defaultValue) + } else { + return resourceAssignment.property!!.value!! + } + } + fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>, templateArtifactName: String): ResourceAssignmentRuntimeService { -- cgit 1.2.3-korg