From ba75d2fad2b0111a510f4ee4cc87e658fb32ac4b Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Tue, 31 Dec 2019 10:53:59 -0500 Subject: Flexible DSL Types and Templates definition. Easy search definitions Types and Templates inside ServiceTemplate DSL builder. Unit test modifications to support this change. Issue-ID: CCSDK-1054 Signed-off-by: Brinda Santh Change-Id: Ie944ff5f75f80c852555306e1a4e0fa7f5b803d7 --- .../controllerblueprints/core/dsl/BluePrintDSL.kt | 69 ++++++- .../core/dsl/BluePrintServiceDSLBuilder.kt | 230 --------------------- .../core/dsl/BluePrintTemplateDSLBuilder.kt | 2 +- .../core/dsl/ServiceTemplateBuilder.kt | 225 ++++++++++++++++++++ .../core/dsl/BluePrintDSLTest.kt | 27 ++- 5 files changed, 317 insertions(+), 236 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/ServiceTemplateBuilder.kt (limited to 'ms/blueprintsprocessor/modules/blueprints') diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt index c23e495fb..3c5561994 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt @@ -46,9 +46,9 @@ fun serviceTemplate( version: String, author: String, tags: String, - block: BluePrintServiceDSLBuilder.() -> Unit + block: ServiceTemplateBuilder.() -> Unit ): ServiceTemplate { - return BluePrintServiceDSLBuilder(name, version, author, tags).apply(block).build() + return ServiceTemplateBuilder(name, version, author, tags).apply(block).build() } fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit): Workflow { @@ -171,6 +171,11 @@ fun getNodeTemplateOperationOutput( } /** Blueprint Type Extensions */ +fun ServiceTemplateBuilder.nodeTypeComponent() { + val nodeType = BluePrintTypes.nodeTypeComponent() + if (this.nodeTypes == null) this.nodeTypes = hashMapOf() + this.nodeTypes!![nodeType.id!!] = nodeType +} fun BluePrintTypes.nodeTypeComponent(): NodeType { return nodeType( @@ -182,6 +187,7 @@ fun BluePrintTypes.nodeTypeComponent(): NodeType { } } +@Deprecated("CDS won't support, use implerative workflow definitions.") fun BluePrintTypes.nodeTypeWorkflow(): NodeType { return nodeType( id = BluePrintConstants.MODEL_TYPE_NODE_WORKFLOW, @@ -192,6 +198,12 @@ fun BluePrintTypes.nodeTypeWorkflow(): NodeType { } } +fun ServiceTemplateBuilder.nodeTypeVnf() { + val nodeType = BluePrintTypes.nodeTypeVnf() + if (this.nodeTypes == null) this.nodeTypes = hashMapOf() + this.nodeTypes!![nodeType.id!!] = nodeType +} + fun BluePrintTypes.nodeTypeVnf(): NodeType { return nodeType( id = BluePrintConstants.MODEL_TYPE_NODE_VNF, @@ -202,6 +214,12 @@ fun BluePrintTypes.nodeTypeVnf(): NodeType { } } +fun ServiceTemplateBuilder.nodeTypeResourceSource() { + val nodeType = BluePrintTypes.nodeTypeResourceSource() + if (this.nodeTypes == null) this.nodeTypes = hashMapOf() + this.nodeTypes!![nodeType.id!!] = nodeType +} + fun BluePrintTypes.nodeTypeResourceSource(): NodeType { return nodeType( id = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, @@ -213,6 +231,11 @@ fun BluePrintTypes.nodeTypeResourceSource(): NodeType { } /** Artifacts */ +fun ServiceTemplateBuilder.artifactTypeTemplateVelocity() { + val artifactType = BluePrintTypes.artifactTypeTemplateVelocity() + if (this.artifactTypes == null) this.artifactTypes = hashMapOf() + this.artifactTypes!![artifactType.id!!] = artifactType +} fun BluePrintTypes.artifactTypeTemplateVelocity(): ArtifactType { return artifactType( @@ -225,6 +248,12 @@ fun BluePrintTypes.artifactTypeTemplateVelocity(): ArtifactType { } } +fun ServiceTemplateBuilder.artifactTypeTempleJinja() { + val artifactType = BluePrintTypes.artifactTypeTempleJinja() + if (this.artifactTypes == null) this.artifactTypes = hashMapOf() + this.artifactTypes!![artifactType.id!!] = artifactType +} + fun BluePrintTypes.artifactTypeTempleJinja(): ArtifactType { return artifactType( id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA, @@ -236,6 +265,12 @@ fun BluePrintTypes.artifactTypeTempleJinja(): ArtifactType { } } +fun ServiceTemplateBuilder.artifactTypeMappingResource() { + val artifactType = BluePrintTypes.artifactTypeMappingResource() + if (this.artifactTypes == null) this.artifactTypes = hashMapOf() + this.artifactTypes!![artifactType.id!!] = artifactType +} + fun BluePrintTypes.artifactTypeMappingResource(): ArtifactType { return artifactType( id = BluePrintConstants.MODEL_TYPE_ARTIFACT_MAPPING_RESOURCE, @@ -259,6 +294,12 @@ fun BluePrintTypes.artifactTypeScriptJython(): ArtifactType { } } +fun ServiceTemplateBuilder.artifactTypeScriptKotlin() { + val artifactType = BluePrintTypes.artifactTypeScriptKotlin() + if (this.artifactTypes == null) this.artifactTypes = hashMapOf() + this.artifactTypes!![artifactType.id!!] = artifactType +} + fun BluePrintTypes.artifactTypeScriptKotlin(): ArtifactType { return artifactType( id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_KOTLIN, @@ -282,6 +323,12 @@ fun BluePrintTypes.artifactTypeDirectedGraph(): ArtifactType { } } +fun ServiceTemplateBuilder.artifactTypeComponentJar() { + val artifactType = BluePrintTypes.artifactTypeComponentJar() + if (this.artifactTypes == null) this.artifactTypes = hashMapOf() + this.artifactTypes!![artifactType.id!!] = artifactType +} + fun BluePrintTypes.artifactTypeComponentJar(): ArtifactType { return artifactType( id = BluePrintConstants.MODEL_TYPE_ARTIFACT_COMPONENT_JAR, @@ -295,6 +342,12 @@ fun BluePrintTypes.artifactTypeComponentJar(): ArtifactType { /** Relationship Types */ +fun ServiceTemplateBuilder.relationshipTypeConnectsTo() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsTo() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsTo(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, @@ -306,6 +359,12 @@ fun BluePrintTypes.relationshipTypeConnectsTo(): RelationshipType { } } +fun ServiceTemplateBuilder.relationshipTypeDependsOn() { + val relationshipType = BluePrintTypes.relationshipTypeDependsOn() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeDependsOn(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON, @@ -316,6 +375,12 @@ fun BluePrintTypes.relationshipTypeDependsOn(): RelationshipType { } } +fun ServiceTemplateBuilder.relationshipTypeHostedOn() { + val relationshipType = BluePrintTypes.relationshipTypeHostedOn() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeHostedOn(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_HOSTED_ON, diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt deleted file mode 100644 index a3db88b6a..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintServiceDSLBuilder.kt +++ /dev/null @@ -1,230 +0,0 @@ -/* - * 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.asBluePrintsDataTypes -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType -import org.onap.ccsdk.cds.controllerblueprints.core.asPropertyDefinitionMap -import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType -import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType -import org.onap.ccsdk.cds.controllerblueprints.core.data.ImportDefinition -import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.cds.controllerblueprints.core.data.PolicyType -import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType -import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate -import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate -import kotlin.reflect.KClass - -class BluePrintServiceDSLBuilder( - private val name: String, - private val version: String, - private val author: String, - private val tags: String -) { - - private var serviceTemplate = ServiceTemplate() - private var topologyTemplate: TopologyTemplate? = null - private var metadata: MutableMap = hashMapOf() - private var dslDefinitions: MutableMap? = null - private var imports: MutableList = mutableListOf() - private var nodeTypes: MutableMap? = null - private var artifactTypes: MutableMap? = null - private var dataTypes: MutableMap? = null - private var relationshipTypes: MutableMap? = null - private var policyTypes: MutableMap? = 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 import(file: String) { - val importDefinition = ImportDefinition().apply { - this.file = file - } - imports.add(importDefinition) - } - - fun dsl(id: String, kclass: KClass<*>) { - dsl(id, kclass.asPropertyDefinitionMap().asJsonNode()) - } - - fun dataType(dataType: KClass<*>) { - dataType(dataType.asBluePrintsDataTypes()) - } - - fun dsl(id: String, content: Any) { - dsl(id, content.asJsonType()) - } - - fun dsl(id: String, json: JsonNode) { - if (dslDefinitions == null) dslDefinitions = hashMapOf() - dslDefinitions!![id] = json - } - - fun dataTypes(dataTypes: MutableMap) { - if (this.dataTypes == null) this.dataTypes = hashMapOf() - - this.dataTypes!!.putAll(dataTypes) - } - - fun artifactTypes(artifactTypes: MutableMap) { - if (this.artifactTypes == null) this.artifactTypes = hashMapOf() - - this.artifactTypes!!.putAll(artifactTypes) - } - - fun relationshipTypes(relationshipTypes: MutableMap) { - if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() - - this.relationshipTypes!!.putAll(relationshipTypes) - } - - fun policyTypes(policyTypes: MutableMap) { - if (this.policyTypes == null) this.policyTypes = hashMapOf() - - this.policyTypes!!.putAll(policyTypes) - } - - fun nodeType(nodeTypes: MutableMap) { - if (this.nodeTypes == null) this.nodeTypes = hashMapOf() - - this.nodeTypes!!.putAll(nodeTypes) - } - - fun dataType(dataType: DataType) { - if (dataTypes == null) dataTypes = hashMapOf() - dataTypes!![dataType.id!!] = dataType - } - - fun artifactType(artifactType: ArtifactType) { - if (artifactTypes == null) artifactTypes = hashMapOf() - artifactTypes!![artifactType.id!!] = artifactType - } - - fun relationshipType(relationshipType: RelationshipType) { - if (relationshipTypes == null) relationshipTypes = hashMapOf() - relationshipTypes!![relationshipType.id!!] = relationshipType - } - - fun relationshipTypes(relationshipTypes: List) { - if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() - relationshipTypes.forEach { relationshipType -> - this.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 nodeTypes(nodeTypes: List) { - if (this.nodeTypes == null) this.nodeTypes = hashMapOf() - nodeTypes.forEach { nodeType -> - this.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, - derivedFrom: String, - description: String, - block: NodeTypeBuilder.() -> Unit - ) { - if (nodeTypes == null) nodeTypes = hashMapOf() - nodeTypes!![id] = NodeTypeBuilder(id, version, derivedFrom, 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.policyTypes = policyTypes - serviceTemplate.topologyTemplate = topologyTemplate - return serviceTemplate - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt index 216a0d16f..a89267387 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt @@ -36,7 +36,7 @@ import kotlin.reflect.jvm.reflect open class TopologyTemplateBuilder { private var topologyTemplate = TopologyTemplate() - private var nodeTemplates: MutableMap? = null + var nodeTemplates: MutableMap? = null var relationshipTemplates: MutableMap? = null private var workflows: MutableMap? = null diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/ServiceTemplateBuilder.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/ServiceTemplateBuilder.kt new file mode 100644 index 000000000..254e644b3 --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/ServiceTemplateBuilder.kt @@ -0,0 +1,225 @@ +/* + * 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.asBluePrintsDataTypes +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.onap.ccsdk.cds.controllerblueprints.core.asPropertyDefinitionMap +import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType +import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType +import org.onap.ccsdk.cds.controllerblueprints.core.data.ImportDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.cds.controllerblueprints.core.data.PolicyType +import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType +import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate +import kotlin.reflect.KClass + +class ServiceTemplateBuilder( + private val name: String, + private val version: String, + private val author: String, + private val tags: String +) { + + private var serviceTemplate = ServiceTemplate() + private var topologyTemplate: TopologyTemplate? = null + private var metadata: MutableMap = hashMapOf() + private var dslDefinitions: MutableMap? = null + private var imports: MutableList = mutableListOf() + var nodeTypes: MutableMap? = null + var artifactTypes: MutableMap? = null + var dataTypes: MutableMap? = null + var relationshipTypes: MutableMap? = null + var policyTypes: MutableMap? = 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 import(file: String) { + val importDefinition = ImportDefinition().apply { + this.file = file + } + imports.add(importDefinition) + } + + fun dsl(id: String, kclass: KClass<*>) { + dsl(id, kclass.asPropertyDefinitionMap().asJsonNode()) + } + + fun dataType(dataType: KClass<*>) { + dataType(dataType.asBluePrintsDataTypes()) + } + + fun dsl(id: String, content: Any) { + dsl(id, content.asJsonType()) + } + + fun dsl(id: String, json: JsonNode) { + if (dslDefinitions == null) dslDefinitions = hashMapOf() + dslDefinitions!![id] = json + } + + fun dataTypes(dataTypes: MutableMap) { + if (this.dataTypes == null) this.dataTypes = hashMapOf() + + this.dataTypes!!.putAll(dataTypes) + } + + fun artifactTypes(artifactTypes: MutableMap) { + if (this.artifactTypes == null) this.artifactTypes = hashMapOf() + this.artifactTypes!!.putAll(artifactTypes) + } + + fun relationshipTypes(relationshipTypes: MutableMap) { + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!!.putAll(relationshipTypes) + } + + fun policyTypes(policyTypes: MutableMap) { + if (this.policyTypes == null) this.policyTypes = hashMapOf() + this.policyTypes!!.putAll(policyTypes) + } + + fun nodeType(nodeTypes: MutableMap) { + if (this.nodeTypes == null) this.nodeTypes = hashMapOf() + this.nodeTypes!!.putAll(nodeTypes) + } + + fun dataType(dataType: DataType) { + if (dataTypes == null) dataTypes = hashMapOf() + dataTypes!![dataType.id!!] = dataType + } + + fun artifactType(artifactType: ArtifactType) { + if (artifactTypes == null) artifactTypes = hashMapOf() + artifactTypes!![artifactType.id!!] = artifactType + } + + fun relationshipType(relationshipType: RelationshipType) { + if (relationshipTypes == null) relationshipTypes = hashMapOf() + relationshipTypes!![relationshipType.id!!] = relationshipType + } + + fun relationshipTypes(relationshipTypes: List) { + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + relationshipTypes.forEach { relationshipType -> + this.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 nodeTypes(nodeTypes: List) { + if (this.nodeTypes == null) this.nodeTypes = hashMapOf() + nodeTypes.forEach { nodeType -> + this.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, + derivedFrom: String, + description: String, + block: NodeTypeBuilder.() -> Unit + ) { + if (nodeTypes == null) nodeTypes = hashMapOf() + nodeTypes!![id] = NodeTypeBuilder(id, version, derivedFrom, 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.policyTypes = policyTypes + serviceTemplate.topologyTemplate = topologyTemplate + return serviceTemplate + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt index c2d764bd6..bf16ea93a 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt @@ -100,6 +100,21 @@ class BluePrintDSLTest { import("Definition/data_types.json") dsl("rest-endpoint", """{ "selector" : "odl-selector"}""") dsl("db-endpoint", """{ "selector" : "db-selector"}""") + + nodeTypeComponent() + nodeTypeResourceSource() + nodeTypeVnf() + + artifactTypeTemplateVelocity() + artifactTypeTempleJinja() + artifactTypeScriptKotlin() + artifactTypeMappingResource() + artifactTypeComponentJar() + + relationshipTypeConnectsTo() + relationshipTypeDependsOn() + relationshipTypeHostedOn() + topologyTemplate { nodeTemplateOperation( nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor", @@ -162,10 +177,16 @@ class BluePrintDSLTest { } } + // println(serviceTemplate.asJsonString(true)) + assertNotNull(serviceTemplate.artifactTypes, "failed to get artifactTypes") + assertNotNull(serviceTemplate.nodeTypes, "failed to get nodeTypes") + assertNotNull(serviceTemplate.relationshipTypes, "failed to get relationshipTypes") 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(serviceTemplate.asJsonString(true)) + assertNotNull( + serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], + "failed to get nodeTypes(activate)" + ) } @Test @@ -254,7 +275,7 @@ fun BluePrintTypes.nodeTemplateComponentTestExecutor( description: String, block: TestNodeTemplateOperationImplBuilder.() -> Unit ): - NodeTemplate { + NodeTemplate { return TestNodeTemplateOperationImplBuilder(id, description).apply(block).build() } -- cgit 1.2.3-korg