diff options
author | Dan Timoney <dtimoney@att.com> | 2019-06-18 15:15:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-06-18 15:15:34 +0000 |
commit | 013df49f02fc67ed196072881d703ff8013c3903 (patch) | |
tree | 4a55ea02293b8ad3458add937ee74f38352787c6 /ms/controllerblueprints/modules | |
parent | 6450dbdd0e85d421ab0001a842efc08e4d64e263 (diff) | |
parent | 07648810cc6a85629b525158fbac029e40df51e4 (diff) |
Merge "Add service template types DSL"
Diffstat (limited to 'ms/controllerblueprints/modules')
7 files changed, 427 insertions, 72 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt index 0638cc521..745671ac9 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt @@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonProperty 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 /** * @@ -207,8 +208,12 @@ class OperationDefinition { } 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 } /* @@ -369,7 +374,10 @@ class NodeType : EntityType() { /* 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() { diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt index a57024eec..4878cb696 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt @@ -40,11 +40,11 @@ fun getAttribute(attributeName: String, jsonPath: String): JsonNode { } 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 @@ -58,11 +58,11 @@ fun getProperty(propertyName: String, jsonPath: String): JsonNode { } 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 diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt index fc6df96c8..3415be8f3 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt @@ -29,11 +29,12 @@ class ServiceTemplateBuilder(private val name: String, 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 @@ -46,8 +47,15 @@ class ServiceTemplateBuilder(private val name: String, 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) { @@ -56,30 +64,105 @@ class ServiceTemplateBuilder(private val name: String, 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) { @@ -95,6 +178,7 @@ class ServiceTemplateBuilder(private val name: String, serviceTemplate.artifactTypes = artifactTypes serviceTemplate.dataTypes = dataTypes serviceTemplate.relationshipTypes = relationshipTypes + serviceTemplate.policyTypes = policyTypes serviceTemplate.topologyTemplate = topologyTemplate return serviceTemplate } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt index 66d36a5b1..7973293ae 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt @@ -17,10 +17,11 @@ 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 @@ -31,17 +32,38 @@ class TopologyTemplateBuilder() { 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 @@ -59,14 +81,16 @@ class NodeTemplateBuilder(private val id: String, 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 } @@ -180,10 +204,22 @@ class OperationAssignmentBuilder(private val id: String, 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 diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt index d60bdbb05..07cc20ebd 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt @@ -17,41 +17,54 @@ 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 @@ -63,24 +76,32 @@ open class EntityTypeBuilder(private val id: String, } } -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) { @@ -95,6 +116,18 @@ class NodeTypeBuilder(private val id: String, private val version: 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 @@ -105,38 +138,53 @@ class NodeTypeBuilder(private val id: String, private val version: String, } } -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 { @@ -145,29 +193,35 @@ class DataTypeBuilder(private val id: String, private val version: String, } } -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 } } @@ -213,18 +267,18 @@ class AttributesDefinitionBuilder { 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> { @@ -233,7 +287,7 @@ class AttributesDefinitionBuilder { } 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? = "") { @@ -266,18 +320,18 @@ class PropertiesDefinitionBuilder { 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> { @@ -286,7 +340,7 @@ class PropertiesDefinitionBuilder { } 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? = "") { @@ -305,6 +359,10 @@ class PropertyDefinitionBuilder(private val id: String, propertyDefinition.defaultValue = defaultValue } + fun value(value: JsonNode) { + propertyDefinition.value = value + } + fun build(): PropertyDefinition { propertyDefinition.id = id propertyDefinition.type = type!! diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt new file mode 100644 index 000000000..5ec3df160 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt @@ -0,0 +1,108 @@ +/* + * 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 + } +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt index 2c0192534..dff0f943f 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt @@ -17,17 +17,21 @@ 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"]""") @@ -36,10 +40,47 @@ class BluePrintDSLTest { 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()) + } + } } } } @@ -49,4 +90,24 @@ class BluePrintDSLTest { 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)) + } + } |