Get DSL Property in Resource Resolution
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Mon, 25 Feb 2019 21:03:16 +0000 (16:03 -0500)
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Fri, 1 Mar 2019 20:54:08 +0000 (15:54 -0500)
Change-Id: I768c2515bc4b0eaa829213ac4d045628ca960adb
Issue-ID: CCSDK-1106
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt

index 2c2e67d..e3545df 100644 (file)
@@ -159,7 +159,11 @@ object BluePrintConstants {
     const val TOSCA_SCRIPTS_KOTLIN_DIR: String = "$TOSCA_SCRIPTS_DIR/kotlin"
     const val TOSCA_SCRIPTS_JYTHON_DIR: String = "$TOSCA_SCRIPTS_DIR/python"
 
-    const val METADATA_USER_GROUPS = "user-groups"
+    const val PROPERTY_ENV = "ENV"
+    const val PROPERTY_APP = "APP"
+    const val PROPERTY_BPP = "BPP"
+    const val PROPERTY_SELF = "SELF"
+
     const val METADATA_TEMPLATE_NAME = "template_name"
     const val METADATA_TEMPLATE_VERSION = "template_version"
     const val METADATA_TEMPLATE_AUTHOR = "template_author"
@@ -174,11 +178,5 @@ object BluePrintConstants {
     const val PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation"
     const val PROPERTY_EXECUTION_REQUEST = "execution-request"
 
-    const val OPERATION_PROCESS = "process"
-    const val OPERATION_PREPARE = "prepare"
-
-    const val BLUEPRINT_RETRIEVE_TYPE_DB = "db"
-    const val BLUEPRINT_RETRIEVE_TYPE_FILE = "file"
-    const val BLUEPRINT_RETRIEVE_TYPE_REPO = "repo"
 
 }
\ No newline at end of file
index f8ac5d6..80ad3f2 100644 (file)
@@ -62,7 +62,7 @@ interface BluePrintRuntimeService<T> {
 
     fun setBluePrintError(bluePrintError: BluePrintError)
 
-    fun loadEnvironments(fileName: String)
+    fun loadEnvironments(type: String, fileName: String)
 
     fun resolveNodeTemplatePropertyAssignments(nodeTemplateName: String,
                                                propertyDefinitions: MutableMap<String, PropertyDefinition>,
@@ -135,11 +135,11 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
 
     init {
         /**
-         * Load Default Environments Properties
+         * Load Blueprint Environments Properties
          */
         val absoluteEnvFilePath = bluePrintContext.rootPath.plus(File.separator)
                 .plus(BluePrintConstants.TOSCA_ENVIRONMENTS_DIR)
-        loadEnvironments(absoluteEnvFilePath)
+        loadEnvironments(BluePrintConstants.PROPERTY_BPP, absoluteEnvFilePath)
 
     }
 
@@ -204,9 +204,10 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
         this.bluePrintError = bluePrintError
     }
 
-    override fun loadEnvironments(fileName: String) {
+    override fun loadEnvironments(type: String, fileName: String) {
         BluePrintMetadataUtils.environmentFileProperties(fileName).forEach { key, value ->
-            setNodeTemplateAttributeValue("ENV", key.toString(), value.toString().asJsonPrimitive())
+            setNodeTemplateAttributeValue(type, key.toString(), value.toString()
+                    .asJsonPrimitive())
         }
     }
 
index ae4f40b..7905b8f 100644 (file)
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.node.NullNode
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
 import org.onap.ccsdk.apps.controllerblueprints.core.format
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
@@ -109,13 +110,27 @@ If Property Assignment is Expression.
         val subAttributeName: String? = attributeExpression.subAttributeName
 
         var attributeNodeTemplateName = nodeTemplateName
+        /**
+         * Attributes are dynamic runtime properties information. There are multiple types of Attributes,
+         * ENV : Environment Variables
+         * APP : Application properties ( ie Spring resolved properties )
+         * BPP : Blueprint Properties, Specific to Blue Print execution.
+         * SELF : Current Node Template properties.
+         */
         when (attributeExpression.modelableEntityName) {
-            "ENV" -> {
+            BluePrintConstants.PROPERTY_ENV -> {
                 val environmentValue = System.getProperty(attributeName)
-                valueNode = JacksonUtils.jsonNode(environmentValue)
+                valueNode = environmentValue.asJsonPrimitive()
+            }
+            BluePrintConstants.PROPERTY_APP -> {
+                TODO("Get property from application properties")
+            }
+            BluePrintConstants.PROPERTY_BPP -> {
+                valueNode = bluePrintRuntimeService.getNodeTemplateAttributeValue(BluePrintConstants.PROPERTY_BPP, attributeName)
+                        ?: throw BluePrintException("failed to get env attribute name ($attributeName) ")
             }
             else -> {
-                if (!attributeExpression.modelableEntityName.equals("SELF", true)) {
+                if (!attributeExpression.modelableEntityName.equals(BluePrintConstants.PROPERTY_SELF, true)) {
                     attributeNodeTemplateName = attributeExpression.modelableEntityName
                 }
 
@@ -146,7 +161,8 @@ If Property Assignment is Expression.
         val subPropertyName: String? = propertyExpression.subPropertyName
 
         var propertyNodeTemplateName = nodeTemplateName
-        if (!propertyExpression.modelableEntityName.equals("SELF", true)) {
+
+        if (!propertyExpression.modelableEntityName.equals(BluePrintConstants.PROPERTY_SELF, true)) {
             propertyNodeTemplateName = propertyExpression.modelableEntityName
         }