From 5c04d574527c41c241361d44bcd58983065ac0c3 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Mon, 10 Jun 2019 15:50:23 -0400 Subject: Add blueprint domain DSL Change-Id: Id9f64605fa74f54d43af55357a521cf347fa8677 Issue-ID: CCSDK-1380 Signed-off-by: Brinda Santh --- .../core/BluePrintConstants.kt | 2 + .../controllerblueprints/core/CustomFunctions.kt | 4 + .../core/data/BluePrintModel.kt | 3 + .../controllerblueprints/core/dsl/BluePrintDSL.kt | 73 +++-- .../core/dsl/BluePrintDSLBuilder.kt | 342 +++++++++++++++++++++ .../core/dsl/BluePrintDSLData.kt | 61 ++++ .../core/dsl/BluePrintTemplateDSLBuilder.kt | 2 +- .../core/dsl/BluePrintWorkflowDSLBuilder.kt | 5 +- .../core/dsl/BluePrintDSLTest.kt | 42 ++- 9 files changed, 508 insertions(+), 26 deletions(-) create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLBuilder.kt create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLData.kt (limited to 'ms/controllerblueprints/modules/blueprint-core/src') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt index 9a652fb92..786bcd3a5 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt @@ -180,6 +180,8 @@ object BluePrintConstants { const val PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation" const val PROPERTY_EXECUTION_REQUEST = "execution-request" + const val DEFAULT_STEP_OPERATION = "process" + const val ARTIFACT_VELOCITY_TYPE_NAME = "artifact-template-velocity" const val ARTIFACT_JINJA_TYPE_NAME = "artifact-template-jinja" } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt index 4f2b7a121..a508c8fbc 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt @@ -34,6 +34,10 @@ fun String.isJson(): Boolean { || (this.startsWith("[") && this.endsWith("]"))) } +fun Any.asJsonString(intend: Boolean? = false): String { + return JacksonUtils.getJson(this, true) +} + fun String.asJsonPrimitive(): TextNode { return TextNode(this) } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt index 745671ac9..9e934c7c7 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt @@ -192,6 +192,9 @@ class AttributeDefinition { var constraints: MutableList? = null @JsonProperty("entry_schema") var entrySchema: EntrySchema? = null + // Mainly used in DSL definitions + @get:ApiModelProperty(notes = "Attribute Value, It may be Expression or Json type values") + var value: JsonNode? = null } /* diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt index 4878cb696..95303ea23 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt @@ -17,60 +17,91 @@ package org.onap.ccsdk.cds.controllerblueprints.core.dsl import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.data.* import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType +// CDS DSLs +fun blueprint(name: String, version: String, author: String, tags: String, + block: DSLBluePrintBuilder.() -> Unit): DSLBluePrint { + return DSLBluePrintBuilder(name, version, author, tags).apply(block).build() +} + +// TOSCA DSLs fun serviceTemplate(name: String, version: String, author: String, tags: String, block: ServiceTemplateBuilder.() -> Unit): ServiceTemplate { return ServiceTemplateBuilder(name, version, author, tags).apply(block).build() } +fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit): Workflow { + return WorkflowBuilder(id, description).apply(block).build() +} + +fun nodeTemplate(id: String, type: String, description: String, + block: NodeTemplateBuilder.() -> Unit): NodeTemplate { + return NodeTemplateBuilder(id, type, description).apply(block).build() +} + +fun nodeType(id: String, version: String, derivedFrom: String, description: String, + block: NodeTypeBuilder.() -> Unit): NodeType { + return NodeTypeBuilder(id, version, derivedFrom, description).apply(block).build() +} + +fun dataType(id: String, version: String, derivedFrom: String, description: String, + block: DataTypeBuilder.() -> Unit): DataType { + return DataTypeBuilder(id, version, derivedFrom, description).apply(block).build() +} + +fun artifactType(id: String, version: String, derivedFrom: String, description: String, + block: ArtifactTypeBuilder.() -> Unit): ArtifactType { + return ArtifactTypeBuilder(id, version, derivedFrom, description).apply(block).build() +} + // Input Function fun getInput(inputKey: String): JsonNode { return """{"get_input": "$inputKey"}""".jsonAsJsonType() } -fun getAttribute(attributeName: String): JsonNode { - return """{"get_attribute": ["SELF", "$attributeName"]}""".jsonAsJsonType() +fun getAttribute(attributeId: String): JsonNode { + return """{"get_attribute": ["SELF", "$attributeId"]}""".jsonAsJsonType() } -fun getAttribute(attributeName: String, jsonPath: String): JsonNode { - return """{"get_attribute": ["SELF", "$attributeName", "$jsonPath"]}""".jsonAsJsonType() +fun getAttribute(attributeId: String, jsonPath: String): JsonNode { + return """{"get_attribute": ["SELF", "$attributeId", "$jsonPath"]}""".jsonAsJsonType() } -fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String): JsonNode { - return """{"get_attribute": ["$nodeTemplateName", "$attributeName"]}""".jsonAsJsonType() +fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String): JsonNode { + return """{"get_attribute": ["$nodeTemplateId", "$attributeId"]}""".jsonAsJsonType() } -fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String, jsonPath: String): JsonNode { - return """{"get_attribute": ["$nodeTemplateName", "$attributeName", "$jsonPath]}""".jsonAsJsonType() +fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String, jsonPath: String): JsonNode { + return """{"get_attribute": ["$nodeTemplateId", "$attributeId", "$jsonPath]}""".jsonAsJsonType() } // Property Function -fun getProperty(propertyName: String): JsonNode { - return """{"get_property": ["SELF", "$propertyName"]}""".jsonAsJsonType() +fun getProperty(propertyId: String): JsonNode { + return """{"get_property": ["SELF", "$propertyId"]}""".jsonAsJsonType() } -fun getProperty(propertyName: String, jsonPath: String): JsonNode { - return """{"get_property": ["SELF", "$propertyName", "$jsonPath"]}""".jsonAsJsonType() +fun getProperty(propertyId: String, jsonPath: String): JsonNode { + return """{"get_property": ["SELF", "$propertyId", "$jsonPath"]}""".jsonAsJsonType() } -fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String): JsonNode { - return """{"get_property": ["$nodeTemplateName", "$propertyName"]}""".jsonAsJsonType() +fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String): JsonNode { + return """{"get_property": ["$nodeTemplateName", "$propertyId"]}""".jsonAsJsonType() } -fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String, jsonPath: String): JsonNode { - return """{"get_property": ["$nodeTemplateName", "$propertyName", "$jsonPath]}""".jsonAsJsonType() +fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String, jsonPath: String): JsonNode { + return """{"get_property": ["$nodeTemplateName", "$propertyId", "$jsonPath]}""".jsonAsJsonType() } // Artifact Function -fun getArtifact(artifactName: String): JsonNode { - return """{"get_artifact": ["SELF", "$artifactName"]}""".jsonAsJsonType() +fun getArtifact(artifactId: String): JsonNode { + return """{"get_artifact": ["SELF", "$artifactId"]}""".jsonAsJsonType() } -fun getNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): JsonNode { - return """{"get_artifact": ["$nodeTemplateName", "$artifactName"]}""".jsonAsJsonType() +fun getNodeTemplateArtifact(nodeTemplateName: String, artifactId: String): JsonNode { + return """{"get_artifact": ["$nodeTemplateName", "$artifactId"]}""".jsonAsJsonType() } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLBuilder.kt new file mode 100644 index 000000000..8cfa90b15 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLBuilder.kt @@ -0,0 +1,342 @@ +/* + * Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.dsl + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.onap.ccsdk.cds.controllerblueprints.core.data.* + +/** + * @author Brinda Santh + */ +class DSLBluePrintBuilder(private val name: String, + private val version: String, + private val author: String, + private val tags: String) { + + private var dslBluePrint = DSLBluePrint() + private var metadata: MutableMap = hashMapOf() + var properties: MutableMap? = null + var dataType: MutableMap = hashMapOf() + var artifacts: MutableMap = hashMapOf() + var components: MutableMap = hashMapOf() + var workflows: MutableMap = hashMapOf() + + 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 property(id: String, expression: Any) { + if (properties == null) + properties = hashMapOf() + properties!![id] = expression.asJsonType() + } + + fun dataType(id: String, version: String, derivedFrom: String, description: String, + block: DataTypeBuilder.() -> Unit) { + dataType[id] = DataTypeBuilder(id, version, derivedFrom, description).apply(block).build() + } + + fun component(id: String, type: String, version: String, description: String, block: DSLComponentBuilder.() -> Unit) { + components[id] = DSLComponentBuilder(id, type, version, description).apply(block).build() + } + + fun workflow(id: String, description: String, block: DSLWorkflowBuilder.() -> Unit) { + workflows[id] = DSLWorkflowBuilder(id, description).apply(block).build() + } + + fun build(): DSLBluePrint { + initMetaData() + dslBluePrint.metadata = metadata + dslBluePrint.properties = properties + dslBluePrint.dataType = dataType + dslBluePrint.components = components + dslBluePrint.workflows = workflows + return dslBluePrint + } +} + +class DSLComponentBuilder(private val id: String, private val type: String, + private val version: String, private val description: String) { + private val dslComponent = DSLComponent() + var properties: MutableMap? = null + var attributes: MutableMap? = null + + // For already registered components + private var assignProperties: MutableMap? = null + + var artifacts: MutableMap? = null + var implementation: Implementation? = null + var inputs: MutableMap? = null + var outputs: MutableMap? = null + + // For already registered components + private var assignInputs: MutableMap? = null + private var assignOutputs: MutableMap? = null + + fun attribute(id: String, type: String, required: Boolean, expression: Any, description: String? = "") { + if (attributes == null) + attributes = hashMapOf() + val attribute = DSLAttributeDefinitionBuilder(id, type, required, expression.asJsonType(), description).build() + attributes!![id] = attribute + } + + fun attribute(id: String, type: String, required: Boolean, expression: Any, description: String? = "", + block: DSLAttributeDefinitionBuilder.() -> Unit) { + if (attributes == null) + attributes = hashMapOf() + val attribute = DSLAttributeDefinitionBuilder(id, type, required, expression.asJsonType(), description) + .apply(block).build() + attributes!![id] = attribute + } + + fun property(id: String, type: String, required: Boolean, expression: Any, description: String? = "") { + if (properties == null) + properties = hashMapOf() + val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description).build() + properties!![id] = property + } + + fun property(id: String, type: String, required: Boolean, expression: Any, description: String? = "", + block: DSLPropertyDefinitionBuilder.() -> Unit) { + if (properties == null) + properties = hashMapOf() + val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description) + .apply(block).build() + properties!![id] = property + } + + fun assignProperty(id: String, expression: Any) { + if (assignProperties == null) + assignProperties = hashMapOf() + assignProperties!![id] = expression.asJsonType() + } + + fun implementation(timeout: Int, operationHost: String? = BluePrintConstants.PROPERTY_SELF) { + implementation = Implementation().apply { + this.operationHost = operationHost!! + this.timeout = timeout + } + } + + fun artifacts(id: String, type: String, file: String) { + if (artifacts == null) + artifacts = hashMapOf() + artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).build() + } + + fun artifacts(id: String, type: String, file: String, block: ArtifactDefinitionBuilder.() -> Unit) { + if (artifacts == null) + artifacts = hashMapOf() + artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).apply(block).build() + } + + + fun input(id: String, type: String, required: Boolean, expression: Any, description: String? = "") { + if (inputs == null) + inputs = hashMapOf() + val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description) + inputs!![id] = property.build() + } + + fun input(id: String, type: String, required: Boolean, expression: Any, description: String? = "", + block: DSLPropertyDefinitionBuilder.() -> Unit) { + if (inputs == null) + inputs = hashMapOf() + val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description) + .apply(block).build() + inputs!![id] = property + } + + fun assignInput(id: String, expression: Any) { + if (assignInputs == null) + assignInputs = hashMapOf() + assignInputs!![id] = expression.asJsonType() + } + + fun output(id: String, type: String, required: Boolean, expression: Any, description: String? = "") { + if (outputs == null) + outputs = hashMapOf() + val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description) + outputs!![id] = property.build() + } + + fun output(id: String, type: String, required: Boolean, expression: Any, description: String? = "", + block: DSLPropertyDefinitionBuilder.() -> Unit) { + if (outputs == null) + outputs = hashMapOf() + val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description) + .apply(block).build() + outputs!![id] = property + } + + fun assignOutput(id: String, expression: Any) { + if (assignOutputs == null) + assignOutputs = hashMapOf() + assignOutputs!![id] = expression.asJsonType() + } + + fun build(): DSLComponent { + dslComponent.id = id + dslComponent.type = type + dslComponent.version = version + dslComponent.description = description + dslComponent.attributes = attributes + dslComponent.properties = properties + dslComponent.assignProperties = assignProperties + dslComponent.implementation = implementation + dslComponent.artifacts = artifacts + dslComponent.inputs = inputs + dslComponent.outputs = outputs + dslComponent.assignInputs = assignInputs + dslComponent.assignOutputs = assignOutputs + dslComponent.outputs = outputs + + return dslComponent + } +} + +class DSLWorkflowBuilder(private val actionName: String, private val description: String) { + private val dslWorkflow = DSLWorkflow() + private var steps: MutableMap? = null + private var inputs: MutableMap? = null + private var outputs: MutableMap? = null + + fun input(id: String, type: String, required: Boolean, description: String? = "") { + if (inputs == null) + inputs = hashMapOf() + val property = PropertyDefinitionBuilder(id, type, required, description) + inputs!![id] = property.build() + } + + fun input(id: String, type: String, required: Boolean, description: String, defaultValue: Any?, + block: PropertyDefinitionBuilder.() -> Unit) { + if (inputs == null) + inputs = hashMapOf() + val property = PropertyDefinitionBuilder(id, type, required, description).apply(block).build() + if (defaultValue != null) + property.defaultValue = defaultValue.asJsonType() + inputs!![id] = property + } + + fun output(id: String, type: String, required: Boolean, expression: Any, description: String? = "") { + if (outputs == null) + outputs = hashMapOf() + val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description) + outputs!![id] = property.build() + } + + fun output(id: String, type: String, required: Boolean, expression: Any, description: String? = "", + block: DSLPropertyDefinitionBuilder.() -> Unit) { + if (outputs == null) + outputs = hashMapOf() + val property = DSLPropertyDefinitionBuilder(id, type, required, expression.asJsonType(), description) + .apply(block).build() + outputs!![id] = property + } + + fun step(id: String, target: String, description: String) { + if (steps == null) + steps = hashMapOf() + steps!![id] = StepBuilder(id, target, description).build() + } + + fun step(id: String, target: String, description: String, block: StepBuilder.() -> Unit) { + if (steps == null) + steps = hashMapOf() + steps!![id] = StepBuilder(id, target, description).apply(block).build() + } + + fun build(): DSLWorkflow { + dslWorkflow.actionName = actionName + dslWorkflow.description = description + dslWorkflow.inputs = inputs + dslWorkflow.outputs = outputs + dslWorkflow.steps = steps!! + return dslWorkflow + } +} + +class DSLAttributeDefinitionBuilder(private val id: String, + private val type: String? = BluePrintConstants.DATA_TYPE_STRING, + private val required: Boolean? = false, + private val expression: JsonNode, + private val description: String? = "") { + + private var attributeDefinition = AttributeDefinition() + + fun entrySchema(entrySchemaType: String) { + attributeDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).build() + } + + fun entrySchema(entrySchemaType: String, block: EntrySchemaBuilder.() -> Unit) { + attributeDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).apply(block).build() + } + // TODO("Constrains") + + fun defaultValue(defaultValue: JsonNode) { + attributeDefinition.defaultValue = defaultValue + } + + fun build(): AttributeDefinition { + attributeDefinition.id = id + attributeDefinition.type = type!! + attributeDefinition.required = required + attributeDefinition.value = expression + attributeDefinition.description = description + return attributeDefinition + } +} + +class DSLPropertyDefinitionBuilder(private val id: String, + private val type: String? = BluePrintConstants.DATA_TYPE_STRING, + private val required: Boolean? = false, + private val expression: JsonNode, + private val description: String? = "") { + + private var propertyDefinition: PropertyDefinition = PropertyDefinition() + + fun entrySchema(entrySchemaType: String) { + propertyDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).build() + } + + fun entrySchema(entrySchemaType: String, block: EntrySchemaBuilder.() -> Unit) { + propertyDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).apply(block).build() + } + // TODO("Constrains") + + fun defaultValue(defaultValue: JsonNode) { + propertyDefinition.defaultValue = defaultValue + } + + fun build(): PropertyDefinition { + propertyDefinition.id = id + propertyDefinition.type = type!! + propertyDefinition.required = required + propertyDefinition.value = expression + propertyDefinition.description = description + return propertyDefinition + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLData.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLData.kt new file mode 100644 index 000000000..12428a90c --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLData.kt @@ -0,0 +1,61 @@ +/* + * 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.annotation.JsonIgnore +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.data.* + +/** + * This is simplified version of DSL, which is used for generating the Service template + * @author Brinda Santh + */ + +class DSLBluePrint { + var metadata: MutableMap = hashMapOf() + var properties: MutableMap? = null + var dataType: MutableMap = hashMapOf() + var components: MutableMap = hashMapOf() + var workflows: MutableMap = hashMapOf() +} + +class DSLWorkflow { + @get:JsonIgnore + var id: String? = null + lateinit var description: String + lateinit var actionName: String + lateinit var steps: MutableMap + var inputs: MutableMap? = null + var outputs: MutableMap? = null +} + +class DSLComponent { + @get:JsonIgnore + lateinit var id: String + lateinit var type: String + lateinit var version: String + lateinit var description: String + var implementation: Implementation? = null + var attributes: MutableMap? = null + var properties: MutableMap? = null + var assignProperties: MutableMap? = null + var artifacts: MutableMap? = null + var inputs: MutableMap? = null + var outputs: MutableMap? = null + var assignInputs: MutableMap? = null + var assignOutputs: MutableMap? = null +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt index 7973293ae..f19ae8eb8 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt @@ -87,7 +87,7 @@ class NodeTemplateBuilder(private val id: String, interfaces = hashMapOf() val interfaceAssignment = InterfaceAssignment() - val defaultOperationName = "process" + val defaultOperationName = BluePrintConstants.DEFAULT_STEP_OPERATION interfaceAssignment.operations = hashMapOf() interfaceAssignment.operations!![defaultOperationName] = OperationAssignmentBuilder(defaultOperationName, description).apply(block).build() diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt index 5ec3df160..f98cf58d3 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt @@ -16,6 +16,7 @@ package org.onap.ccsdk.cds.controllerblueprints.core.dsl +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.data.Activity import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.cds.controllerblueprints.core.data.Step @@ -30,7 +31,7 @@ class WorkflowBuilder(private val id: String, private val description: String) { // Used Internally fun nodeTemplateStep(nodeTemplateName: String, description: String) { - step(nodeTemplateName, nodeTemplateName, "") + step(nodeTemplateName, nodeTemplateName, "$description step") } fun step(id: String, target: String, description: String) { @@ -98,7 +99,7 @@ class StepBuilder(private val id: String, private val target: String, step.id = id step.target = target // Add Default Activity, Assumption is only one Operation - activity(".process") + activity(".${BluePrintConstants.DEFAULT_STEP_OPERATION}") step.description = description step.activities = activities step.onSuccess = onSuccess diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt index dff0f943f..e7f24d629 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt @@ -21,6 +21,44 @@ import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType import kotlin.test.assertNotNull class BluePrintDSLTest { + + @Test + fun testOperationDSLWorkflow() { + + val blueprint = blueprint("sample-bp", "1.0.0", + "brindasanth@onap.com", "sample, blueprints") { + + // For New Component Definition + component("resource-resolution", "component-resource-resolution", "1.0.0", + "Resource Resolution Call") { + implementation(180) + // Attributes ( Properties which will be set during execution) + attribute("template1-data", "string", true, "") + + // Properties + property("string-value1", "string", true, "sample") + property("string-value2", "string", true, getInput("key-1")) + // Inputs + input("json-content", "json", true, """{ "name" : "cds"}""") + input("template-content", "string", true, getArtifact("template1")) + // Outputs + output("self-attribute-expression", "json", true, getAttribute("template1-data")) + // Artifacts + artifacts("template1", "artifact-velocity", "Templates/template1.vtl") + } + + workflow("resource-resolution-process", "") { + input("json-content", "json", true, "") + input("key-1", "string", true, "") + output("status", "string", true, "success") + step("resource-resolution-call", "resource-resolution", "Resource Resolution component invoke") + } + } + assertNotNull(blueprint.components, "failed to get components") + assertNotNull(blueprint.workflows, "failed to get workflows") + //println(blueprint.asJsonString(true)) + } + @Test fun testServiceTemplate() { val serviceTemplate = serviceTemplate("sample-bp", "1.0.0", @@ -88,7 +126,7 @@ class BluePrintDSLTest { assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template") assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes") assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], "failed to get nodeTypes(activate)") - //println(JacksonUtils.getJson(serviceTemplate, true)) + //println(serviceTemplate.asJsonString(true)) } @Test @@ -107,7 +145,7 @@ class BluePrintDSLTest { } assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template") assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)") - //println(JacksonUtils.getJson(serviceTemplate, true)) + //println(serviceTemplate.asJsonString(true)) } } -- cgit 1.2.3-korg