summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints/modules')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt2
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt4
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt3
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSL.kt73
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLBuilder.kt342
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLData.kt61
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTemplateDSLBuilder.kt2
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintWorkflowDSLBuilder.kt5
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintTemplateService.kt15
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt73
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateService.kt29
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt42
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt61
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json15
-rwxr-xr-xms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-jinja-template.jinja42
-rwxr-xr-xms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/interface.jinja3
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/isis.jinja3
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/master.jinja7
18 files changed, 608 insertions, 174 deletions
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<ConstraintClause>? = 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<String, String> = hashMapOf()
+ var properties: MutableMap<String, JsonNode>? = null
+ var dataType: MutableMap<String, DataType> = hashMapOf()
+ var artifacts: MutableMap<String, ArtifactDefinition> = hashMapOf()
+ var components: MutableMap<String, DSLComponent> = hashMapOf()
+ var workflows: MutableMap<String, DSLWorkflow> = 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<String, PropertyDefinition>? = null
+ var attributes: MutableMap<String, AttributeDefinition>? = null
+
+ // For already registered components
+ private var assignProperties: MutableMap<String, JsonNode>? = null
+
+ var artifacts: MutableMap<String, ArtifactDefinition>? = null
+ var implementation: Implementation? = null
+ var inputs: MutableMap<String, PropertyDefinition>? = null
+ var outputs: MutableMap<String, PropertyDefinition>? = null
+
+ // For already registered components
+ private var assignInputs: MutableMap<String, JsonNode>? = null
+ private var assignOutputs: MutableMap<String, JsonNode>? = 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<String, Step>? = null
+ private var inputs: MutableMap<String, PropertyDefinition>? = null
+ private var outputs: MutableMap<String, PropertyDefinition>? = 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<String, String> = hashMapOf()
+ var properties: MutableMap<String, JsonNode>? = null
+ var dataType: MutableMap<String, DataType> = hashMapOf()
+ var components: MutableMap<String, DSLComponent> = hashMapOf()
+ var workflows: MutableMap<String, DSLWorkflow> = hashMapOf()
+}
+
+class DSLWorkflow {
+ @get:JsonIgnore
+ var id: String? = null
+ lateinit var description: String
+ lateinit var actionName: String
+ lateinit var steps: MutableMap<String, Step>
+ var inputs: MutableMap<String, PropertyDefinition>? = null
+ var outputs: MutableMap<String, PropertyDefinition>? = 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<String, AttributeDefinition>? = null
+ var properties: MutableMap<String, PropertyDefinition>? = null
+ var assignProperties: MutableMap<String, JsonNode>? = null
+ var artifacts: MutableMap<String, ArtifactDefinition>? = null
+ var inputs: MutableMap<String, PropertyDefinition>? = null
+ var outputs: MutableMap<String, PropertyDefinition>? = null
+ var assignInputs: MutableMap<String, JsonNode>? = null
+ var assignOutputs: MutableMap<String, JsonNode>? = 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/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintTemplateService.kt
index 86bf3ff56..98abf8987 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintTemplateService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BlueprintTemplateService.kt
@@ -40,21 +40,6 @@ interface BlueprintTemplateService {
jsonData: String = "",
ignoreJsonNull: Boolean = false,
additionalContext: MutableMap<String, Any> = mutableMapOf()): String
-
-
- /**
- * Generate dynamique content using Velocity Template or Jinja template
- *
- * @param template template string content
- * @param templateType template type
- * @param jsonData json string data content to mash
- * @param ignoreJsonNull Ignore Null value in the JSON content
- * @param additionalContext (Key, value) mutable map for additional variables
- * @return Content result
- *
- **/
- suspend fun generateContent(template: String, templateType: String, jsonData: String = "", ignoreJsonNull: Boolean = false,
- additionalContext: MutableMap<String, Any> = mutableMapOf()): String
}
/**
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt
index 912667e0a..baddd6a12 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt
@@ -16,20 +16,76 @@
package org.onap.ccsdk.cds.controllerblueprints.core.service
+import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.common.io.Resources
import com.hubspot.jinjava.Jinjava
+import com.hubspot.jinjava.interpret.Context
+import com.hubspot.jinjava.interpret.JinjavaInterpreter
+import com.hubspot.jinjava.loader.ClasspathResourceLocator
+import com.hubspot.jinjava.loader.ResourceLocator
+import com.hubspot.jinjava.loader.ResourceNotFoundException
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfiguration
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintJsonNodeFactory
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
import org.onap.ccsdk.cds.controllerblueprints.core.removeNullNode
-
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Service
+import java.io.IOException
+import java.nio.charset.Charset
+import java.nio.file.Files.readAllBytes
+import java.nio.file.Paths
object BluePrintJinjaTemplateService {
+ /**
+ * To enable inheritance within CBA, we need Jinja runtime to know where to load the templates.
+ */
+ class BlueprintRelatedTemplateLocator(private val bluePrintPathConfiguration: BluePrintPathConfiguration,
+ private val artifactName: String,
+ private val artifactVersion: String) : ResourceLocator {
+
+ @Throws(IOException::class)
+ override fun getString(fullName: String, encoding: Charset, interpreter: JinjavaInterpreter): String {
+ try {
+ val deployFile =
+ normalizedPathName(bluePrintPathConfiguration.blueprintDeployPath,
+ artifactName,
+ artifactVersion,
+ fullName)
+
+ return String(readAllBytes(Paths.get(deployFile)))
+ } catch (var5: IllegalArgumentException) {
+ throw ResourceNotFoundException("Couldn't find resource: $fullName")
+ }
+
+ }
+ }
+
fun generateContent(template: String, json: String, ignoreJsonNull: Boolean,
- additionalContext: MutableMap<String, Any>): String {
- // Load template
+ additionalContext: MutableMap<String, Any>,
+ bluePrintPathConfiguration: BluePrintPathConfiguration, artifactName: String,
+ artifactVersion: String): String {
+
+
+ return generateContent(template,
+ json,
+ ignoreJsonNull,
+ additionalContext,
+ BlueprintRelatedTemplateLocator(bluePrintPathConfiguration, artifactName, artifactVersion))
+ }
+
+ fun generateContent(template: String, json: String, ignoreJsonNull: Boolean,
+ additionalContext: MutableMap<String, Any>, resourceLocator: ResourceLocator? = null): String {
val jinJava = Jinjava()
+ if (resourceLocator != null) {
+ jinJava.resourceLocator = resourceLocator
+ }
+
val mapper = ObjectMapper()
val nodeFactory = BluePrintJsonNodeFactory()
mapper.nodeFactory = nodeFactory
@@ -37,15 +93,16 @@ object BluePrintJinjaTemplateService {
// Add the JSON Data to the context
if (json.isNotEmpty()) {
val jsonNode = mapper.readValue<JsonNode>(json, JsonNode::class.java)
- ?: throw BluePrintProcessorException("couldn't get json node from json")
- if (ignoreJsonNull)
+ ?: throw BluePrintProcessorException("couldn't get json node from json")
+ if (ignoreJsonNull) {
jsonNode.removeNullNode()
- jsonNode.fields().forEach { entry ->
- additionalContext[entry.key] = entry.value
}
+
+ val jsonMap: Map<String, Any> = mapper.readValue(json, object : TypeReference<Map<String, Any>>() {})
+ additionalContext.putAll(jsonMap)
}
- return jinJava.render(template, additionalContext.toMap())
+ return jinJava.render(template, additionalContext)
}
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateService.kt
index 45e2678ed..af97d6691 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateService.kt
@@ -17,26 +17,33 @@ package org.onap.ccsdk.cds.controllerblueprints.core.service
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfiguration
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintTemplateService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.stereotype.Service
-class BluePrintTemplateService : BlueprintTemplateService {
+@Service
+class BluePrintTemplateService(private val bluePrintPathConfiguration: BluePrintPathConfiguration) :
+ BlueprintTemplateService {
override suspend fun generateContent(bluePrintRuntimeService: BluePrintRuntimeService<*>,
nodeTemplateName: String, artifactName: String, jsonData: String,
ignoreJsonNull: Boolean, additionalContext: MutableMap<String, Any>): String {
- val artifactDefinition = bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName)
+ val artifactDefinition =
+ bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName)
val templateType = artifactDefinition.type
val template = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
- return generateContent(template, templateType, jsonData, ignoreJsonNull, additionalContext)
- }
- override suspend fun generateContent(template: String, templateType: String, jsonData: String, ignoreJsonNull: Boolean,
- additionalContext: MutableMap<String, Any>): String {
return when (templateType) {
BluePrintConstants.ARTIFACT_JINJA_TYPE_NAME -> {
- BluePrintJinjaTemplateService.generateContent(template, jsonData, ignoreJsonNull, additionalContext)
+ BluePrintJinjaTemplateService.generateContent(template,
+ jsonData,
+ ignoreJsonNull,
+ additionalContext,
+ bluePrintPathConfiguration,
+ bluePrintRuntimeService.bluePrintContext().name(),
+ bluePrintRuntimeService.bluePrintContext().version())
}
BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME -> {
BluePrintVelocityTemplateService.generateContent(template, jsonData, ignoreJsonNull, additionalContext)
@@ -47,12 +54,4 @@ class BluePrintTemplateService : BlueprintTemplateService {
}
}
}
-
- suspend fun generateContentFromFiles(templatePath: String, templateType: String, jsonPath: String,
- ignoreJsonNull: Boolean,
- additionalContext: MutableMap<String, Any>): String {
- val json = JacksonUtils.getClassPathFileContent(jsonPath)
- val template = JacksonUtils.getClassPathFileContent(templatePath)
- return generateContent(template, templateType, json, ignoreJsonNull, additionalContext)
- }
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt
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))
}
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt
index 6f961c8ed..63c8ad74e 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt
@@ -36,7 +36,8 @@ class BluePrintTemplateServiceTest {
@BeforeTest
fun setup() {
- val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ val blueprintBasePath: String =
+ ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
}
@@ -55,11 +56,12 @@ class BluePrintTemplateServiceTest {
@Test
fun testJinjaGeneratedContent() {
runBlocking {
- val template = JacksonUtils.getClassPathFileContent("templates/base-config-jinja-template.jinja")
+ val template = JacksonUtils.getClassPathFileContent("templates/master.jinja")
val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-jinja.json")
var element: MutableMap<String, Any> = mutableMapOf()
- element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), hashMapOf("name" to "Element2", "location" to "Region1"))
+ element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"),
+ hashMapOf("name" to "Element2", "location" to "Region1"))
val content = BluePrintJinjaTemplateService.generateContent(template, json, false, element)
assertNotNull(content, "failed to generate content for velocity template")
@@ -67,42 +69,12 @@ class BluePrintTemplateServiceTest {
}
- @Test
- fun testVelocityGeneratedContentFromFiles() {
- runBlocking {
- val bluePrintTemplateService = BluePrintTemplateService()
- val templateFile = "templates/base-config-velocity-template.vtl"
- val jsonFile = "templates/base-config-data-velocity.json"
-
- val content = bluePrintTemplateService.generateContentFromFiles(
- templateFile, BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME, jsonFile, false, mutableMapOf())
- assertNotNull(content, "failed to generate content for velocity template")
- }
-
- }
-
- @Test
- fun testJinjaGeneratedContentFromFiles() {
- runBlocking {
- var element: MutableMap<String, Any> = mutableMapOf()
- element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), hashMapOf("name" to "Element2", "location" to "Region1"))
-
- val bluePrintTemplateService = BluePrintTemplateService()
-
- val templateFile = "templates/base-config-jinja-template.jinja"
- val jsonFile = "templates/base-config-data-jinja.json"
-
- val content = bluePrintTemplateService.generateContentFromFiles(
- templateFile, BluePrintConstants.ARTIFACT_JINJA_TYPE_NAME,
- jsonFile, false, element)
- assertNotNull(content, "failed to generate content for velocity template")
- }
- }
@Test
fun `no value variable should evaluate to default value - standalone template mesh test`() {
runBlocking {
- val template = JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl")
+ val template =
+ JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl")
val json = JacksonUtils.getClassPathFileContent("templates/default-variable-value-data.json")
val content = BluePrintVelocityTemplateService.generateContent(template, json)
@@ -113,24 +85,5 @@ class BluePrintTemplateServiceTest {
}
}
- @Test
- fun `no value variable should evaluate to default value - blueprint processing test`() {
- runBlocking {
- val bluePrintTemplateService = BluePrintTemplateService()
-
- val templateFile = "templates/default-variable-value-velocity-template.vtl"
- val jsonFile = "templates/default-variable-value-data.json"
-
- val content = bluePrintTemplateService.generateContentFromFiles(templateFile,
- BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME, jsonFile, false, mutableMapOf())
-
- //first line represents a variable whose value was successfully retrieved, second line contains a variable
- // whose value could not be evaluated
- val expected = "sample-hostname\n\${node0_backup_router_address}"
- assertEquals(expected, content, "No value variable should use default value")
- }
-
- }
-
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json
index bbfb38d80..ab7abf3d4 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json
@@ -1,16 +1,3 @@
{
- "node_hostname": "sdnc-host",
- "node_backup_router_address": "2001:1890:1253::192:168:100:1",
- "node_backup_router_d_address": "2011:1090:1253::112:158:100:1",
- "servers": [
- "Server1",
- "Server2",
- "Server3"
- ],
- "classes": [
- "superuser-class",
- "tacacs-adv-class",
- "tacacs-base-class"
- ],
- "system_password": "teamops-system-password"
+ "occurrence": 2
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-jinja-template.jinja b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-jinja-template.jinja
deleted file mode 100755
index db900bc8b..000000000
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-jinja-template.jinja
+++ /dev/null
@@ -1,42 +0,0 @@
-<configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm"
-xmlns:a="http://xml.juniper.net/junos/15.1X49/junos">
- <version>15.1X49-D50.3</version>
- <groups>
- <name>node0</name>
- <system>
- {%- for server in servers %}
- <server-host-name>{{ server }}</server-host-name>
- {%- endfor %}
- </system>
- <system>
- <host-name>{{ node_hostname }}</host-name>
- <backup-router>
- <address>{{ node_backup_router_address }}</address>
- <destination>{{ node_backup_router_d_address }}</destination>
- </backup-router>
- <login>
- <message>ONAP information assets</message>
- {%- for class in classes %}
- <class>
- {{ class }}
- </class>
- {%- endfor %}
- <user>
- <name>readwrite</name>
- <full-name>Read - Write Account Access</full-name>
- <uid>1002</uid>
- <class>tacacs-adv-class</class>
- <authentication>
- <encrypted-password>{{ system_password }}</encrypted-password>
- </authentication>
- </user>
- </login>
- {%- for element in additional_array %}
- <additionalArray>
- <name>{{ element.name }}</name>
- <location>{{ element.location }}</location>
- </additionalArray>
- {%- endfor %}
- </system>
- </groups>
-</configuration> \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/interface.jinja b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/interface.jinja
new file mode 100755
index 000000000..93114d90a
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/interface.jinja
@@ -0,0 +1,3 @@
+ <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
+blo
+ </interface-configurations> \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/isis.jinja b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/isis.jinja
new file mode 100644
index 000000000..f46d91330
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/isis.jinja
@@ -0,0 +1,3 @@
+ <isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-cfg">
+blah
+ </isis> \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/master.jinja b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/master.jinja
new file mode 100644
index 000000000..1137b2595
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/master.jinja
@@ -0,0 +1,7 @@
+{%- for i in range(occurrence) %}
+<config>
+{% include "templates/isis.jinja" %}
+{% include "templates/interface.jinja" %}
+</config>
+{{ "]]>]]" if not loop.last }}
+{%- endfor %} \ No newline at end of file