Implement Blueprint Workflow Enhancement
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Thu, 13 Dec 2018 16:34:49 +0000 (11:34 -0500)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Thu, 13 Dec 2018 16:34:49 +0000 (11:34 -0500)
Change-Id: I64d6e949e9a4bc2100b49fedb3781b04c1c03f43
Issue-ID: CCSDK-722
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt
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/utils/BluePrintFileUtils.kt
components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/activation-blueprint.json
components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/data_types.json
components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/node_types.json
components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/policy_types.json [new file with mode: 0644]
components/model-catalog/definition-type/starter-type/node_type/dg-generic.json

index 167496e..fd6a8db 100644 (file)
@@ -55,6 +55,7 @@ object BluePrintConstants {
     const val PATH_TOPOLOGY_TEMPLATE: String = "topology_template"\r
     const val PATH_METADATA: String = "metadata"\r
     const val PATH_NODE_TYPES: String = "node_types"\r
+    const val PATH_POLICY_TYPES: String = "policy_types"\r
     const val PATH_ARTIFACT_TYPES: String = "artifact_types"\r
     const val PATH_DATA_TYPES: String = "data_types"\r
     const val PATH_INPUTS: String = "inputs"\r
index cb835d7..f6659e7 100644 (file)
 
 package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
 
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
 
 interface BluePrintEnhancer<T> {
-    fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: T)
+    fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
 }
 
 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
@@ -49,9 +49,6 @@ interface BluePrintEnhancerService {
 
     @Throws(BluePrintException::class)
     fun enhance(basePath: String): BluePrintContext
-
-    @Throws(BluePrintException::class)
-    fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate
 }
 
 interface BluePrintTypeEnhancerService {
@@ -72,63 +69,63 @@ interface BluePrintTypeEnhancerService {
 
     fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
 
-    fun enhanceServiceTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, serviceTemplate: ServiceTemplate) {
+    fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
         val enhancers = getServiceTemplateEnhancers()
-        doEnhancement(bluePrintContext, error, name, serviceTemplate, enhancers)
+        doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
     }
 
-    fun enhanceTopologyTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, topologyTemplate: TopologyTemplate) {
+    fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
         val enhancers = getTopologyTemplateEnhancers()
-        doEnhancement(bluePrintContext, error, name, topologyTemplate, enhancers)
+        doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
     }
 
-    fun enhanceWorkflow(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, workflow: Workflow) {
+    fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
         val enhancers = getWorkflowEnhancers()
-        doEnhancement(bluePrintContext, error, name, workflow, enhancers)
+        doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
     }
 
-    fun enhanceNodeTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeTemplate: NodeTemplate) {
+    fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
         val enhancers = getNodeTemplateEnhancers()
-        doEnhancement(bluePrintContext, error, name, nodeTemplate, enhancers)
+        doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
     }
 
-    fun enhanceNodeType(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeType: NodeType) {
+    fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
         val enhancers = getNodeTypeEnhancers()
-        doEnhancement(bluePrintContext, error, name, nodeType, enhancers)
+        doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
     }
 
-    fun enhancePolicyType(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, policyType: PolicyType) {
+    fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
         val enhancers = getPolicyTypeEnhancers()
-        doEnhancement(bluePrintContext, error, name, policyType, enhancers)
+        doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
     }
 
-    fun enhancePropertyDefinitions(bluePrintContext: BluePrintContext, error: BluePrintError, properties: MutableMap<String, PropertyDefinition>) {
+    fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
         properties.forEach { propertyName, propertyDefinition ->
-            enhancePropertyDefinition(bluePrintContext, error, propertyName, propertyDefinition)
+            enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
         }
     }
 
-    fun enhancePropertyDefinition(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, propertyDefinition: PropertyDefinition) {
+    fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
         val enhancers = getPropertyDefinitionEnhancers()
-        doEnhancement(bluePrintContext, error, name, propertyDefinition, enhancers)
+        doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
     }
 
-    fun enhanceAttributeDefinitions(bluePrintContext: BluePrintContext, error: BluePrintError, attributes: MutableMap<String, AttributeDefinition>) {
+    fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
         attributes.forEach { attributeName, attributeDefinition ->
-            enhanceAttributeDefinition(bluePrintContext, error, attributeName, attributeDefinition)
+            enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
         }
     }
 
-    fun enhanceAttributeDefinition(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, attributeDefinition: AttributeDefinition) {
+    fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
         val enhancers = getAttributeDefinitionEnhancers()
-        doEnhancement(bluePrintContext, error, name, attributeDefinition, enhancers)
+        doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
     }
 
     @Suppress("UNCHECKED_CAST")
-    private fun <T> doEnhancement(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
+    private fun <T> doEnhancement(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
         if (enhancers.isNotEmpty()) {
             enhancers.forEach {
-                it.enhance(bluePrintContext, error, name, definition as T)
+                it.enhance(bluePrintRuntimeService, name, definition as T)
             }
         }
     }
index 448a06a..cf518bd 100644 (file)
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.node.NullNode
 import com.fasterxml.jackson.databind.node.ObjectNode\r
 import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate\r
@@ -55,6 +56,10 @@ interface BluePrintRuntimeService<T> {
 \r
     fun getAsDouble(key: String): Double?\r
 \r
+    fun getBluePrintError(): BluePrintError\r
+\r
+    fun setBluePrintError(bluePrintError: BluePrintError)\r
+\r
     /*\r
       Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing\r
    */\r
@@ -113,6 +118,8 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
 \r
     private var store: MutableMap<String, JsonNode> = hashMapOf()\r
 \r
+    private var bluePrintError = BluePrintError()\r
+\r
     override fun id(): String {\r
         return id\r
     }\r
@@ -162,9 +169,17 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
         return get(key).asDouble()\r
     }\r
 \r
+    override fun getBluePrintError(): BluePrintError {\r
+        return this.bluePrintError\r
+    }\r
+\r
+    override fun setBluePrintError(bluePrintError: BluePrintError) {\r
+        this.bluePrintError = bluePrintError\r
+    }\r
+\r
     /*\r
-            Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing\r
-         */\r
+                Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing\r
+             */\r
     override fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap<String, JsonNode> {\r
         log.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName)\r
         val propertyAssignmentValue: MutableMap<String, JsonNode> = hashMapOf()\r
@@ -439,11 +454,11 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
                 setInputValue(propertyName, property, valueNode)\r
             }\r
         }\r
-\r
+        // Load Dynamic data Types\r
         val workflowDynamicInputs: JsonNode? = jsonNode.get(dynamicInputPropertiesName)\r
 \r
         workflowDynamicInputs?.let {\r
-            bluePrintContext.dataTypeByName(dynamicInputPropertiesName)?.properties?.forEach { propertyName, property ->\r
+            bluePrintContext.dataTypeByName("dt-$dynamicInputPropertiesName")?.properties?.forEach { propertyName, property ->\r
                 val valueNode: JsonNode = workflowDynamicInputs.at(BluePrintConstants.PATH_DIVIDER + propertyName)\r
                         ?: NullNode.getInstance()\r
                 setInputValue(propertyName, property, valueNode)\r
index d9222d7..4cb247b 100644 (file)
@@ -89,25 +89,37 @@ class BluePrintFileUtils {
                 throw BluePrintException("couldn't get definition file under path(${definitionDir.absolutePath})")
             }
 
-            blueprintContext.dataTypes.let {
-                val dataTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_DATA_TYPES, blueprintContext.dataTypes!!, true)
-                writeFile(definitionDir.absolutePath, BluePrintConstants.PATH_DATA_TYPES, dataTypesContent)
+            blueprintContext.serviceTemplate.dataTypes?.let {
+                val dataTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_DATA_TYPES, it, true)
+                writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_DATA_TYPES, dataTypesContent)
+            }
 
+            blueprintContext.serviceTemplate.artifactTypes?.let {
+                val artifactTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_ARTIFACT_TYPES, it, true)
+                writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_ARTIFACT_TYPES, artifactTypesContent)
             }
 
-            blueprintContext.artifactTypes.let {
-                val artifactTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_ARTIFACT_TYPES, blueprintContext.artifactTypes!!, true)
-                writeFile(definitionDir.absolutePath, BluePrintConstants.PATH_ARTIFACT_TYPES, artifactTypesContent)
+            blueprintContext.serviceTemplate.nodeTypes?.let {
+                val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_NODE_TYPES, it, true)
+                writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_NODE_TYPES, nodeTypesContent)
             }
 
-            blueprintContext.nodeTypes.let {
-                val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_NODE_TYPES, blueprintContext.nodeTypes!!, true)
-                writeFile(definitionDir.absolutePath, BluePrintConstants.PATH_NODE_TYPES, nodeTypesContent)
+            blueprintContext.serviceTemplate.policyTypes?.let {
+                val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_POLICY_TYPES, it, true)
+                writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_POLICY_TYPES, nodeTypesContent)
             }
+        }
 
+        fun writeDefinitionFile(definitionFile: String, content: String) = runBlocking {
+            val definitionFile = File(definitionFile)
+
+            Files.write(definitionFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE)
+            check(definitionFile.exists()) {
+                throw BluePrintException("couldn't write definition file under path(${definitionFile.absolutePath})")
+            }
         }
 
-        private fun writeFile(definitionPath: String, type: String, content: String) = runBlocking {
+        private fun writeTypeFile(definitionPath: String, type: String, content: String) = runBlocking {
             val typeFile = File(definitionPath.plus(File.separator).plus("$type.json"))
 
             Files.write(typeFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)
index f756ef7..ec229df 100644 (file)
     {
       "file": "Definitions/data_types.json"
     },
+    {
+      "file": "Definitions/artifact_types.json"
+    },
     {
       "file": "Definitions/node_types.json"
     },
     {
-      "file": "Definitions/artifact_types.json"
+      "file": "Definitions/policy_types.json"
     }
   ],
   "topology_template": {
               "SELF",
               "dg-resource-assignment-process"
             ]
-          }
+          },
+          "dependency-node-templates": [
+            "resource-assignment"
+          ]
         },
         "artifacts": {
           "dg-resource-assignment-process": {
               "SELF",
               "dg-activate-process"
             ]
-          }
+          },
+          "dependency-node-templates": [
+            "activate-jython"
+          ]
         },
         "artifacts": {
           "dg-activate-process": {
               "SELF",
               "dg-assign-activate-process"
             ]
-          }
+          },
+          "dependency-node-templates": [
+            "resource-assignment",
+            "activate-jython"
+          ]
         },
         "artifacts": {
           "dg-assign-activate-process": {
         "inputs": {
           "resource-assignment-properties": {
             "required": true,
-            "type": "resource-assignment-properties"
+            "type": "dt-resource-assignment-properties"
           }
         },
         "steps": {
       },
       "activate": {
         "inputs": {
-          "activate-properties": {
+          "request-id": {
+            "required": true,
+            "type": "string"
+          },
+          "action-name": {
+            "required": true,
+            "type": "string"
+          },
+          "scope-type": {
+            "required": true,
+            "type": "string"
+          },
+          "hostname": {
             "required": true,
-            "type": "activate-properties"
+            "type": "string"
           }
         },
         "steps": {
         "inputs": {
           "assign-activate-properties": {
             "required": true,
-            "type": "assign-activate-properties"
+            "type": "dt-assign-activate-properties"
           }
         },
         "steps": {
index 3ea494a..7d850f2 100644 (file)
@@ -20,7 +20,7 @@
       },
       "derived_from": "tosca.datatypes.Root"
     },
-    "activate-properties": {
+    "dt-resource-assignment-properties": {
       "description": "This is Dynamically generated data type for workflow activate",
       "version": "1.0.0",
       "properties": {
       },
       "derived_from": "tosca.datatypes.Dynamic"
     },
-    "resource-assignment-properties": {
-      "description": "This is Dynamically generated data type for workflow activate",
-      "version": "1.0.0",
-      "properties": {
-        "request-id": {
-          "required": true,
-          "type": "string"
-        },
-        "action-name": {
-          "required": true,
-          "type": "string"
-        },
-        "scope-type": {
-          "required": true,
-          "type": "string"
-        },
-        "hostname": {
-          "required": true,
-          "type": "string"
-        }
-      },
-      "derived_from": "tosca.datatypes.Dynamic"
-    },
-    "assign-activate-properties": {
+    "dt-assign-activate-properties": {
       "description": "This is Dynamically generated data type for workflow assign-activate",
       "version": "1.0.0",
       "properties": {
index 8227b82..8f242ef 100644 (file)
@@ -7,6 +7,14 @@
         "content": {
           "required": true,
           "type": "string"
+        },
+        "dependency-node-templates": {
+          "required": true,
+          "description": "Dependent Step Components",
+          "type": "list",
+          "entry_schema": {
+            "type": "string"
+          }
         }
       },
       "derived_from": "tosca.nodes.DG"
diff --git a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/policy_types.json b/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/policy_types.json
new file mode 100644 (file)
index 0000000..0c9b992
--- /dev/null
@@ -0,0 +1,4 @@
+{
+  "policy_types": {
+  }
+}
\ No newline at end of file
index 6274445..ec9904b 100644 (file)
@@ -5,6 +5,14 @@
     "content": {
       "required": true,
       "type": "string"
+    },
+    "dependency-node-templates": {
+      "required": true,
+      "description": "Dependent Step Components NodeTemplate name.",
+      "type": "list",
+      "entry_schema": {
+        "type": "string"
+      }
     }
   },
   "derived_from": "tosca.nodes.DG"