Controller Blueprints Microservice
authorBrinda Santh <brindasanth@in.ibm.com>
Tue, 11 Sep 2018 03:15:31 +0000 (23:15 -0400)
committerBrinda Santh <brindasanth@in.ibm.com>
Tue, 11 Sep 2018 03:15:31 +0000 (23:15 -0400)
Add Attribute function implementation for Operation output properties.

Change-Id: I8fd116ad7def07d208f9c3c1bfe7b75deae667d4
Issue-ID: CCSDK-524
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
components/core/load/blueprints/baseconfiguration/Definitions/activation-blueprint.json
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt

index 9c70d6e..bc10f76 100644 (file)
@@ -66,8 +66,8 @@
                   }\r
                 },\r
                 "outputs": {\r
-                  "resource-assignment-params": "success",\r
-                  "status": "status"\r
+                  "resource-assignment-params": { "get_attribute" : ["SELF", "params"] },\r
+                  "status": "Success"\r
                 }\r
               }\r
             }\r
index ce0bcee..1fdb6c3 100644 (file)
@@ -29,6 +29,9 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
 import com.att.eelf.configuration.EELFLogger\r
 import com.att.eelf.configuration.EELFManager\r
+import com.fasterxml.jackson.databind.node.ObjectNode\r
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper\r
+\r
 /**\r
  *\r
  *\r
@@ -78,8 +81,8 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
     }\r
 \r
     open fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String,\r
-                                                    interfaceName: String, operationName: String): MutableMap<String, Any?> {\r
-        log.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " +\r
+                                                         interfaceName: String, operationName: String): MutableMap<String, Any?> {\r
+        log.info("resolveNodeTemplateInterfaceOperationInputs for node template ({}),interface name ({}), " +\r
                 "operationName({})", nodeTemplateName, interfaceName, operationName)\r
 \r
         val propertyAssignmentValue: MutableMap<String, Any?> = hashMapOf()\r
@@ -117,17 +120,25 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
             // Set for Return of method\r
             propertyAssignmentValue[nodeTypePropertyName] = resolvedValue\r
         }\r
-        log.info("resolved input assignments for node template ({}), values ({})", nodeTemplateName, propertyAssignmentValue)\r
+        log.trace("resolved input assignments for node template ({}), values ({})", nodeTemplateName,\r
+                propertyAssignmentValue)\r
 \r
         return propertyAssignmentValue\r
     }\r
 \r
 \r
     open fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String,\r
-                                                     interfaceName: String, operationName: String, componentContext: MutableMap<String, Any?>) {\r
-        log.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " +\r
+                                                          interfaceName: String, operationName: String): MutableMap<String, Any?>  {\r
+        log.info("resolveNodeTemplateInterfaceOperationOutputs for node template ({}),interface name ({}), " +\r
                 "operationName({})", nodeTemplateName, interfaceName, operationName)\r
 \r
+        val propertyAssignmentValue: MutableMap<String, Any?> = hashMapOf()\r
+\r
+        val propertyAssignments: MutableMap<String, Any> =\r
+                bluePrintContext.nodeTemplateInterfaceOperationOutputs(nodeTemplateName, interfaceName, operationName) as? MutableMap<String, Any>\r
+                        ?: throw BluePrintException(String.format("failed to get output definitions for node template (%s), " +\r
+                                "interface name (%s), operationName(%s)", nodeTemplateName, interfaceName, operationName))\r
+\r
         val nodeTypeName = bluePrintContext.nodeTemplateByName(nodeTemplateName).type\r
 \r
         val nodeTypeInterfaceOperationOutputs: MutableMap<String, PropertyDefinition> =\r
@@ -138,21 +149,32 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
         // Iterate Node Type Properties\r
         nodeTypeInterfaceOperationOutputs.forEach { nodeTypePropertyName, nodeTypeProperty ->\r
 \r
-            val operationOutputPropertyName: String = StringBuilder().append(nodeTemplateName)\r
-                    .append(".").append(interfaceName)\r
-                    .append(".").append(operationName)\r
-                    .append(".").append(nodeTypePropertyName).toString()\r
-            // Get the Value from component context\r
-            val resolvedValue: JsonNode = componentContext[operationOutputPropertyName] as? JsonNode\r
-                    ?: NullNode.getInstance()\r
+            // Get the Express or Value for the Node Template\r
+            val propertyAssignment: Any? = propertyAssignments[nodeTypePropertyName]\r
+\r
+            var resolvedValue: JsonNode = NullNode.getInstance()\r
+            if (propertyAssignment != null) {\r
+                // Resolve the Expressing\r
+                val propertyAssignmentExpression = PropertyAssignmentService(context, this)\r
+                resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment)\r
+            } else {\r
+                // Assign default value to the Operation\r
+                nodeTypeProperty.defaultValue?.let {\r
+                    resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!)\r
+                }\r
+            }\r
+            // Set for Return of method\r
+            propertyAssignmentValue[nodeTypePropertyName] = resolvedValue\r
+\r
             // Store  operation output values into context\r
-            setNodeTemplateOperationPropertyValue(nodeTemplateName, interfaceName, operationName, nodeTypePropertyName, resolvedValue)\r
-            log.debug("resolved output assignments for node template ({}), property name ({}), value ({})", nodeTemplateName, nodeTypePropertyName, resolvedValue)\r
+            setNodeTemplateOperationOutputValue(nodeTemplateName, interfaceName, operationName, nodeTypePropertyName, resolvedValue)\r
+            log.trace("resolved output assignments for node template ({}), property name ({}), value ({})", nodeTemplateName, nodeTypePropertyName, resolvedValue)\r
         }\r
+        return propertyAssignmentValue\r
     }\r
 \r
     open fun resolveNodeTemplateArtifact(nodeTemplateName: String,\r
-                                    artifactName: String): String {\r
+                                         artifactName: String): String {\r
         val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName)\r
 \r
         val artifactDefinition: ArtifactDefinition = nodeTemplate.artifacts?.get(artifactName)\r
@@ -186,8 +208,16 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
         context[path] = value\r
     }\r
 \r
+    open fun setNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String, value: JsonNode) {\r
+\r
+        val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString()\r
+        context[path] = value\r
+    }\r
+\r
     open fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,\r
-                                              value: JsonNode) {\r
+                                                   value: JsonNode) {\r
         val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName)\r
@@ -198,10 +228,10 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
     }\r
 \r
     open fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,\r
-                                           value: JsonNode) {\r
+                                                value: JsonNode) {\r
         val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
-                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName)\r
-                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()\r
@@ -209,10 +239,10 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
     }\r
 \r
     open fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String,\r
-                                            value: JsonNode) {\r
+                                                 value: JsonNode) {\r
         val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
-                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName)\r
-                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()\r
@@ -230,19 +260,27 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
         val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName)\r
-                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS).append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()\r
         return context[path] as JsonNode\r
     }\r
 \r
-    open fun getPropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? {\r
+    open fun getNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? {\r
         val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString()\r
         return context[path] as JsonNode\r
     }\r
 \r
-    open fun getRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName: String): JsonNode? {\r
+    open fun getNodeTemplateAttributeValue(nodeTemplateName: String, attributeName: String): JsonNode? {\r
+        val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(attributeName).toString()\r
+        return context[path] as JsonNode\r
+    }\r
+\r
+    open fun getNodeTemplateRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName:\r
+    String): JsonNode? {\r
         val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_REQUIREMENTS).append(requirementName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)\r
@@ -250,7 +288,8 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
         return context[path] as JsonNode\r
     }\r
 \r
-    open fun getCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName: String): JsonNode? {\r
+    open fun getNodeTemplateCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName:\r
+    String): JsonNode? {\r
         val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_CAPABILITIES).append(capabilityName)\r
                 .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES)\r
@@ -275,4 +314,24 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
             setWorkflowInputValue(workflowName, propertyName, valueNode)\r
         }\r
     }\r
+\r
+    open fun getJsonForNodeTemplateAttributeProperties(nodeTemplateName: String, keys: List<String>): JsonNode {\r
+\r
+        val jsonNode: ObjectNode = jacksonObjectMapper().createObjectNode()\r
+        val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName)\r
+                .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_ATTRIBUTES)\r
+                .append(BluePrintConstants.PATH_DIVIDER).toString()\r
+        context.keys.filter {\r
+            it.startsWith(path)\r
+        }.map {\r
+            val key = it.replace(path, "")\r
+            if (keys.contains(key)) {\r
+                val value = context[it] as JsonNode\r
+                jsonNode.set(key, value)\r
+            }\r
+        }\r
+        return jsonNode\r
+    }\r
+\r
+\r
 }
\ No newline at end of file
index ece09d6..131bb30 100644 (file)
@@ -20,6 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service
 \r
 import com.fasterxml.jackson.databind.JsonNode\r
 import com.fasterxml.jackson.databind.node.NullNode\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*\r
 import org.onap.ccsdk.apps.controllerblueprints.core.format\r
@@ -27,6 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.ResourceResolverUtils\r
 import com.att.eelf.configuration.EELFLogger\r
 import com.att.eelf.configuration.EELFManager\r
+\r
 /**\r
  *\r
  *\r
@@ -42,11 +44,11 @@ class PropertyAssignmentService(var context: MutableMap<String, Any>,
 \r
 If Property Assignment is Expression.\r
     Get the Expression\r
-    Recurssely resolve the expression\r
+    Recursively resolve the expression\r
  */\r
 \r
     fun resolveAssignmentExpression(nodeTemplateName: String, assignmentName: String,\r
-                                            assignment: Any): JsonNode {\r
+                                    assignment: Any): JsonNode {\r
         val valueNode: JsonNode\r
         log.trace("Assignment ({})", assignment)\r
         val expressionData = BluePrintExpressionService.getExpressionData(assignment)\r
@@ -63,30 +65,30 @@ If Property Assignment is Expression.
 \r
         var valueNode: JsonNode = NullNode.getInstance()\r
 \r
-        if(expressionData.isExpression) {\r
+        if (expressionData.isExpression) {\r
             val command = expressionData.command!!\r
 \r
-            when(command){\r
-                org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_INPUT ->{\r
+            when (command) {\r
+                BluePrintConstants.EXPRESSION_GET_INPUT -> {\r
                     valueNode = bluePrintRuntimeService.getInputValue(expressionData.inputExpression?.propertyName!!)\r
                 }\r
-                org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ATTRIBUTE ->{\r
+                BluePrintConstants.EXPRESSION_GET_ATTRIBUTE -> {\r
                     valueNode = resolveAttributeExpression(nodeTemplateName, expressionData.attributeExpression!!)\r
                 }\r
-                org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_PROPERTY ->{\r
+                BluePrintConstants.EXPRESSION_GET_PROPERTY -> {\r
                     valueNode = resolvePropertyExpression(nodeTemplateName, expressionData.propertyExpression!!)\r
                 }\r
-                org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT ->{\r
+                BluePrintConstants.EXPRESSION_GET_OPERATION_OUTPUT -> {\r
                     valueNode = resolveOperationOutputExpression(nodeTemplateName, expressionData.operationOutputExpression!!)\r
                 }\r
-                org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_ARTIFACT ->{\r
+                BluePrintConstants.EXPRESSION_GET_ARTIFACT -> {\r
                     valueNode = resolveArtifactExpression(nodeTemplateName, expressionData.artifactExpression!!)\r
                 }\r
-                org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE ->{\r
+                BluePrintConstants.EXPRESSION_GET_NODE_OF_TYPE -> {\r
 \r
                 }\r
-                else ->{\r
-                    throw BluePrintException(String.format("for property ({}), command ({}) is not supported ", propName, command))\r
+                else -> {\r
+                    throw BluePrintException(format("for property ({}), command ({}) is not supported ", propName, command))\r
                 }\r
             }\r
         }\r
@@ -104,20 +106,30 @@ If Property Assignment is Expression.
         val subAttributeName: String? = attributeExpression.subAttributeName\r
 \r
         var attributeNodeTemplateName = nodeTemplateName\r
-        if (!attributeExpression.modelableEntityName.equals("SELF", true)) {\r
-            attributeNodeTemplateName = attributeExpression.modelableEntityName\r
-        }\r
-\r
-        val nodeTemplateAttributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName)\r
-                ?: throw BluePrintException(String.format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, attributeName))\r
+        when (attributeExpression.modelableEntityName) {\r
+            "ENV" -> {\r
+                val environmentValue = System.getProperty(attributeName)\r
+                valueNode = JacksonUtils.jsonNode(environmentValue)\r
+            }\r
+            else -> {\r
+                if (!attributeExpression.modelableEntityName.equals("SELF", true)) {\r
+                    attributeNodeTemplateName = attributeExpression.modelableEntityName\r
+                }\r
+                /* Enable in ONAP Dublin Release\r
+                val nodeTemplateAttributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName)\r
+                        ?: throw BluePrintException(format("failed to get attribute definitions for node template " +\r
+                                "({})'s property name ({}) ", nodeTemplateName, attributeName))\r
 \r
-        var propertyDefinition: AttributeDefinition = bluePrintContext.nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)!!\r
+                var attributeDefinition: AttributeDefinition = bluePrintContext.nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)!!\r
 \r
-        log.info("node template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression)\r
+                log.info("node template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression)\r
+                */\r
 \r
-        // Check it it is a nested expression\r
-        valueNode = resolveAssignmentExpression(attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression)\r
+                valueNode = bluePrintRuntimeService.getNodeTemplateAttributeValue(attributeNodeTemplateName, attributeName)\r
+                        ?: throw BluePrintException(format("failed to get node template ({})'s attribute ({}) ", nodeTemplateName, attributeName))\r
+            }\r
 \r
+        }\r
 //        subPropertyName?.let {\r
 //            valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName))\r
 //        }\r
@@ -171,7 +183,7 @@ If Property Assignment is Expression.
     /*\r
     get_artifact: [ <modelable_entity_name>, <artifact_name>, <location>, <remove> ]\r
      */\r
-    fun resolveArtifactExpression(nodeTemplateName: String,  artifactExpression: ArtifactExpression): JsonNode {\r
+    fun resolveArtifactExpression(nodeTemplateName: String, artifactExpression: ArtifactExpression): JsonNode {\r
 \r
         var artifactNodeTemplateName = nodeTemplateName\r
         if (!artifactExpression.modelableEntityName.equals("SELF", true)) {\r
@@ -179,15 +191,15 @@ If Property Assignment is Expression.
         }\r
         val artifactDefinition: ArtifactDefinition = bluePrintContext.nodeTemplateByName(artifactNodeTemplateName)\r
                 .artifacts?.get(artifactExpression.artifactName)\r
-                ?: throw BluePrintException(String.format("failed to get artifact definitions for node template ({})'s " +\r
+                ?: throw BluePrintException(format("failed to get artifact definitions for node template ({})'s " +\r
                         "artifact name ({}) ", nodeTemplateName, artifactExpression.artifactName))\r
 \r
         return JacksonUtils.jsonNodeFromObject(artifactContent(artifactDefinition))\r
     }\r
 \r
     fun artifactContent(artifactDefinition: ArtifactDefinition): String {\r
-        val bluePrintBasePath: String = context[org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] as? String\r
-                ?: throw BluePrintException(String.format("failed to get property (%s) from context", org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH))\r
+        val bluePrintBasePath: String = context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] as? String\r
+                ?: throw BluePrintException(format("failed to get property (%s) from context", BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH))\r
 \r
         if (artifactDefinition.repository != null) {\r
             TODO()\r
index 277ec3a..f1980d2 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -17,7 +18,6 @@
 package org.onap.ccsdk.apps.controllerblueprints.core.service\r
 \r
 import com.fasterxml.jackson.databind.JsonNode\r
-import com.fasterxml.jackson.databind.node.NullNode\r
 import org.junit.Before\r
 import org.junit.Test\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
@@ -48,12 +48,8 @@ class BluePrintRuntimeServiceTest {
     @Test\r
     fun testResolveNodeTemplateProperties() {\r
         log.info("************************ testResolveNodeTemplateProperties **********************")\r
-        val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
-                .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)\r
 \r
-        val context: MutableMap<String, Any> = hashMapOf()\r
-        context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")\r
-        val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)\r
+        val bluePrintRuntimeService = getBluePrintRuntimeService()\r
 \r
         val inputDataPath = "src/test/resources/data/default-context.json"\r
 \r
@@ -99,31 +95,59 @@ class BluePrintRuntimeServiceTest {
     @Test\r
     fun testResolveNodeTemplateInterfaceOperationOutputs() {\r
         log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")\r
-        val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
-                .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)\r
-        assertNotNull(bluePrintContext, "Failed to populate Blueprint context")\r
-\r
-        val context: MutableMap<String, Any> = hashMapOf()\r
-        context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")\r
 \r
-        val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)\r
+        val bluePrintRuntimeService = getBluePrintRuntimeService()\r
 \r
-        val componentContext: MutableMap<String, Any?> = hashMapOf()\r
         val successValue: JsonNode = jsonNodeFromObject("Success")\r
-        componentContext["resource-assignment-ra-component.org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode.process.status"] = successValue\r
-        componentContext["resource-assignment-ra-component.org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode.process.resource-assignment-params"] = null\r
+        val paramValue: JsonNode = jsonNodeFromObject("param-content")\r
+\r
+        bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "params", paramValue)\r
 \r
         bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment-ra-component",\r
-                "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process", componentContext)\r
+                "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process")\r
 \r
-        assertEquals(NullNode.instance,\r
-                context.get("node_templates/resource-assignment-ra-component/interfaces/org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode/operations/process/properties/resource-assignment-params"),\r
-                "Failed to get operation property resource-assignment-params")\r
+        val resourceAssignmentParamsNode = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment-ra-component",\r
+                "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process", "resource-assignment-params")\r
 \r
-        assertEquals(successValue,\r
-                context.get("node_templates/resource-assignment-ra-component/interfaces/org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode/operations/process/properties/status"),\r
-                "Failed to get operation property status")\r
+        val statusNode = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment-ra-component",\r
+                "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process", "status")\r
+\r
+        assertEquals(paramValue, resourceAssignmentParamsNode, "Failed to get operation property resource-assignment-params")\r
+\r
+        assertEquals(successValue, statusNode, "Failed to get operation property status")\r
 \r
 \r
     }\r
+\r
+    @Test\r
+    fun testNodeTemplateContextProperty() {\r
+        log.info("************************ testNodeTemplateContextProperty **********************")\r
+        val bluePrintRuntimeService = getBluePrintRuntimeService()\r
+\r
+        bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1",\r
+                jsonNodeFromObject("context1-value"))\r
+        bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",\r
+                jsonNodeFromObject("context2-value"))\r
+\r
+        log.info("Context {}", bluePrintRuntimeService.context)\r
+\r
+        val keys = listOf("context1", "context2")\r
+\r
+        val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)\r
+        assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")\r
+        log.info("JSON Prepared Value Context {}", jsonValueNode)\r
+\r
+    }\r
+\r
+    private fun getBluePrintRuntimeService(): BluePrintRuntimeService {\r
+        val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
+                .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)\r
+        assertNotNull(bluePrintContext, "Failed to populate Blueprint context")\r
+\r
+        val context: MutableMap<String, Any> = hashMapOf()\r
+        context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")\r
+\r
+        return BluePrintRuntimeService(bluePrintContext, context)\r
+    }\r
+\r
 }
\ No newline at end of file