import com.fasterxml.jackson.annotation.JsonPropertyOrder
import com.fasterxml.jackson.databind.JsonNode
import io.swagger.annotations.ApiModelProperty
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
/**
*
}
class Implementation {
- lateinit var primary: String
+ var primary: String? = null
var dependencies: MutableList<String>? = null
+ @get:JsonProperty("operation_host")
+ var operationHost: String = BluePrintConstants.PROPERTY_SELF
+ //Timeout value in seconds
+ var timeout: Int = 180
}
/*
/*
3.6.8 Requirement Type
-A Requirement Type is a reusable entity that describes a kind of requirement that a Node Type can declare to expose. The TOSCA Simple Profile seeks to simplify the need for declaring specific Requirement Types from nodes and instead rely upon nodes declaring their features sets using TOSCA Capability Types along with a named Feature notation.
+A Requirement Type is a reusable entity that describes a kind of requirement that a Node Type can declare to expose.
+The TOSCA Simple Profile seeks to simplify the need for declaring specific Requirement Types
+from nodes and instead rely upon nodes declaring their features sets using TOSCA Capability Types
+along with a named Feature notation.
*/
class RequirementType : EntityType() {
}
fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String): JsonNode {
- return """{"get_attribute": ["${nodeTemplateName}", "$attributeName"]}""".jsonAsJsonType()
+ return """{"get_attribute": ["$nodeTemplateName", "$attributeName"]}""".jsonAsJsonType()
}
fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String, jsonPath: String): JsonNode {
- return """{"get_attribute": ["${nodeTemplateName}", "$attributeName", "$jsonPath]}""".jsonAsJsonType()
+ return """{"get_attribute": ["$nodeTemplateName", "$attributeName", "$jsonPath]}""".jsonAsJsonType()
}
// Property Function
}
fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String): JsonNode {
- return """{"get_property": ["${nodeTemplateName}", "$propertyName"]}""".jsonAsJsonType()
+ return """{"get_property": ["$nodeTemplateName", "$propertyName"]}""".jsonAsJsonType()
}
fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String, jsonPath: String): JsonNode {
- return """{"get_property": ["${nodeTemplateName}", "$propertyName", "$jsonPath]}""".jsonAsJsonType()
+ return """{"get_property": ["$nodeTemplateName", "$propertyName", "$jsonPath]}""".jsonAsJsonType()
}
// Artifact Function
private lateinit var topologyTemplate: TopologyTemplate
private var metadata: MutableMap<String, String> = hashMapOf()
private var dslDefinitions: MutableMap<String, JsonNode>? = null
- private var imports: MutableList<ImportDefinition>? = null
+ private var imports: MutableList<ImportDefinition> = mutableListOf()
private var nodeTypes: MutableMap<String, NodeType>? = null
private var artifactTypes: MutableMap<String, ArtifactType>? = null
private var dataTypes: MutableMap<String, DataType>? = null
private var relationshipTypes: MutableMap<String, RelationshipType>? = null
+ private var policyTypes: MutableMap<String, PolicyType>? = null
private fun initMetaData() {
metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] = name
metadata[id] = value
}
+ fun import(file: String) {
+ val importDefinition = ImportDefinition().apply {
+ this.file = file
+ }
+ imports.add(importDefinition)
+ }
+
fun dsl(id: String, json: String) {
- dsl(id, json.asJsonType())
+ dsl(id, json.asJsonType())
}
fun dsl(id: String, json: JsonNode) {
dslDefinitions!![id] = json.asJsonType()
}
- // TODO("Imports")
+ fun dataTypes(dataTypes: MutableMap<String, DataType>) {
+ if (this.dataTypes == null)
+ this.dataTypes = hashMapOf()
+
+ this.dataTypes!!.putAll(dataTypes)
+ }
+
+ fun artifactTypes(artifactTypes: MutableMap<String, ArtifactType>) {
+ if (this.artifactTypes == null)
+ this.artifactTypes = hashMapOf()
+
+ this.artifactTypes!!.putAll(artifactTypes)
+ }
+
+ fun relationshipTypes(relationshipTypes: MutableMap<String, RelationshipType>) {
+ if (this.relationshipTypes == null)
+ this.relationshipTypes = hashMapOf()
+
+ this.relationshipTypes!!.putAll(relationshipTypes)
+ }
- fun dataType(id: String, version: String, description: String, block: DataTypeBuilder.() -> Unit) {
+ fun policyTypes(policyTypes: MutableMap<String, PolicyType>) {
+ if (this.policyTypes == null)
+ this.policyTypes = hashMapOf()
+
+ this.policyTypes!!.putAll(policyTypes)
+ }
+
+ fun nodeType(nodeTypes: MutableMap<String, NodeType>) {
+ if (this.nodeTypes == null)
+ this.nodeTypes = hashMapOf()
+
+ this.nodeTypes!!.putAll(nodeTypes)
+ }
+
+ fun dataType(dataType: DataType) {
if (dataTypes == null)
dataTypes = hashMapOf()
- dataTypes!![id] = DataTypeBuilder(id, version, description).apply(block).build()
+ dataTypes!![dataType.id!!] = dataType
}
- fun artifactType(id: String, version: String, description: String, block: ArtifactTypeBuilder.() -> Unit) {
+ fun artifactType(artifactType: ArtifactType) {
if (artifactTypes == null)
artifactTypes = hashMapOf()
- artifactTypes!![id] = ArtifactTypeBuilder(id, version, description).apply(block).build()
+ artifactTypes!![artifactType.id!!] = artifactType
}
- fun relationshipType(id: String, version: String, description: String, block: RelationshipTypeBuilder.() -> Unit) {
+ fun relationshipType(relationshipType: RelationshipType) {
if (relationshipTypes == null)
relationshipTypes = hashMapOf()
- relationshipTypes!![id] = RelationshipTypeBuilder(id, version, description).apply(block).build()
+ relationshipTypes!![relationshipType.id!!] = relationshipType
+ }
+
+ fun policyType(policyType: PolicyType) {
+ if (policyTypes == null)
+ policyTypes = hashMapOf()
+
+ policyTypes!![policyType.id!!] = policyType
+ }
+
+ fun nodeType(nodeType: NodeType) {
+ if (nodeTypes == null)
+ nodeTypes = hashMapOf()
+ nodeTypes!![nodeType.id!!] = nodeType
+ }
+
+ fun dataType(id: String, version: String, derivedFrom: String, description: String,
+ block: DataTypeBuilder.() -> Unit) {
+ if (dataTypes == null)
+ dataTypes = hashMapOf()
+ dataTypes!![id] = DataTypeBuilder(id, version, derivedFrom, description).apply(block).build()
+ }
+
+ fun artifactType(id: String, version: String, derivedFrom: String, description: String,
+ block: ArtifactTypeBuilder.() -> Unit) {
+ if (artifactTypes == null)
+ artifactTypes = hashMapOf()
+ artifactTypes!![id] = ArtifactTypeBuilder(id, version, derivedFrom, description).apply(block).build()
+ }
+
+ fun relationshipType(id: String, version: String, derivedFrom: String, description: String,
+ block: RelationshipTypeBuilder.() -> Unit) {
+ if (relationshipTypes == null)
+ relationshipTypes = hashMapOf()
+ relationshipTypes!![id] = RelationshipTypeBuilder(id, version, derivedFrom, description).apply(block).build()
+ }
+
+ fun policyType(id: String, version: String, derivedFrom: String, description: String,
+ block: PolicyTypeBuilder.() -> Unit) {
+ if (policyTypes == null)
+ policyTypes = hashMapOf()
+ policyTypes!![id] = PolicyTypeBuilder(id, version, derivedFrom, description).apply(block).build()
}
- fun nodeType(id: String, version: String, description: String, block: NodeTypeBuilder.() -> Unit) {
+ fun nodeType(id: String, version: String, derivedFrom: String, description: String,
+ block: NodeTypeBuilder.() -> Unit) {
if (nodeTypes == null)
nodeTypes = hashMapOf()
- nodeTypes!![id] = NodeTypeBuilder(id, version, description).apply(block).build()
+ nodeTypes!![id] = NodeTypeBuilder(id, version, derivedFrom, description).apply(block).build()
}
fun topologyTemplate(block: TopologyTemplateBuilder.() -> Unit) {
serviceTemplate.artifactTypes = artifactTypes
serviceTemplate.dataTypes = dataTypes
serviceTemplate.relationshipTypes = relationshipTypes
+ serviceTemplate.policyTypes = policyTypes
serviceTemplate.topologyTemplate = topologyTemplate
return serviceTemplate
}
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.*
-class TopologyTemplateBuilder() {
+class TopologyTemplateBuilder {
private var topologyTemplate = TopologyTemplate()
private var nodeTemplates: MutableMap<String, NodeTemplate>? = null
private var workflows: MutableMap<String, Workflow>? = null
nodeTemplates!![id] = NodeTemplateBuilder(id, type, description).apply(block).build()
}
- fun nodeTemplateOperation(nodeTemplateName: String, type: String,
- interfaceName: String, operationName: String,
- description: String, operationBlock: OperationAssignmentBuilder.() -> Unit) {
+ fun nodeTemplateOperation(nodeTemplateName: String, type: String, interfaceName: String, description: String,
+ operationBlock: OperationAssignmentBuilder.() -> Unit) {
if (nodeTemplates == null)
nodeTemplates = hashMapOf()
val nodeTemplateBuilder = NodeTemplateBuilder(nodeTemplateName, type, description)
- nodeTemplateBuilder.operation(interfaceName, operationName, "$description operation", operationBlock)
+ nodeTemplateBuilder.operation(interfaceName, "$description operation", operationBlock)
nodeTemplates!![nodeTemplateName] = nodeTemplateBuilder.build()
}
- //TODO("workflow")
+
+ fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit) {
+ if (workflows == null)
+ workflows = hashMapOf()
+ workflows!![id] = WorkflowBuilder(id, description).apply(block).build()
+ }
+
+ //TODO("populate inputs, outputs")
+ fun workflowNodeTemplate(actionName: String,
+ nodeTemplateType: String, description: String, block: NodeTemplateBuilder.() -> Unit) {
+ if (nodeTemplates == null)
+ nodeTemplates = hashMapOf()
+
+ if (workflows == null)
+ workflows = hashMapOf()
+
+ val workflowBuilder = WorkflowBuilder(actionName, description)
+ workflowBuilder.nodeTemplateStep(actionName, description)
+ // Workflow name is NodeTemplate name
+ workflows!![actionName] = workflowBuilder.build()
+
+ nodeTemplates!![actionName] = NodeTemplateBuilder(actionName, nodeTemplateType, description).apply(block).build()
+ }
fun build(): TopologyTemplate {
topologyTemplate.nodeTemplates = nodeTemplates
private var capabilities: MutableMap<String, CapabilityAssignment>? = null
private var requirements: MutableMap<String, RequirementAssignment>? = null
- fun operation(interfaceName: String, operationName: String, description: String? = "",
+ fun operation(interfaceName: String, description: String? = "",
block: OperationAssignmentBuilder.() -> Unit) {
if (interfaces == null)
interfaces = hashMapOf()
val interfaceAssignment = InterfaceAssignment()
+ val defaultOperationName = "process"
interfaceAssignment.operations = hashMapOf()
- interfaceAssignment.operations!![operationName] = OperationAssignmentBuilder(operationName, description).apply(block).build()
+ interfaceAssignment.operations!![defaultOperationName] =
+ OperationAssignmentBuilder(defaultOperationName, description).apply(block).build()
interfaces!![interfaceName] = interfaceAssignment
}
private var operationAssignment: OperationAssignment = OperationAssignment()
+ fun implementation(timeout: Int, operationHost: String? = BluePrintConstants.PROPERTY_SELF) {
+ val implementation = Implementation().apply {
+ this.operationHost = operationHost!!
+ this.timeout = timeout
+ }
+ operationAssignment.implementation = implementation
+ }
+
fun inputs(block: PropertiesAssignmentBuilder.() -> Unit) {
operationAssignment.inputs = PropertiesAssignmentBuilder().apply(block).build()
}
+ fun outputs(block: PropertiesAssignmentBuilder.() -> Unit) {
+ operationAssignment.outputs = PropertiesAssignmentBuilder().apply(block).build()
+ }
+
fun build(): OperationAssignment {
operationAssignment.id = id
operationAssignment.description = description
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.data.*
open class EntityTypeBuilder(private val id: String,
private val version: String,
+ private val derivedFrom: String,
private val description: String? = "") {
- lateinit var derivedFrom: String
var metadata: MutableMap<String, String>? = null
var properties: MutableMap<String, PropertyDefinition>? = null
var attributes: MutableMap<String, AttributeDefinition>? = null
- fun derivedFrom(derivedFrom: String) {
- this.derivedFrom = derivedFrom
- }
-
fun metadata(key: String, value: String) {
if (metadata == null)
metadata = hashMapOf()
metadata!![key] = value
}
- fun attribute(id: String, type: String? = "string", required: Boolean? = false, description: String? = "") {
+ fun attribute(id: String, type: String, required: Boolean, description: String? = "") {
if (attributes == null)
attributes = hashMapOf()
val attribute = AttributeDefinitionBuilder(id, type, required, description).build()
attributes!![id] = attribute
}
- fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "") {
+ fun attribute(id: String, type: String, required: Boolean, description: String? = "",
+ block: AttributeDefinitionBuilder.() -> Unit) {
+ if (attributes == null)
+ attributes = hashMapOf()
+ val attribute = AttributeDefinitionBuilder(id, type, required, description).apply(block).build()
+ attributes!![id] = attribute
+ }
+
+ fun property(id: String, type: String, required: Boolean, description: String? = "") {
if (properties == null)
properties = hashMapOf()
val property = PropertyDefinitionBuilder(id, type, required, description).build()
properties!![id] = property
}
+ fun property(id: String, type: String, required: Boolean, description: String? = "",
+ block: PropertyDefinitionBuilder.() -> Unit) {
+ if (properties == null)
+ properties = hashMapOf()
+ val property = PropertyDefinitionBuilder(id, type, required, description).apply(block).build()
+ properties!![id] = property
+ }
+
fun buildEntityType(entity: EntityType) {
entity.id = id
entity.description = description
}
}
-class NodeTypeBuilder(private val id: String, private val version: String,
- private val description: String? = "") : EntityTypeBuilder(id, version, description) {
+class NodeTypeBuilder(id: String, version: String, derivedFrom: String,
+ description: String?) : EntityTypeBuilder(id, version, derivedFrom, description) {
private var nodeType = NodeType()
private var capabilities: MutableMap<String, CapabilityDefinition>? = null
private var requirements: MutableMap<String, RequirementDefinition>? = null
private var interfaces: MutableMap<String, InterfaceDefinition>? = null
private var artifacts: MutableMap<String, ArtifactDefinition>? = null
- fun capability(id: String, block: CapabilityDefinitionBuilder.() -> Unit) {
+ fun capability(id: String, type: String, description: String, block: CapabilityDefinitionBuilder.() -> Unit) {
if (capabilities == null)
capabilities = hashMapOf()
- capabilities!![id] = CapabilityDefinitionBuilder(id).apply(block).build()
+ capabilities!![id] = CapabilityDefinitionBuilder(id, type, description).apply(block).build()
}
- fun requirement(id: String, block: RequirementDefinitionBuilder.() -> Unit) {
+ fun requirement(id: String, capability: String, node: String, relationship: String, description: String) {
if (requirements == null)
requirements = hashMapOf()
- requirements!![id] = RequirementDefinitionBuilder(id).apply(block).build()
+ requirements!![id] = RequirementDefinitionBuilder(id, capability, node, relationship, description).build()
+ }
+
+ fun requirement(id: String, capability: String, node: String, relationship: String, description: String,
+ block: RequirementDefinitionBuilder.() -> Unit) {
+ if (requirements == null)
+ requirements = hashMapOf()
+ requirements!![id] = RequirementDefinitionBuilder(id, capability, node, relationship, description)
+ .apply(block).build()
}
fun artifact(id: String, type: String, file: String) {
interfaces!![id] = InterfaceDefinitionBuilder(id).apply(block).build()
}
+ fun operation(interfaceName: String, description: String?, block: OperationDefinitionBuilder.() -> Unit) {
+ if (interfaces == null)
+ interfaces = hashMapOf()
+
+ val interfaceDefinition = InterfaceDefinition()
+ val defaultOperationName = "process"
+ interfaceDefinition.operations = hashMapOf()
+ interfaceDefinition.operations!![defaultOperationName] =
+ OperationDefinitionBuilder(defaultOperationName, description).apply(block).build()
+ interfaces!![interfaceName] = interfaceDefinition
+ }
+
fun build(): NodeType {
buildEntityType(nodeType)
nodeType.capabilities = capabilities
}
}
-class ArtifactTypeBuilder(private val id: String, private val version: String,
- private val description: String? = "") : EntityTypeBuilder(id, version, description) {
+class ArtifactTypeBuilder(id: String, version: String, derivedFrom: String,
+ description: String?) : EntityTypeBuilder(id, version, derivedFrom, description) {
private var artifactType = ArtifactType()
- //TODO()
+ private var fileExt: MutableList<String>? = null
+
+ fun fileExt(vararg fileExts: String) {
+ if (fileExt == null)
+ fileExt = arrayListOf()
+ fileExts.forEach {
+ fileExt!!.add(it)
+ }
+ }
+
fun build(): ArtifactType {
buildEntityType(artifactType)
+ artifactType.fileExt = fileExt
return artifactType
}
}
-class RequirementTypeBuilder(private val id: String, private val version: String,
- private val description: String? = "") : EntityTypeBuilder(id, version, description) {
- private var requirementType = RequirementType()
+class PolicyTypeBuilder(id: String, version: String, derivedFrom: String,
+ description: String?) : EntityTypeBuilder(id, version, derivedFrom, description) {
+ private var policyType = PolicyType()
// TODO()
- fun build(): RequirementType {
- buildEntityType(requirementType)
- return requirementType
+ fun build(): PolicyType {
+ buildEntityType(policyType)
+ return policyType
}
}
class RelationshipTypeBuilder(private val id: String, private val version: String,
- private val description: String? = "") : EntityTypeBuilder(id, version, description) {
+ derivedFrom: String, private val description: String?)
+ : EntityTypeBuilder(id, version, derivedFrom, description) {
+
private var relationshipType = RelationshipType()
// TODO()
fun build(): RelationshipType {
buildEntityType(relationshipType)
+ relationshipType.id = id
+ relationshipType.version = version
+ relationshipType.description = description
return relationshipType
}
}
-class DataTypeBuilder(private val id: String, private val version: String,
- private val description: String? = "") : EntityTypeBuilder(id, version, description) {
+class DataTypeBuilder(id: String, version: String, derivedFrom: String,
+ description: String?) : EntityTypeBuilder(id, version, derivedFrom, description) {
private var dataType = DataType()
// TODO()
fun build(): DataType {
}
}
-class CapabilityDefinitionBuilder(private val id: String) {
+class CapabilityDefinitionBuilder(private val id: String, private val type: String, private val description: String? = "") {
private var capabilityDefinition = CapabilityDefinition()
private val properties: MutableMap<String, PropertyDefinition> = hashMapOf()
- // TODO()
- fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "") {
+
+ fun property(id: String, type: String? = BluePrintConstants.DATA_TYPE_STRING, required: Boolean? = false, description: String? = "") {
val property = PropertyDefinitionBuilder(id, type, required, description).build()
- properties.put(id, property)
+ properties[id] = property
}
fun build(): CapabilityDefinition {
capabilityDefinition.id = id
+ capabilityDefinition.description = description
+ capabilityDefinition.type = type
capabilityDefinition.properties = properties
return capabilityDefinition
}
}
-class RequirementDefinitionBuilder(private val id: String) {
+class RequirementDefinitionBuilder(private val id: String, private val capability: String, private val node: String,
+ private val relationship: String, private val description: String? = "") {
private var requirementDefinition = RequirementDefinition()
- // TODO()
+
fun build(): RequirementDefinition {
requirementDefinition.id = id
-
+ requirementDefinition.description = description
+ requirementDefinition.capability = capability
+ requirementDefinition.node = node
+ requirementDefinition.relationship = relationship
return requirementDefinition
}
}
private val attributes: MutableMap<String, AttributeDefinition> = hashMapOf()
fun property(id: String, attribute: AttributeDefinition) {
- attributes.put(id, attribute)
+ attributes[id] = attribute
}
- fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "") {
+ fun property(id: String, type: String?, required: Boolean?, description: String?) {
val attribute = AttributeDefinitionBuilder(id, type, required, description).build()
- attributes.put(id, attribute)
+ attributes[id] = attribute
}
- fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "",
+ fun property(id: String, type: String?, required: Boolean?, description: String?,
block: AttributeDefinitionBuilder.() -> Unit) {
val attribute = AttributeDefinitionBuilder(id, type, required, description).apply(block).build()
- attributes.put(id, attribute)
+ attributes[id] = attribute
}
fun build(): MutableMap<String, AttributeDefinition> {
}
class AttributeDefinitionBuilder(private val id: String,
- private val type: String? = "string",
+ private val type: String? = BluePrintConstants.DATA_TYPE_STRING,
private val required: Boolean? = false,
private val description: String? = "") {
private val properties: MutableMap<String, PropertyDefinition> = hashMapOf()
fun property(id: String, property: PropertyDefinition) {
- properties.put(id, property)
+ properties[id] = property
}
- fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "") {
+ fun property(id: String, type: String?, required: Boolean?, description: String? = "") {
val property = PropertyDefinitionBuilder(id, type, required, description).build()
- properties.put(id, property)
+ properties[id] = property
}
- fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "",
+ fun property(id: String, type: String?, required: Boolean?, description: String? = "",
block: PropertyDefinitionBuilder.() -> Unit) {
val property = PropertyDefinitionBuilder(id, type, required, description).apply(block).build()
- properties.put(id, property)
+ properties[id] = property
}
fun build(): MutableMap<String, PropertyDefinition> {
}
class PropertyDefinitionBuilder(private val id: String,
- private val type: String? = "string",
+ private val type: String? = BluePrintConstants.DATA_TYPE_STRING,
private val required: Boolean? = false,
private val description: String? = "") {
propertyDefinition.defaultValue = defaultValue
}
+ fun value(value: JsonNode) {
+ propertyDefinition.value = value
+ }
+
fun build(): PropertyDefinition {
propertyDefinition.id = id
propertyDefinition.type = type!!
--- /dev/null
+/*
+ * 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 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
+import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
+
+class WorkflowBuilder(private val id: String, private val description: String) {
+
+ private var workflow = Workflow()
+ private var steps: MutableMap<String, Step>? = null
+ private var inputs: MutableMap<String, PropertyDefinition>? = null
+ private var outputs: MutableMap<String, PropertyDefinition>? = null
+
+ // Used Internally
+ fun nodeTemplateStep(nodeTemplateName: String, description: String) {
+ step(nodeTemplateName, nodeTemplateName, "")
+ }
+
+ 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 inputs(block: PropertiesDefinitionBuilder.() -> Unit) {
+ inputs = PropertiesDefinitionBuilder().apply(block).build()
+ }
+
+ fun outputs(block: PropertiesDefinitionBuilder.() -> Unit) {
+ outputs = PropertiesDefinitionBuilder().apply(block).build()
+ }
+
+ fun build(): Workflow {
+ workflow.id = id
+ workflow.description = description
+ workflow.steps = steps
+ workflow.inputs = inputs
+ workflow.outputs = outputs
+ return workflow
+ }
+
+}
+
+class StepBuilder(private val id: String, private val target: String,
+ private val description: String) {
+
+ private var step = Step()
+ private var activities: ArrayList<Activity> = arrayListOf()
+ private var onSuccess: ArrayList<String>? = null
+ private var onFailure: ArrayList<String>? = null
+
+ fun activity(callOperation: String) {
+ val activity = Activity()
+ activity.callOperation = callOperation
+ activities.add(activity)
+ }
+
+ fun success(vararg successTargets: String) {
+ if (onSuccess == null)
+ onSuccess = arrayListOf()
+ successTargets.forEach {
+ onSuccess!!.add(it)
+ }
+ }
+
+ fun failure(vararg failureTargets: String) {
+ if (onFailure == null)
+ onFailure = arrayListOf()
+ failureTargets.forEach {
+ onFailure!!.add(it)
+ }
+ }
+
+ fun build(): Step {
+ step.id = id
+ step.target = target
+ // Add Default Activity, Assumption is only one Operation
+ activity(".process")
+ step.description = description
+ step.activities = activities
+ step.onSuccess = onSuccess
+ step.onFailure = onFailure
+ return step
+ }
+}
package org.onap.ccsdk.cds.controllerblueprints.core.dsl
import org.junit.Test
+import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
import kotlin.test.assertNotNull
class BluePrintDSLTest {
@Test
fun testServiceTemplate() {
val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
- "brindasanth@onap.com", "sample") {
+ "brindasanth@onap.com", "sample, blueprints") {
metadata("release", "1806")
+ import("Definition/data_types.json")
+ dsl("rest-endpoint", """{ "selector" : "odl-selector"}""")
+ dsl("db-endpoint", """{ "selector" : "db-selector"}""")
topologyTemplate {
nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
- operationName = "process", description = "sample activation") {
+ description = "sample activation") {
inputs {
property("json-content", """{ "name" : "cds"}""")
property("array-content", """["controller", "blueprints"]""")
property("string-value", "sample")
property("input-expression", getInput("key-1"))
property("self-property-expression", getProperty("key-1"))
- property("self-attribute-expression", getAttribute("key-1"))
property("self-artifact-expression", getArtifact("key-1"))
property("other-artifact-expression", getNodeTemplateArtifact("node-1", "key-1"))
}
+ outputs {
+ property("self-attribute-expression", getAttribute("key-1"))
+ }
+ }
+ // Other way of defining Node Template with artifacts, implementation
+ nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") {
+ operation("ResourceResolutionExecutor", "") {
+ implementation(180)
+ inputs {
+ property("boolean-value", true)
+ property("string-value", "sample")
+ }
+ outputs {
+ property("resolve-expression", getAttribute("key-1"))
+ }
+ }
+ artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl")
+ }
+
+ workflow("resource-resolution", "to resolve resources") {
+ step("resource-resolution-call", "resolve", "Resource Resolution component invoke")
+ }
+ // Alternate way to define workflow
+ workflow("activate", "to resolve resources") {
+ // Alternate step definition
+ step("netconf-activate-call", "activate", "call activation component") {
+ success("END")
+ failure("END")
+ }
+ inputs {
+ property("request-content", "json", true)
+ }
+ outputs {
+ property("response-content", "json", true) {
+ value(getAttribute("key-1"))
+ defaultValue("""{ "status" : "success"}""".jsonAsJsonType())
+ }
+ }
}
}
}
assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], "failed to get nodeTypes(activate)")
//println(JacksonUtils.getJson(serviceTemplate, true))
}
+
+ @Test
+ fun testServiceTemplateWorkflow() {
+ val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
+ "brindasanth@onap.com", "sample, blueprints") {
+ topologyTemplate {
+ workflowNodeTemplate("activate", "component-resource-resolution", "") {
+ operation("ResourceResolutionExecutor", "") {
+ inputs {
+ property("string-value", "sample")
+ }
+ }
+ }
+ }
+ }
+ assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
+ assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)")
+ //println(JacksonUtils.getJson(serviceTemplate, true))
+ }
+
}