Add blueprint domain DSL 94/90094/4
authorBrinda Santh <brindasanth@in.ibm.com>
Mon, 10 Jun 2019 19:50:23 +0000 (15:50 -0400)
committerBrinda Santh <brindasanth@in.ibm.com>
Tue, 25 Jun 2019 18:07:03 +0000 (14:07 -0400)
Change-Id: Id9f64605fa74f54d43af55357a521cf347fa8677
Issue-ID: CCSDK-1380
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLBuilder.kt [new file with mode: 0644]
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLData.kt [new file with mode: 0644]
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt
ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt

index 9a652fb..786bcd3 100644 (file)
@@ -180,6 +180,8 @@ object BluePrintConstants {
     const val PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation"
     const val PROPERTY_EXECUTION_REQUEST = "execution-request"
 
+    const val DEFAULT_STEP_OPERATION = "process"
+
     const val ARTIFACT_VELOCITY_TYPE_NAME = "artifact-template-velocity"
     const val ARTIFACT_JINJA_TYPE_NAME = "artifact-template-jinja"
 }
\ No newline at end of file
index 4f2b7a1..a508c8f 100644 (file)
@@ -34,6 +34,10 @@ fun String.isJson(): Boolean {
             || (this.startsWith("[") && this.endsWith("]")))
 }
 
+fun Any.asJsonString(intend: Boolean? = false): String {
+    return JacksonUtils.getJson(this, true)
+}
+
 fun String.asJsonPrimitive(): TextNode {
     return TextNode(this)
 }
index 745671a..9e934c7 100644 (file)
@@ -192,6 +192,9 @@ class AttributeDefinition {
     var constraints: MutableList<ConstraintClause>? = null
     @JsonProperty("entry_schema")
     var entrySchema: EntrySchema? = null
+    // Mainly used in DSL definitions
+    @get:ApiModelProperty(notes = "Attribute Value, It may be Expression or Json type values")
+    var value: JsonNode? = null
 }
 
 /*
index 4878cb6..95303ea 100644 (file)
 package org.onap.ccsdk.cds.controllerblueprints.core.dsl
 
 import com.fasterxml.jackson.databind.JsonNode
-import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
+import org.onap.ccsdk.cds.controllerblueprints.core.data.*
 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
 
+// CDS DSLs
+fun blueprint(name: String, version: String, author: String, tags: String,
+              block: DSLBluePrintBuilder.() -> Unit): DSLBluePrint {
+    return DSLBluePrintBuilder(name, version, author, tags).apply(block).build()
+}
+
+// TOSCA DSLs
 fun serviceTemplate(name: String, version: String, author: String, tags: String,
                     block: ServiceTemplateBuilder.() -> Unit): ServiceTemplate {
     return ServiceTemplateBuilder(name, version, author, tags).apply(block).build()
 }
 
+fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit): Workflow {
+    return WorkflowBuilder(id, description).apply(block).build()
+}
+
+fun nodeTemplate(id: String, type: String, description: String,
+                 block: NodeTemplateBuilder.() -> Unit): NodeTemplate {
+    return NodeTemplateBuilder(id, type, description).apply(block).build()
+}
+
+fun nodeType(id: String, version: String, derivedFrom: String, description: String,
+             block: NodeTypeBuilder.() -> Unit): NodeType {
+    return NodeTypeBuilder(id, version, derivedFrom, description).apply(block).build()
+}
+
+fun dataType(id: String, version: String, derivedFrom: String, description: String,
+             block: DataTypeBuilder.() -> Unit): DataType {
+    return DataTypeBuilder(id, version, derivedFrom, description).apply(block).build()
+}
+
+fun artifactType(id: String, version: String, derivedFrom: String, description: String,
+                 block: ArtifactTypeBuilder.() -> Unit): ArtifactType {
+    return ArtifactTypeBuilder(id, version, derivedFrom, description).apply(block).build()
+}
+
 // Input Function
 
 fun getInput(inputKey: String): JsonNode {
     return """{"get_input": "$inputKey"}""".jsonAsJsonType()
 }
 
-fun getAttribute(attributeName: String): JsonNode {
-    return """{"get_attribute": ["SELF", "$attributeName"]}""".jsonAsJsonType()
+fun getAttribute(attributeId: String): JsonNode {
+    return """{"get_attribute": ["SELF", "$attributeId"]}""".jsonAsJsonType()
 }
 
-fun getAttribute(attributeName: String, jsonPath: String): JsonNode {
-    return """{"get_attribute": ["SELF", "$attributeName", "$jsonPath"]}""".jsonAsJsonType()
+fun getAttribute(attributeId: String, jsonPath: String): JsonNode {
+    return """{"get_attribute": ["SELF", "$attributeId", "$jsonPath"]}""".jsonAsJsonType()
 }
 
-fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String): JsonNode {
-    return """{"get_attribute": ["$nodeTemplateName", "$attributeName"]}""".jsonAsJsonType()
+fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String): JsonNode {
+    return """{"get_attribute": ["$nodeTemplateId", "$attributeId"]}""".jsonAsJsonType()
 }
 
-fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String, jsonPath: String): JsonNode {
-    return """{"get_attribute": ["$nodeTemplateName", "$attributeName", "$jsonPath]}""".jsonAsJsonType()
+fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String, jsonPath: String): JsonNode {
+    return """{"get_attribute": ["$nodeTemplateId", "$attributeId", "$jsonPath]}""".jsonAsJsonType()
 }
 
 // Property Function
 
-fun getProperty(propertyName: String): JsonNode {
-    return """{"get_property": ["SELF", "$propertyName"]}""".jsonAsJsonType()
+fun getProperty(propertyId: String): JsonNode {
+    return """{"get_property": ["SELF", "$propertyId"]}""".jsonAsJsonType()
 }
 
-fun getProperty(propertyName: String, jsonPath: String): JsonNode {
-    return """{"get_property": ["SELF", "$propertyName", "$jsonPath"]}""".jsonAsJsonType()
+fun getProperty(propertyId: String, jsonPath: String): JsonNode {
+    return """{"get_property": ["SELF", "$propertyId", "$jsonPath"]}""".jsonAsJsonType()
 }
 
-fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String): JsonNode {
-    return """{"get_property": ["$nodeTemplateName", "$propertyName"]}""".jsonAsJsonType()
+fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String): JsonNode {
+    return """{"get_property": ["$nodeTemplateName", "$propertyId"]}""".jsonAsJsonType()
 }
 
-fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String, jsonPath: String): JsonNode {
-    return """{"get_property": ["$nodeTemplateName", "$propertyName", "$jsonPath]}""".jsonAsJsonType()
+fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String, jsonPath: String): JsonNode {
+    return """{"get_property": ["$nodeTemplateName", "$propertyId", "$jsonPath]}""".jsonAsJsonType()
 }
 
 // Artifact Function
 
-fun getArtifact(artifactName: String): JsonNode {
-    return """{"get_artifact": ["SELF", "$artifactName"]}""".jsonAsJsonType()
+fun getArtifact(artifactId: String): JsonNode {
+    return """{"get_artifact": ["SELF", "$artifactId"]}""".jsonAsJsonType()
 }
 
-fun getNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): JsonNode {
-    return """{"get_artifact": ["$nodeTemplateName", "$artifactName"]}""".jsonAsJsonType()
+fun getNodeTemplateArtifact(nodeTemplateName: String, artifactId: String): JsonNode {
+    return """{"get_artifact": ["$nodeTemplateName", "$artifactId"]}""".jsonAsJsonType()
 }
\ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLBuilder.kt
new file mode 100644 (file)
index 0000000..8cfa90b
--- /dev/null
@@ -0,0 +1,342 @@
+/*
+ *  Copyright © 2019 IBM.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.controllerblueprints.core.dsl
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
+import org.onap.ccsdk.cds.controllerblueprints.core.data.*
+
+/**
+ * @author Brinda Santh
+ */
+class DSLBluePrintBuilder(private val name: String,
+                          private val version: String,
+                          private val author: String,
+                          private val tags: String) {
+
+    private var dslBluePrint = DSLBluePrint()
+    private var metadata: MutableMap<String, String> = hashMapOf()
+    var properties: MutableMap<String, JsonNode>? = null
+    var dataType: MutableMap<String, DataType> = hashMapOf()
+    var artifacts: MutableMap<String, ArtifactDefinition> = hashMapOf()
+    var components: MutableMap<String, DSLComponent> = hashMapOf()
+    var workflows: MutableMap<String, DSLWorkflow> = hashMapOf()
+
+    private fun initMetaData() {
+        metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] = name
+        metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] = version
+        metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] = author
+        metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS] = tags
+    }
+
+    fun metadata(id: String, value: String) {
+        metadata[id] = value
+    }
+
+    fun property(id: String, expression: Any) {
+        if (properties == null)
+            properties = hashMapOf()
+        properties!![id] = expression.asJsonType()
+    }
+
+    fun dataType(id: String, version: String, derivedFrom: String, description: String,
+                 block: DataTypeBuilder.() -> Unit) {
+        dataType[id] = DataTypeBuilder(id, version, derivedFrom, description).apply(block).build()
+    }
+
+    fun component(id: String, type: String, version: String, description: String, block: DSLComponentBuilder.() -> Unit) {
+        components[id] = DSLComponentBuilder(id, type, version, description).apply(block).build()
+    }
+
+    fun workflow(id: String, description: String, block: DSLWorkflowBuilder.() -> Unit) {
+        workflows[id] = DSLWorkflowBuilder(id, description).apply(block).build()
+    }
+
+    fun build(): DSLBluePrint {
+        initMetaData()
+        dslBluePrint.metadata = metadata
+        dslBluePrint.properties = properties
+        dslBluePrint.dataType = dataType
+        dslBluePrint.components = components
+        dslBluePrint.workflows = workflows
+        return dslBluePrint
+    }
+}
+
+class DSLComponentBuilder(private val id: String, private val type: String,
+                          private val version: String, private val description: String) {
+    private val dslComponent = DSLComponent()
+    var properties: MutableMap<String, PropertyDefinition>? = null
+    var attributes: MutableMap<String, AttributeDefinition>? = null
+
+    // For already registered components
+    private var assignProperties: MutableMap<String, JsonNode>? = null
+
+    var artifacts: MutableMap<String, ArtifactDefinition>? = null
+    var implementation: Implementation? = null
+    var inputs: MutableMap<String, PropertyDefinition>? = null
+    var outputs: MutableMap<String, PropertyDefinition>? = null
+
+    // For already registered components
+    private var assignInputs: MutableMap<String, JsonNode>? = null
+    private var assignOutputs: MutableMap<String, JsonNode>? = null
+
+    fun attribute(id: String, type: String, required: Boolean, expression: Any, description: String? = "") {
+        if (attributes == null)
+            attributes = hashMapOf()
+        val attribute = DSLAttributeDefinitionBuilder(id, type, required, expression.asJsonType(), description).build()
+        attributes!![id] = attribute
+    }
+
+    fun attribute(id: String, type: String, required: Boolean, expression: Any, description: String? = "",
+                  block: DSLAttributeDefinitionBuilder.() -> Unit) {
+        if (attributes == null)
+            attributes = hashMapOf()
+        val attribute = DSLAttributeDefinitionBuilder(id, type, required, expression.asJsonType(), description)
+                .apply(block).build()
+        attributes!![id] = attribute
+    }
+
+    fun property(id: String, type: String, required: Boolean, expression: Any, description: String? = "") {
+        if (properties == null)
+            properties = hashMapOf()
+        val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description).build()
+        properties!![id] = property
+    }
+
+    fun property(id: String, type: String, required: Boolean, expression: Any, description: String? = "",
+                 block: DSLPropertyDefinitionBuilder.() -> Unit) {
+        if (properties == null)
+            properties = hashMapOf()
+        val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description)
+                .apply(block).build()
+        properties!![id] = property
+    }
+
+    fun assignProperty(id: String, expression: Any) {
+        if (assignProperties == null)
+            assignProperties = hashMapOf()
+        assignProperties!![id] = expression.asJsonType()
+    }
+
+    fun implementation(timeout: Int, operationHost: String? = BluePrintConstants.PROPERTY_SELF) {
+        implementation = Implementation().apply {
+            this.operationHost = operationHost!!
+            this.timeout = timeout
+        }
+    }
+
+    fun artifacts(id: String, type: String, file: String) {
+        if (artifacts == null)
+            artifacts = hashMapOf()
+        artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).build()
+    }
+
+    fun artifacts(id: String, type: String, file: String, block: ArtifactDefinitionBuilder.() -> Unit) {
+        if (artifacts == null)
+            artifacts = hashMapOf()
+        artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).apply(block).build()
+    }
+
+
+    fun input(id: String, type: String, required: Boolean, expression: Any, description: String? = "") {
+        if (inputs == null)
+            inputs = hashMapOf()
+        val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description)
+        inputs!![id] = property.build()
+    }
+
+    fun input(id: String, type: String, required: Boolean, expression: Any, description: String? = "",
+              block: DSLPropertyDefinitionBuilder.() -> Unit) {
+        if (inputs == null)
+            inputs = hashMapOf()
+        val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description)
+                .apply(block).build()
+        inputs!![id] = property
+    }
+
+    fun assignInput(id: String, expression: Any) {
+        if (assignInputs == null)
+            assignInputs = hashMapOf()
+        assignInputs!![id] = expression.asJsonType()
+    }
+
+    fun output(id: String, type: String, required: Boolean, expression: Any, description: String? = "") {
+        if (outputs == null)
+            outputs = hashMapOf()
+        val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description)
+        outputs!![id] = property.build()
+    }
+
+    fun output(id: String, type: String, required: Boolean, expression: Any, description: String? = "",
+               block: DSLPropertyDefinitionBuilder.() -> Unit) {
+        if (outputs == null)
+            outputs = hashMapOf()
+        val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description)
+                .apply(block).build()
+        outputs!![id] = property
+    }
+
+    fun assignOutput(id: String, expression: Any) {
+        if (assignOutputs == null)
+            assignOutputs = hashMapOf()
+        assignOutputs!![id] = expression.asJsonType()
+    }
+
+    fun build(): DSLComponent {
+        dslComponent.id = id
+        dslComponent.type = type
+        dslComponent.version = version
+        dslComponent.description = description
+        dslComponent.attributes = attributes
+        dslComponent.properties = properties
+        dslComponent.assignProperties = assignProperties
+        dslComponent.implementation = implementation
+        dslComponent.artifacts = artifacts
+        dslComponent.inputs = inputs
+        dslComponent.outputs = outputs
+        dslComponent.assignInputs = assignInputs
+        dslComponent.assignOutputs = assignOutputs
+        dslComponent.outputs = outputs
+
+        return dslComponent
+    }
+}
+
+class DSLWorkflowBuilder(private val actionName: String, private val description: String) {
+    private val dslWorkflow = DSLWorkflow()
+    private var steps: MutableMap<String, Step>? = null
+    private var inputs: MutableMap<String, PropertyDefinition>? = null
+    private var outputs: MutableMap<String, PropertyDefinition>? = null
+
+    fun input(id: String, type: String, required: Boolean, description: String? = "") {
+        if (inputs == null)
+            inputs = hashMapOf()
+        val property = PropertyDefinitionBuilder(id, type, required, description)
+        inputs!![id] = property.build()
+    }
+
+    fun input(id: String, type: String, required: Boolean, description: String, defaultValue: Any?,
+              block: PropertyDefinitionBuilder.() -> Unit) {
+        if (inputs == null)
+            inputs = hashMapOf()
+        val property = PropertyDefinitionBuilder(id, type, required, description).apply(block).build()
+        if (defaultValue != null)
+            property.defaultValue = defaultValue.asJsonType()
+        inputs!![id] = property
+    }
+
+    fun output(id: String, type: String, required: Boolean, expression: Any, description: String? = "") {
+        if (outputs == null)
+            outputs = hashMapOf()
+        val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description)
+        outputs!![id] = property.build()
+    }
+
+    fun output(id: String, type: String, required: Boolean, expression: Any, description: String? = "",
+               block: DSLPropertyDefinitionBuilder.() -> Unit) {
+        if (outputs == null)
+            outputs = hashMapOf()
+        val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description)
+                .apply(block).build()
+        outputs!![id] = property
+    }
+
+    fun step(id: String, target: String, description: String) {
+        if (steps == null)
+            steps = hashMapOf()
+        steps!![id] = StepBuilder(id, target, description).build()
+    }
+
+    fun step(id: String, target: String, description: String, block: StepBuilder.() -> Unit) {
+        if (steps == null)
+            steps = hashMapOf()
+        steps!![id] = StepBuilder(id, target, description).apply(block).build()
+    }
+
+    fun build(): DSLWorkflow {
+        dslWorkflow.actionName = actionName
+        dslWorkflow.description = description
+        dslWorkflow.inputs = inputs
+        dslWorkflow.outputs = outputs
+        dslWorkflow.steps = steps!!
+        return dslWorkflow
+    }
+}
+
+class DSLAttributeDefinitionBuilder(private val id: String,
+                                    private val type: String? = BluePrintConstants.DATA_TYPE_STRING,
+                                    private val required: Boolean? = false,
+                                    private val expression: JsonNode,
+                                    private val description: String? = "") {
+
+    private var attributeDefinition = AttributeDefinition()
+
+    fun entrySchema(entrySchemaType: String) {
+        attributeDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).build()
+    }
+
+    fun entrySchema(entrySchemaType: String, block: EntrySchemaBuilder.() -> Unit) {
+        attributeDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).apply(block).build()
+    }
+    // TODO("Constrains")
+
+    fun defaultValue(defaultValue: JsonNode) {
+        attributeDefinition.defaultValue = defaultValue
+    }
+
+    fun build(): AttributeDefinition {
+        attributeDefinition.id = id
+        attributeDefinition.type = type!!
+        attributeDefinition.required = required
+        attributeDefinition.value = expression
+        attributeDefinition.description = description
+        return attributeDefinition
+    }
+}
+
+class DSLPropertyDefinitionBuilder(private val id: String,
+                                   private val type: String? = BluePrintConstants.DATA_TYPE_STRING,
+                                   private val required: Boolean? = false,
+                                   private val expression: JsonNode,
+                                   private val description: String? = "") {
+
+    private var propertyDefinition: PropertyDefinition = PropertyDefinition()
+
+    fun entrySchema(entrySchemaType: String) {
+        propertyDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).build()
+    }
+
+    fun entrySchema(entrySchemaType: String, block: EntrySchemaBuilder.() -> Unit) {
+        propertyDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).apply(block).build()
+    }
+    // TODO("Constrains")
+
+    fun defaultValue(defaultValue: JsonNode) {
+        propertyDefinition.defaultValue = defaultValue
+    }
+
+    fun build(): PropertyDefinition {
+        propertyDefinition.id = id
+        propertyDefinition.type = type!!
+        propertyDefinition.required = required
+        propertyDefinition.value = expression
+        propertyDefinition.description = description
+        return propertyDefinition
+    }
+}
\ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLData.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLData.kt
new file mode 100644 (file)
index 0000000..12428a9
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ *  Copyright © 2019 IBM.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.controllerblueprints.core.dsl
+
+import com.fasterxml.jackson.annotation.JsonIgnore
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.cds.controllerblueprints.core.data.*
+
+/**
+ * This is simplified version of DSL, which is used for generating the Service template
+ * @author Brinda Santh
+ */
+
+class DSLBluePrint {
+    var metadata: MutableMap<String, String> = hashMapOf()
+    var properties: MutableMap<String, JsonNode>? = null
+    var dataType: MutableMap<String, DataType> = hashMapOf()
+    var components: MutableMap<String, DSLComponent> = hashMapOf()
+    var workflows: MutableMap<String, DSLWorkflow> = hashMapOf()
+}
+
+class DSLWorkflow {
+    @get:JsonIgnore
+    var id: String? = null
+    lateinit var description: String
+    lateinit var actionName: String
+    lateinit var steps: MutableMap<String, Step>
+    var inputs: MutableMap<String, PropertyDefinition>? = null
+    var outputs: MutableMap<String, PropertyDefinition>? = null
+}
+
+class DSLComponent {
+    @get:JsonIgnore
+    lateinit var id: String
+    lateinit var type: String
+    lateinit var version: String
+    lateinit var description: String
+    var implementation: Implementation? = null
+    var attributes: MutableMap<String, AttributeDefinition>? = null
+    var properties: MutableMap<String, PropertyDefinition>? = null
+    var assignProperties: MutableMap<String, JsonNode>? = null
+    var artifacts: MutableMap<String, ArtifactDefinition>? = null
+    var inputs: MutableMap<String, PropertyDefinition>? = null
+    var outputs: MutableMap<String, PropertyDefinition>? = null
+    var assignInputs: MutableMap<String, JsonNode>? = null
+    var assignOutputs: MutableMap<String, JsonNode>? = null
+}
\ No newline at end of file
index 7973293..f19ae8e 100644 (file)
@@ -87,7 +87,7 @@ class NodeTemplateBuilder(private val id: String,
             interfaces = hashMapOf()
 
         val interfaceAssignment = InterfaceAssignment()
-        val defaultOperationName = "process"
+        val defaultOperationName = BluePrintConstants.DEFAULT_STEP_OPERATION
         interfaceAssignment.operations = hashMapOf()
         interfaceAssignment.operations!![defaultOperationName] =
                 OperationAssignmentBuilder(defaultOperationName, description).apply(block).build()
index 5ec3df1..f98cf58 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.onap.ccsdk.cds.controllerblueprints.core.dsl
 
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.data.Activity
 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.cds.controllerblueprints.core.data.Step
@@ -30,7 +31,7 @@ class WorkflowBuilder(private val id: String, private val description: String) {
 
     // Used Internally
     fun nodeTemplateStep(nodeTemplateName: String, description: String) {
-        step(nodeTemplateName, nodeTemplateName, "")
+        step(nodeTemplateName, nodeTemplateName, "$description step")
     }
 
     fun step(id: String, target: String, description: String) {
@@ -98,7 +99,7 @@ class StepBuilder(private val id: String, private val target: String,
         step.id = id
         step.target = target
         // Add Default Activity, Assumption is only one Operation
-        activity(".process")
+        activity(".${BluePrintConstants.DEFAULT_STEP_OPERATION}")
         step.description = description
         step.activities = activities
         step.onSuccess = onSuccess
index dff0f94..e7f24d6 100644 (file)
@@ -21,6 +21,44 @@ import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
 import kotlin.test.assertNotNull
 
 class BluePrintDSLTest {
+
+    @Test
+    fun testOperationDSLWorkflow() {
+
+        val blueprint = blueprint("sample-bp", "1.0.0",
+                "brindasanth@onap.com", "sample, blueprints") {
+
+            // For New Component Definition
+            component("resource-resolution", "component-resource-resolution", "1.0.0",
+                    "Resource Resolution Call") {
+                implementation(180)
+                // Attributes ( Properties which will be set during execution)
+                attribute("template1-data", "string", true, "")
+
+                // Properties
+                property("string-value1", "string", true, "sample")
+                property("string-value2", "string", true, getInput("key-1"))
+                // Inputs
+                input("json-content", "json", true, """{ "name" : "cds"}""")
+                input("template-content", "string", true, getArtifact("template1"))
+                // Outputs
+                output("self-attribute-expression", "json", true, getAttribute("template1-data"))
+                // Artifacts
+                artifacts("template1", "artifact-velocity", "Templates/template1.vtl")
+            }
+
+            workflow("resource-resolution-process", "") {
+                input("json-content", "json", true, "")
+                input("key-1", "string", true, "")
+                output("status", "string", true, "success")
+                step("resource-resolution-call", "resource-resolution", "Resource Resolution component invoke")
+            }
+        }
+        assertNotNull(blueprint.components, "failed to get components")
+        assertNotNull(blueprint.workflows, "failed to get workflows")
+        //println(blueprint.asJsonString(true))
+    }
+
     @Test
     fun testServiceTemplate() {
         val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
@@ -88,7 +126,7 @@ class BluePrintDSLTest {
         assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
         assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes")
         assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], "failed to get nodeTypes(activate)")
-        //println(JacksonUtils.getJson(serviceTemplate, true))
+        //println(serviceTemplate.asJsonString(true))
     }
 
     @Test
@@ -107,7 +145,7 @@ class BluePrintDSLTest {
         }
         assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
         assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)")
-        //println(JacksonUtils.getJson(serviceTemplate, true))
+        //println(serviceTemplate.asJsonString(true))
     }
 
 }