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 --- .../resolution/ResourceResolutionComponentDSL.kt | 28 ++- .../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 ++- .../db/DatabasePropertiesDSL.kt | 7 + .../db/DatabasePropertiesDSLTest.kt | 25 ++- .../blueprintsprocessor/grpc/GrpcPropertiesDSL.kt | 13 ++ .../grpc/GrpcPropertiesDSLTest.kt | 48 +++-- .../message/MessagePropertiesDSL.kt | 13 ++ .../message/MessagePropertiesDSLTest.kt | 47 +++-- .../blueprintsprocessor/nats/NatsPropertiesDSL.kt | 7 + .../nats/NatsPropertiesDSLTest.kt | 25 ++- .../rest/RestClientPropertiesDSL.kt | 7 + .../rest/service/RestClientPropertiesDSLTest.kt | 22 +- .../blueprintsprocessor/ssh/SshPropertiesDSL.kt | 7 + .../ssh/SshPropertiesDSLTest.kt | 24 ++- .../execution/ComponentRemoteScriptExecutorDSL.kt | 23 ++- .../execution/ComponentScriptExecutorDSL.kt | 30 ++- .../execution/ComponentRemoteScriptExecutorTest.kt | 52 +++-- .../execution/ComponentScriptExecutorDSLTest.kt | 62 ++++++ 22 files changed, 666 insertions(+), 327 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 create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSLTest.kt (limited to 'ms') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt index 25338c6ca..6573d0e9a 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt @@ -26,10 +26,18 @@ import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType /** Component Extensions **/ +fun ServiceTemplateBuilder.nodeTypeComponentResourceResolution() { + val nodeType = BluePrintTypes.nodeTypeComponentResourceResolution() + if (this.nodeTypes == null) this.nodeTypes = hashMapOf() + this.nodeTypes!![nodeType.id!!] = nodeType +} + fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType { return nodeType( id = "component-resource-resolution", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, @@ -112,19 +120,31 @@ fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType { } /** Component Builder */ +fun TopologyTemplateBuilder.nodeTemplateComponentResourceResolution( + id: String, + description: String, + block: ComponentResourceResolutionNodeTemplateBuilder.() -> Unit +) { + val nodeTemplate = BluePrintTypes.nodeTemplateComponentResourceResolution( + id, description, + block + ) + if (nodeTemplates == null) nodeTemplates = hashMapOf() + nodeTemplates!![nodeTemplate.id!!] = nodeTemplate +} + fun BluePrintTypes.nodeTemplateComponentResourceResolution( id: String, description: String, block: ComponentResourceResolutionNodeTemplateBuilder.() -> Unit -): - NodeTemplate { +): NodeTemplate { return ComponentResourceResolutionNodeTemplateBuilder(id, description).apply(block).build() } class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: String) : AbstractNodeTemplateOperationImplBuilder( + ComponentResourceResolutionNodeTemplateBuilder.InputsBuilder, + ComponentResourceResolutionNodeTemplateBuilder.OutputsBuilder>( id, "component-script-executor", "ComponentResourceResolution", description 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() } diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt index 2bf56f482..34dd0a417 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt @@ -24,10 +24,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for Database Producer */ +fun ServiceTemplateBuilder.relationshipTypeConnectsToDb() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToDb() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToDb(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB, diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt index b0c7d8b3c..dd84e5b02 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -52,19 +52,28 @@ class DatabasePropertiesDSLTest { } } } - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToDb(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToDb() + relationshipTypeConnectsTo() } + + // println(serviceTemplate.asJsonString(true)) assertNotNull(serviceTemplate, "failed to create service template") val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates assertNotNull(relationshipTemplates, "failed to get relationship templates") assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match") assertNotNull(relationshipTemplates["sample-maria-db"], "failed to get sample-maria-db") assertNotNull(relationshipTemplates["sample-mysql-db"], "failed to get sample-mysql-db") - // println(serviceTemplate.asJsonString(true)) + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB}" + ) } } diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSL.kt index 354e38dc7..8063e8909 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSL.kt @@ -24,10 +24,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for GRPC Server Producer */ +fun ServiceTemplateBuilder.relationshipTypeConnectsToGrpcServer() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToGrpcServer() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToGrpcServer(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER, @@ -45,6 +52,12 @@ fun BluePrintTypes.relationshipTypeConnectsToGrpcServer(): RelationshipType { } } +fun ServiceTemplateBuilder.relationshipTypeConnectsToGrpcClient() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToGrpcClient() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToGrpcClient(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT, diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSLTest.kt index 9b3cf80bc..3de857fa5 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/GrpcPropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -44,20 +44,29 @@ class GrpcPropertiesDSLTest { } } } - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToGrpcServer(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToGrpcServer() + relationshipTypeConnectsTo() } + + // println(serviceTemplate.asJsonString(true)) assertNotNull(serviceTemplate, "failed to create service template") val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates assertNotNull(relationshipTemplates, "failed to get relationship templates") assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match") assertNotNull(relationshipTemplates["sample-tls-auth"], "failed to get sample-tls-auth") assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth") - // println(serviceTemplate.asJsonString(true)) + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER}" + ) } @Test @@ -89,13 +98,11 @@ class GrpcPropertiesDSLTest { } } } - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToGrpcClient(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToGrpcClient() + relationshipTypeConnectsTo() } + + // println(serviceTemplate.asJsonString(true)) assertNotNull(serviceTemplate, "failed to create service template") val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates assertNotNull(relationshipTemplates, "failed to get relationship templates") @@ -103,6 +110,17 @@ class GrpcPropertiesDSLTest { assertNotNull(relationshipTemplates["sample-tls-auth"], "failed to get sample-tls-auth") assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth") assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth") - // println(serviceTemplate.asJsonString(true)) + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT}" + ) } } diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSL.kt index c6e923948..88039466d 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSL.kt @@ -24,10 +24,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for Message Producer */ +fun ServiceTemplateBuilder.relationshipTypeConnectsToMessageProducer() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToMessageProducer() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToMessageProducer(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER, @@ -45,6 +52,12 @@ fun BluePrintTypes.relationshipTypeConnectsToMessageProducer(): RelationshipType } } +fun ServiceTemplateBuilder.relationshipTypeConnectsToMessageConsumer() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToMessageConsumer() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToMessageConsumer(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER, diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSLTest.kt index 9ece90ffc..b10e1023b 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/MessagePropertiesDSLTest.kt @@ -18,7 +18,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.message import org.apache.kafka.streams.StreamsConfig import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -41,19 +41,28 @@ class MessagePropertiesDSLTest { } } } - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToMessageProducer(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToMessageProducer() + relationshipTypeConnectsTo() } + + // println(serviceTemplate.asJsonString(true)) assertNotNull(serviceTemplate, "failed to create service template") val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates assertNotNull(relationshipTemplates, "failed to get relationship templates") assertEquals(1, relationshipTemplates.size, "relationshipTemplates doesn't match") assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth") - // println(serviceTemplate.asJsonString(true)) + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER}" + ) } @Test @@ -82,20 +91,28 @@ class MessagePropertiesDSLTest { } } } - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToMessageConsumer(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToMessageConsumer() + relationshipTypeConnectsTo() } + // println(serviceTemplate.asJsonString(true)) assertNotNull(serviceTemplate, "failed to create service template") val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates assertNotNull(relationshipTemplates, "failed to get relationship templates") assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match") assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth") assertNotNull(relationshipTemplates["sample-stream-basic-auth"], "failed to get sample-stream-basic-auth") - // println(serviceTemplate.asJsonString(true)) + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER}" + ) } } diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSL.kt index 5c4301b38..8ef476446 100644 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSL.kt @@ -24,10 +24,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for NATS Producer */ +fun ServiceTemplateBuilder.relationshipTypeConnectsToNats() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToNats() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToNats(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS, diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSLTest.kt index 4cf474b93..a95b900fe 100644 --- a/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/nats-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nats/NatsPropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.nats import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getInput import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate @@ -43,21 +43,28 @@ class NatsPropertiesDSLTest { } } } - - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToNats(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToNats() + relationshipTypeConnectsTo() } + // println(serviceTemplate.asJsonString(true)) assertNotNull(serviceTemplate, "failed to create service template") val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates assertNotNull(relationshipTemplates, "failed to get relationship templates") assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match") assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth") assertNotNull(relationshipTemplates["sample-tls-auth"], "failed to get sample-tls-auth") - // println(serviceTemplate.asJsonString(true)) + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_NATS}" + ) } } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt index 4c25cb5bf..5d68e5d43 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt @@ -24,10 +24,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Type DSL for Rest */ +fun ServiceTemplateBuilder.relationshipTypeConnectsToRestClient() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToRestClient() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToRestClient(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt index 28784e4ae..f06f827ad 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt @@ -19,7 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest.service import org.junit.Test import org.onap.ccsdk.cds.blueprintsprocessor.rest.relationshipTemplateRestClient import org.onap.ccsdk.cds.blueprintsprocessor.rest.relationshipTypeConnectsToRestClient -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -56,12 +56,8 @@ class RestClientPropertiesDSLTest { } } } - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToRestClient(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToRestClient() + relationshipTypeConnectsTo() } // println(serviceTemplate.asJsonString(true)) @@ -72,5 +68,17 @@ class RestClientPropertiesDSLTest { assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth") assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth") assertNotNull(relationshipTemplates["sample-ssl-auth"], "failed to get sample-ssl-auth") + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT}" + ) } } diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSL.kt index e63f2eb49..ee7a7dead 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSL.kt @@ -24,10 +24,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for Message Producer */ +fun ServiceTemplateBuilder.relationshipTypeConnectsToSshClient() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToSshClient() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToSshClient(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT, diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSLTest.kt index bc4355357..85891b1b5 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/SshPropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.ssh import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -38,19 +38,27 @@ class SshPropertiesDSLTest { } } } - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToSshClient(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToSshClient() + relationshipTypeConnectsTo() } + // println(serviceTemplate.asJsonString(true)) assertNotNull(serviceTemplate, "failed to create service template") val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates assertNotNull(relationshipTemplates, "failed to get relationship templates") assertEquals(1, relationshipTemplates.size, "relationshipTemplates doesn't match") assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth") - // println(serviceTemplate.asJsonString(true)) + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_SSH_CLIENT}" + ) } } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorDSL.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorDSL.kt index 0210e88ea..7bb071501 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorDSL.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorDSL.kt @@ -25,9 +25,16 @@ import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType /** Component Extensions **/ +fun ServiceTemplateBuilder.nodeTypeComponentRemoteScriptExecutor() { + val nodeType = BluePrintTypes.nodeTypeComponentRemoteScriptExecutor() + if (this.nodeTypes == null) this.nodeTypes = hashMapOf() + this.nodeTypes!![nodeType.id!!] = nodeType +} fun BluePrintTypes.nodeTypeComponentRemoteScriptExecutor(): NodeType { return nodeType( @@ -86,12 +93,24 @@ fun BluePrintTypes.nodeTypeComponentRemoteScriptExecutor(): NodeType { } /** Component Builder */ +fun TopologyTemplateBuilder.nodeTemplateComponentRemoteScriptExecutor( + id: String, + description: String, + block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit +) { + val nodeTemplate = BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor( + id, description, + block + ) + if (nodeTemplates == null) nodeTemplates = hashMapOf() + nodeTemplates!![nodeTemplate.id!!] = nodeTemplate +} + fun BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor( id: String, description: String, block: ComponentRemoteScriptExecutorNodeTemplateBuilder.() -> Unit -): - NodeTemplate { +): NodeTemplate { return ComponentRemoteScriptExecutorNodeTemplateBuilder(id, description).apply(block).build() } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt index d4ca0f487..8592ce62b 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt @@ -25,10 +25,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType import kotlin.reflect.KClass /** Component Extensions **/ +fun ServiceTemplateBuilder.nodeTypeComponentScriptExecutor() { + val nodeType = BluePrintTypes.nodeTypeComponentScriptExecutor() + if (this.nodeTypes == null) this.nodeTypes = hashMapOf() + this.nodeTypes!![nodeType.id!!] = nodeType +} fun BluePrintTypes.nodeTypeComponentScriptExecutor(): NodeType { return nodeType( @@ -80,19 +87,31 @@ fun BluePrintTypes.nodeTypeComponentScriptExecutor(): NodeType { } /** Component Builder */ +fun TopologyTemplateBuilder.nodeTemplateComponentScriptExecutor( + id: String, + description: String, + block: ComponentScriptExecutorNodeTemplateBuilder.() -> Unit +) { + val nodeTemplate = BluePrintTypes.nodeTemplateComponentScriptExecutor( + id, description, + block + ) + if (nodeTemplates == null) nodeTemplates = hashMapOf() + nodeTemplates!![nodeTemplate.id!!] = nodeTemplate +} + fun BluePrintTypes.nodeTemplateComponentScriptExecutor( id: String, description: String, block: ComponentScriptExecutorNodeTemplateBuilder.() -> Unit -): - NodeTemplate { +): NodeTemplate { return ComponentScriptExecutorNodeTemplateBuilder(id, description).apply(block).build() } class ComponentScriptExecutorNodeTemplateBuilder(id: String, description: String) : AbstractNodeTemplateOperationImplBuilder( + ComponentScriptExecutorNodeTemplateBuilder.InputsBuilder, + ComponentScriptExecutorNodeTemplateBuilder.OutputsBuilder>( id, "component-script-executor", "ComponentScriptExecutor", description @@ -110,7 +129,8 @@ class ComponentScriptExecutorNodeTemplateBuilder(id: String, description: String scriptClassReference(scriptClassReference.qualifiedName!!) } - fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive()) + fun scriptClassReference(scriptClassReference: String) = + scriptClassReference(scriptClassReference.asJsonPrimitive()) fun scriptClassReference(scriptClassReference: JsonNode) { property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference) diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorTest.kt index 2091e0366..0125cd8d9 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentRemoteScriptExecutorTest.kt @@ -36,6 +36,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext @@ -54,26 +55,41 @@ class ComponentRemoteScriptExecutorTest { @Test fun testNodeTemplateComponentRemoteScriptExecutor() { - val nodeTemplate = BluePrintTypes.nodeTemplateComponentRemoteScriptExecutor( - "remote-sample", - "This is sample node template" - ) { - definedOperation(" Sample Operation") { - implementation(180, "SELF") - inputs { - selector("remote-script-executor") - blueprintName("sample") - blueprintVersion("1.0.0") - blueprintAction("sample-action") - timeout(120) - requestData("""{"key" :"value"}""") - } - outputs { - status("success") + val serviceTemplate = serviceTemplate("remote-script-dsl", "1.0.0", "xx@xx.com", "remote-script-ds") { + topologyTemplate { + nodeTemplateComponentRemoteScriptExecutor( + "remote-sample", + "This is sample node template" + ) { + definedOperation(" Sample Operation") { + implementation(180, "SELF") + inputs { + selector("remote-script-executor") + blueprintName("sample") + blueprintVersion("1.0.0") + blueprintAction("sample-action") + timeout(120) + requestData("""{"key" :"value"}""") + } + outputs { + status("success") + } + } } } + nodeTypeComponentRemoteScriptExecutor() } - assertNotNull(nodeTemplate, "failed to generate nodeTemplate Component Remote Script Executor") + // println(serviceTemplate.asJsonString(true)) + assertNotNull(serviceTemplate, "failed to service template") + assertNotNull(serviceTemplate.nodeTypes, "failed to service template node Types") + assertNotNull( + serviceTemplate.nodeTypes!!["component-remote-script-executor"], + "failed to service template nodeType(component-remote-script-executor)" + ) + assertNotNull( + serviceTemplate.topologyTemplate?.nodeTemplates?.get("remote-sample"), + "failed to nodeTemplate(remote-sample)" + ) } @Test @@ -95,7 +111,7 @@ class ComponentRemoteScriptExecutorTest { val mockStreamingRemoteExecutionService = mockk>() + ExecutionServiceOutput>>() coEvery { mockStreamingRemoteExecutionService.sendNonInteractive( diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSLTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSLTest.kt new file mode 100644 index 000000000..6f957e666 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSLTest.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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.blueprintsprocessor.services.execution + +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate +import kotlin.test.assertNotNull + +class ComponentScriptExecutorDSLTest { + + @Test + fun nodeTemplateComponentScriptExecutor() { + + val serviceTemplate = serviceTemplate("remote-script-dsl", "1.0.0", "xx@xx.com", "remote-script-ds") { + topologyTemplate { + nodeTemplateComponentScriptExecutor( + "script-sample", + "This is sample node template" + ) { + definedOperation(" Sample Operation") { + implementation(180, "SELF") + inputs { + type("kotlin") + scriptClassReference("cba.sample.Processor") + dynamicProperties("*dynamic-inputs") + } + outputs { + status("success") + } + } + } + } + nodeTypeComponentScriptExecutor() + } + + // println(serviceTemplate.asJsonString(true)) + assertNotNull(serviceTemplate, "failed to service template") + assertNotNull(serviceTemplate.nodeTypes, "failed to service template node Types") + assertNotNull( + serviceTemplate.nodeTypes!!["component-script-executor"], + "failed to service template nodeType(component-script-executor)" + ) + assertNotNull( + serviceTemplate.topologyTemplate?.nodeTemplates?.get("script-sample"), + "failed to nodeTemplate(script-sample)" + ) + } +} -- cgit 1.2.3-korg