aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-06-18 15:15:18 +0000
committerGerrit Code Review <gerrit@onap.org>2019-06-18 15:15:18 +0000
commit6450dbdd0e85d421ab0001a842efc08e4d64e263 (patch)
treebfaac926ccc1d83ce15fb57d72e7e302f3399f3c
parente0dc3a5fe5c427fa29a3fda8b19db874dfcdec70 (diff)
parente953ae91f7c74c12aa5770da9e967c03dd21a44c (diff)
Merge "Add service template assignments DSL"
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt18
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt76
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt101
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt224
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt324
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt52
6 files changed, 793 insertions, 2 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
index 583fc9d4d..4f2b7a121 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
@@ -29,10 +29,20 @@ import kotlin.reflect.KClass
* @author Brinda Santh
*/
+fun String.isJson(): Boolean {
+ return ((this.startsWith("{") && this.endsWith("}"))
+ || (this.startsWith("[") && this.endsWith("]")))
+}
+
fun String.asJsonPrimitive(): TextNode {
return TextNode(this)
}
+// If you know the string is json content, then use the function directly
+fun String.jsonAsJsonType(): JsonNode {
+ return JacksonUtils.jsonNode(this.trim())
+}
+
fun Boolean.asJsonPrimitive(): BooleanNode {
return BooleanNode.valueOf(this)
}
@@ -52,8 +62,12 @@ fun <T : Any?> T.asJsonType(): JsonNode {
when (this) {
is JsonNode ->
this
- is String ->
- TextNode(this)
+ is String -> {
+ if (this.isJson())
+ this.jsonAsJsonType()
+ else
+ TextNode(this)
+ }
is Boolean ->
BooleanNode.valueOf(this)
is Int ->
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
new file mode 100644
index 000000000..a57024eec
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt
@@ -0,0 +1,76 @@
+/*
+ * 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.data.ServiceTemplate
+import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
+
+fun serviceTemplate(name: String, version: String, author: String, tags: String,
+ block: ServiceTemplateBuilder.() -> Unit): ServiceTemplate {
+ return ServiceTemplateBuilder(name, version, author, tags).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(attributeName: String, jsonPath: String): JsonNode {
+ return """{"get_attribute": ["SELF", "$attributeName", "$jsonPath"]}""".jsonAsJsonType()
+}
+
+fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String): JsonNode {
+ return """{"get_attribute": ["${nodeTemplateName}", "$attributeName"]}""".jsonAsJsonType()
+}
+
+fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String, jsonPath: String): JsonNode {
+ return """{"get_attribute": ["${nodeTemplateName}", "$attributeName", "$jsonPath]}""".jsonAsJsonType()
+}
+
+// Property Function
+
+fun getProperty(propertyName: String): JsonNode {
+ return """{"get_property": ["SELF", "$propertyName"]}""".jsonAsJsonType()
+}
+
+fun getProperty(propertyName: String, jsonPath: String): JsonNode {
+ return """{"get_property": ["SELF", "$propertyName", "$jsonPath"]}""".jsonAsJsonType()
+}
+
+fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String): JsonNode {
+ return """{"get_property": ["${nodeTemplateName}", "$propertyName"]}""".jsonAsJsonType()
+}
+
+fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String, jsonPath: String): JsonNode {
+ return """{"get_property": ["${nodeTemplateName}", "$propertyName", "$jsonPath]}""".jsonAsJsonType()
+}
+
+// Artifact Function
+
+fun getArtifact(artifactName: String): JsonNode {
+ return """{"get_artifact": ["SELF", "$artifactName"]}""".jsonAsJsonType()
+}
+
+fun getNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): JsonNode {
+ return """{"get_artifact": ["$nodeTemplateName", "$artifactName"]}""".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/BluePrintServiceDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt
new file mode 100644
index 000000000..fc6df96c8
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt
@@ -0,0 +1,101 @@
+/*
+ * 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.*
+
+class ServiceTemplateBuilder(private val name: String,
+ private val version: String,
+ private val author: String,
+ private val tags: String) {
+ private var serviceTemplate = ServiceTemplate()
+ 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 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 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 dsl(id: String, json: String) {
+ dsl(id, json.asJsonType())
+ }
+
+ fun dsl(id: String, json: JsonNode) {
+ if (dslDefinitions == null)
+ dslDefinitions = hashMapOf()
+ dslDefinitions!![id] = json.asJsonType()
+ }
+
+ // TODO("Imports")
+
+ fun dataType(id: String, version: String, description: String, block: DataTypeBuilder.() -> Unit) {
+ if (dataTypes == null)
+ dataTypes = hashMapOf()
+ dataTypes!![id] = DataTypeBuilder(id, version, description).apply(block).build()
+ }
+
+ fun artifactType(id: String, version: String, description: String, block: ArtifactTypeBuilder.() -> Unit) {
+ if (artifactTypes == null)
+ artifactTypes = hashMapOf()
+ artifactTypes!![id] = ArtifactTypeBuilder(id, version, description).apply(block).build()
+ }
+
+ fun relationshipType(id: String, version: String, description: String, block: RelationshipTypeBuilder.() -> Unit) {
+ if (relationshipTypes == null)
+ relationshipTypes = hashMapOf()
+ relationshipTypes!![id] = RelationshipTypeBuilder(id, version, description).apply(block).build()
+ }
+
+ fun nodeType(id: String, version: String, description: String, block: NodeTypeBuilder.() -> Unit) {
+ if (nodeTypes == null)
+ nodeTypes = hashMapOf()
+ nodeTypes!![id] = NodeTypeBuilder(id, version, description).apply(block).build()
+ }
+
+ fun topologyTemplate(block: TopologyTemplateBuilder.() -> Unit) {
+ topologyTemplate = TopologyTemplateBuilder().apply(block).build()
+ }
+
+ fun build(): ServiceTemplate {
+ initMetaData()
+ serviceTemplate.metadata = metadata
+ serviceTemplate.imports = imports
+ serviceTemplate.dslDefinitions = dslDefinitions
+ serviceTemplate.nodeTypes = nodeTypes
+ serviceTemplate.artifactTypes = artifactTypes
+ serviceTemplate.dataTypes = dataTypes
+ serviceTemplate.relationshipTypes = relationshipTypes
+ 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
new file mode 100644
index 000000000..66d36a5b1
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt
@@ -0,0 +1,224 @@
+/*
+ * 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.asJsonType
+import org.onap.ccsdk.cds.controllerblueprints.core.data.*
+
+class TopologyTemplateBuilder() {
+ private var topologyTemplate = TopologyTemplate()
+ private var nodeTemplates: MutableMap<String, NodeTemplate>? = null
+ private var workflows: MutableMap<String, Workflow>? = null
+
+ fun nodeTemplate(id: String, type: String, description: String, block: NodeTemplateBuilder.() -> Unit) {
+ if (nodeTemplates == null)
+ nodeTemplates = hashMapOf()
+ nodeTemplates!![id] = NodeTemplateBuilder(id, type, description).apply(block).build()
+ }
+
+ fun nodeTemplateOperation(nodeTemplateName: String, type: String,
+ interfaceName: String, operationName: String,
+ description: String, operationBlock: OperationAssignmentBuilder.() -> Unit) {
+ if (nodeTemplates == null)
+ nodeTemplates = hashMapOf()
+
+ val nodeTemplateBuilder = NodeTemplateBuilder(nodeTemplateName, type, description)
+ nodeTemplateBuilder.operation(interfaceName, operationName, "$description operation", operationBlock)
+ nodeTemplates!![nodeTemplateName] = nodeTemplateBuilder.build()
+ }
+ //TODO("workflow")
+
+ fun build(): TopologyTemplate {
+ topologyTemplate.nodeTemplates = nodeTemplates
+ topologyTemplate.workflows = workflows
+ return topologyTemplate
+ }
+}
+
+class NodeTemplateBuilder(private val id: String,
+ private val type: String,
+ private val description: String? = "") {
+ private var nodeTemplate: NodeTemplate = NodeTemplate()
+ private var interfaces: MutableMap<String, InterfaceAssignment>? = null
+ private var artifacts: MutableMap<String, ArtifactDefinition>? = null
+ private var capabilities: MutableMap<String, CapabilityAssignment>? = null
+ private var requirements: MutableMap<String, RequirementAssignment>? = null
+
+ fun operation(interfaceName: String, operationName: String, description: String? = "",
+ block: OperationAssignmentBuilder.() -> Unit) {
+ if (interfaces == null)
+ interfaces = hashMapOf()
+
+ val interfaceAssignment = InterfaceAssignment()
+ interfaceAssignment.operations = hashMapOf()
+ interfaceAssignment.operations!![operationName] = OperationAssignmentBuilder(operationName, description).apply(block).build()
+ interfaces!![interfaceName] = interfaceAssignment
+ }
+
+ fun artifact(id: String, type: String, file: String) {
+ if (artifacts == null)
+ artifacts = hashMapOf()
+ artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).build()
+ }
+
+ fun artifact(id: String, type: String, file: String, block: ArtifactDefinitionBuilder.() -> Unit) {
+ if (artifacts == null)
+ artifacts = hashMapOf()
+ artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).apply(block).build()
+ }
+
+ fun capability(id: String, block: CapabilityAssignmentBuilder.() -> Unit) {
+ if (capabilities == null)
+ capabilities = hashMapOf()
+ capabilities!![id] = CapabilityAssignmentBuilder(id).apply(block).build()
+ }
+
+ fun requirement(id: String, capability: String, node: String, relationship: String) {
+ if (requirements == null)
+ requirements = hashMapOf()
+ requirements!![id] = RequirementAssignmentBuilder(id, capability, node, relationship).build()
+ }
+
+ fun build(): NodeTemplate {
+ nodeTemplate.id = id
+ nodeTemplate.type = type
+ nodeTemplate.description = description
+ nodeTemplate.interfaces = interfaces
+ nodeTemplate.artifacts = artifacts
+ nodeTemplate.capabilities = capabilities
+ nodeTemplate.requirements = requirements
+ return nodeTemplate
+ }
+}
+
+class ArtifactDefinitionBuilder(private val id: String, private val type: String, private val file: String) {
+
+ private var artifactDefinition: ArtifactDefinition = ArtifactDefinition()
+ // TODO()
+
+ fun build(): ArtifactDefinition {
+ artifactDefinition.id = id
+ artifactDefinition.type = type
+ artifactDefinition.file = file
+ return artifactDefinition
+ }
+}
+
+class CapabilityAssignmentBuilder(private val id: String) {
+ private var capabilityAssignment: CapabilityAssignment = CapabilityAssignment()
+ private var attributes: MutableMap<String, JsonNode>? = null
+ private var properties: MutableMap<String, JsonNode>? = null
+
+ fun attributes(block: AttributesAssignmentBuilder.() -> Unit) {
+ if (attributes == null)
+ attributes = hashMapOf()
+ attributes = AttributesAssignmentBuilder().apply(block).build()
+ }
+
+ fun properties(block: PropertiesAssignmentBuilder.() -> Unit) {
+ if (properties == null)
+ properties = hashMapOf()
+ properties = PropertiesAssignmentBuilder().apply(block).build()
+ }
+
+ fun build(): CapabilityAssignment {
+ capabilityAssignment.properties = properties
+ capabilityAssignment.attributes = attributes
+ return capabilityAssignment
+ }
+}
+
+class RequirementAssignmentBuilder(private val id: String, private val capability: String,
+ private val node: String,
+ private val relationship: String) {
+ private var requirementAssignment: RequirementAssignment = RequirementAssignment()
+
+ fun build(): RequirementAssignment {
+ requirementAssignment.id = id
+ requirementAssignment.capability = capability
+ requirementAssignment.node = node
+ requirementAssignment.relationship = relationship
+ return requirementAssignment
+ }
+}
+
+class InterfaceAssignmentBuilder(private val id: String) {
+
+ private var interfaceAssignment: InterfaceAssignment = InterfaceAssignment()
+ private var operations: MutableMap<String, OperationAssignment>? = null
+
+ fun operation(id: String, description: String? = "", block: OperationAssignmentBuilder.() -> Unit) {
+ if (operations == null)
+ operations = hashMapOf()
+ operations!![id] = OperationAssignmentBuilder(id, description).apply(block).build()
+ }
+
+ fun build(): InterfaceAssignment {
+ interfaceAssignment.id = id
+ interfaceAssignment.operations = operations
+ return interfaceAssignment
+ }
+}
+
+class OperationAssignmentBuilder(private val id: String,
+ private val description: String? = "") {
+
+ private var operationAssignment: OperationAssignment = OperationAssignment()
+
+ fun inputs(block: PropertiesAssignmentBuilder.() -> Unit) {
+ operationAssignment.inputs = PropertiesAssignmentBuilder().apply(block).build()
+ }
+
+ fun build(): OperationAssignment {
+ operationAssignment.id = id
+ operationAssignment.description = description
+ return operationAssignment
+ }
+}
+
+class PropertiesAssignmentBuilder {
+ private var properties: MutableMap<String, JsonNode> = hashMapOf()
+
+ fun property(id: String, value: Any) {
+ property(id, value.asJsonType())
+ }
+
+ fun property(id: String, value: JsonNode) {
+ properties[id] = value
+ }
+
+ fun build(): MutableMap<String, JsonNode> {
+ return properties
+ }
+}
+
+class AttributesAssignmentBuilder {
+ private var attributes: MutableMap<String, JsonNode> = hashMapOf()
+
+ fun attribute(id: String, value: String) {
+ attribute(id, value.asJsonType())
+ }
+
+ fun attribute(id: String, value: JsonNode) {
+ attributes[id] = value
+ }
+
+ fun build(): MutableMap<String, JsonNode> {
+ return attributes
+ }
+} \ No newline at end of file
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
new file mode 100644
index 000000000..d60bdbb05
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt
@@ -0,0 +1,324 @@
+/*
+ * 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.data.*
+
+
+open class EntityTypeBuilder(private val id: String,
+ private val version: 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? = "") {
+ 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? = "") {
+ if (properties == null)
+ properties = hashMapOf()
+ val property = PropertyDefinitionBuilder(id, type, required, description).build()
+ properties!![id] = property
+ }
+
+ fun buildEntityType(entity: EntityType) {
+ entity.id = id
+ entity.description = description
+ entity.version = version
+ entity.derivedFrom = derivedFrom
+ entity.metadata = metadata
+ entity.properties = properties
+ entity.attributes = attributes
+ }
+}
+
+class NodeTypeBuilder(private val id: String, private val version: String,
+ private val description: String? = "") : EntityTypeBuilder(id, version, 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) {
+ if (capabilities == null)
+ capabilities = hashMapOf()
+ capabilities!![id] = CapabilityDefinitionBuilder(id).apply(block).build()
+ }
+
+ fun requirement(id: String, block: RequirementDefinitionBuilder.() -> Unit) {
+ if (requirements == null)
+ requirements = hashMapOf()
+ requirements!![id] = RequirementDefinitionBuilder(id).apply(block).build()
+ }
+
+ fun artifact(id: String, type: String, file: String) {
+ if (artifacts == null)
+ artifacts = hashMapOf()
+ artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).build()
+ }
+
+ private fun nodeInterface(id: String, block: InterfaceDefinitionBuilder.() -> Unit) {
+ if (interfaces == null)
+ interfaces = hashMapOf()
+ interfaces!![id] = InterfaceDefinitionBuilder(id).apply(block).build()
+ }
+
+ fun build(): NodeType {
+ buildEntityType(nodeType)
+ nodeType.capabilities = capabilities
+ nodeType.requirements = requirements
+ nodeType.interfaces = interfaces
+ nodeType.artifacts = artifacts
+ return nodeType
+ }
+}
+
+class ArtifactTypeBuilder(private val id: String, private val version: String,
+ private val description: String? = "") : EntityTypeBuilder(id, version, description) {
+ private var artifactType = ArtifactType()
+ //TODO()
+ fun build(): ArtifactType {
+ buildEntityType(artifactType)
+ return artifactType
+ }
+}
+
+class RequirementTypeBuilder(private val id: String, private val version: String,
+ private val description: String? = "") : EntityTypeBuilder(id, version, description) {
+ private var requirementType = RequirementType()
+ // TODO()
+ fun build(): RequirementType {
+ buildEntityType(requirementType)
+ return requirementType
+ }
+}
+
+class RelationshipTypeBuilder(private val id: String, private val version: String,
+ private val description: String? = "") : EntityTypeBuilder(id, version, description) {
+ private var relationshipType = RelationshipType()
+ // TODO()
+ fun build(): RelationshipType {
+ buildEntityType(relationshipType)
+ return relationshipType
+ }
+}
+
+class DataTypeBuilder(private val id: String, private val version: String,
+ private val description: String? = "") : EntityTypeBuilder(id, version, description) {
+ private var dataType = DataType()
+ // TODO()
+ fun build(): DataType {
+ buildEntityType(dataType)
+ return dataType
+ }
+}
+
+class CapabilityDefinitionBuilder(private val id: 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? = "") {
+ val property = PropertyDefinitionBuilder(id, type, required, description).build()
+ properties.put(id, property)
+ }
+
+ fun build(): CapabilityDefinition {
+ capabilityDefinition.id = id
+ capabilityDefinition.properties = properties
+ return capabilityDefinition
+ }
+}
+
+class RequirementDefinitionBuilder(private val id: String) {
+ private var requirementDefinition = RequirementDefinition()
+ // TODO()
+ fun build(): RequirementDefinition {
+ requirementDefinition.id = id
+
+ return requirementDefinition
+ }
+}
+
+class InterfaceDefinitionBuilder(private val id: String) {
+
+ private var interfaceDefinition: InterfaceDefinition = InterfaceDefinition()
+ private var operations: MutableMap<String, OperationDefinition>? = null
+
+ fun operation(id: String, description: String? = "", block: OperationDefinitionBuilder.() -> Unit) {
+ if (operations == null)
+ operations = hashMapOf()
+ operations!![id] = OperationDefinitionBuilder(id, description).apply(block).build()
+ }
+
+ fun build(): InterfaceDefinition {
+ interfaceDefinition.id = id
+ interfaceDefinition.operations = operations
+ return interfaceDefinition
+ }
+}
+
+class OperationDefinitionBuilder(private val id: String,
+ private val description: String? = "") {
+ private var operationDefinition: OperationDefinition = OperationDefinition()
+
+ fun inputs(block: PropertiesDefinitionBuilder.() -> Unit) {
+ operationDefinition.inputs = PropertiesDefinitionBuilder().apply(block).build()
+ }
+
+ fun outputs(block: PropertiesDefinitionBuilder.() -> Unit) {
+ operationDefinition.outputs = PropertiesDefinitionBuilder().apply(block).build()
+ }
+
+ fun build(): OperationDefinition {
+ operationDefinition.id = id
+ operationDefinition.description = description
+ return operationDefinition
+ }
+}
+
+class AttributesDefinitionBuilder {
+ private val attributes: MutableMap<String, AttributeDefinition> = hashMapOf()
+
+ fun property(id: String, attribute: AttributeDefinition) {
+ attributes.put(id, attribute)
+ }
+
+ fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "") {
+ val attribute = AttributeDefinitionBuilder(id, type, required, description).build()
+ attributes.put(id, attribute)
+ }
+
+ fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "",
+ block: AttributeDefinitionBuilder.() -> Unit) {
+ val attribute = AttributeDefinitionBuilder(id, type, required, description).apply(block).build()
+ attributes.put(id, attribute)
+ }
+
+ fun build(): MutableMap<String, AttributeDefinition> {
+ return attributes
+ }
+}
+
+class AttributeDefinitionBuilder(private val id: String,
+ private val type: String? = "string",
+ private val required: Boolean? = false,
+ private val description: String? = "") {
+
+ private var attributeDefinition: 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.description = description
+ return attributeDefinition
+ }
+}
+
+class PropertiesDefinitionBuilder {
+ private val properties: MutableMap<String, PropertyDefinition> = hashMapOf()
+
+ fun property(id: String, property: PropertyDefinition) {
+ properties.put(id, property)
+ }
+
+ fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "") {
+ val property = PropertyDefinitionBuilder(id, type, required, description).build()
+ properties.put(id, property)
+ }
+
+ fun property(id: String, type: String? = "string", required: Boolean? = false, description: String? = "",
+ block: PropertyDefinitionBuilder.() -> Unit) {
+ val property = PropertyDefinitionBuilder(id, type, required, description).apply(block).build()
+ properties.put(id, property)
+ }
+
+ fun build(): MutableMap<String, PropertyDefinition> {
+ return properties
+ }
+}
+
+class PropertyDefinitionBuilder(private val id: String,
+ private val type: String? = "string",
+ private val required: Boolean? = false,
+ 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.description = description
+ return propertyDefinition
+ }
+}
+
+class EntrySchemaBuilder(private val type: String) {
+ private var entrySchema: EntrySchema = EntrySchema()
+
+ fun build(): EntrySchema {
+ entrySchema.type = type
+ return entrySchema
+ }
+} \ No newline at end of file
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
new file mode 100644
index 000000000..2c0192534
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt
@@ -0,0 +1,52 @@
+/*
+ * 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.junit.Test
+import kotlin.test.assertNotNull
+
+class BluePrintDSLTest {
+ @Test
+ fun testServiceTemplate() {
+ val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
+ "brindasanth@onap.com", "sample") {
+ metadata("release", "1806")
+ topologyTemplate {
+ nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
+ operationName = "process", description = "sample activation") {
+ inputs {
+ property("json-content", """{ "name" : "cds"}""")
+ property("array-content", """["controller", "blueprints"]""")
+ property("int-value", 234)
+ property("boolean-value", true)
+ 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"))
+ }
+ }
+ }
+ }
+
+ 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))
+ }
+}