2 * Copyright © 2019 IBM.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.controllerblueprints.core.dsl
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.*
24 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
27 fun blueprint(name: String, version: String, author: String, tags: String,
28 block: DSLBluePrintBuilder.() -> Unit): DSLBluePrint {
29 return DSLBluePrintBuilder(name, version, author, tags).apply(block).build()
33 fun serviceTemplate(name: String, version: String, author: String, tags: String,
34 block: ServiceTemplateBuilder.() -> Unit): ServiceTemplate {
35 return ServiceTemplateBuilder(name, version, author, tags).apply(block).build()
38 fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit): Workflow {
39 return WorkflowBuilder(id, description).apply(block).build()
42 fun nodeTemplate(id: String, type: String, description: String,
43 block: NodeTemplateBuilder.() -> Unit): NodeTemplate {
44 return NodeTemplateBuilder(id, type, description).apply(block).build()
47 fun nodeType(id: String, version: String, derivedFrom: String, description: String,
48 block: NodeTypeBuilder.() -> Unit): NodeType {
49 return NodeTypeBuilder(id, version, derivedFrom, description).apply(block).build()
52 fun dataType(id: String, version: String, derivedFrom: String, description: String,
53 block: DataTypeBuilder.() -> Unit): DataType {
54 return DataTypeBuilder(id, version, derivedFrom, description).apply(block).build()
57 fun artifactType(id: String, version: String, derivedFrom: String, description: String,
58 block: ArtifactTypeBuilder.() -> Unit): ArtifactType {
59 return ArtifactTypeBuilder(id, version, derivedFrom, description).apply(block).build()
62 fun relationshipType(id: String, version: String, derivedFrom: String, description: String,
63 block: RelationshipTypeBuilder.() -> Unit): RelationshipType {
64 return RelationshipTypeBuilder(id, version, derivedFrom, description).apply(block).build()
68 fun dslExpression(key: String): JsonNode {
69 return ("*$key").asJsonPrimitive()
73 fun getInput(inputKey: String, jsonPath: String? = null): JsonNode {
74 return """{"get_input": "$inputKey"}""".jsonAsJsonType()
77 fun getAttribute(attributeId: String, jsonPath: String? = null): JsonNode {
78 return getNodeTemplateAttribute("SELF", attributeId, jsonPath)
81 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String): JsonNode {
82 return getNodeTemplateAttribute(nodeTemplateId, attributeId, null)
85 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String, jsonPath: String?): JsonNode {
86 return if (jsonPath.isNullOrEmpty() || jsonPath.isNullOrBlank()) {
87 """{"get_attribute": ["$nodeTemplateId", "$attributeId"]}""".jsonAsJsonType()
89 """{"get_attribute": ["$nodeTemplateId", "$attributeId", "$jsonPath"]}""".jsonAsJsonType()
95 fun getProperty(propertyId: String, jsonPath: String? = null): JsonNode {
96 return getNodeTemplateProperty("SELF", propertyId, jsonPath)
99 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String): JsonNode {
100 return getNodeTemplateProperty(nodeTemplateName, propertyId, null)
103 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String, jsonPath: String?): JsonNode {
104 return if (jsonPath.isNullOrEmpty() || jsonPath.isNullOrBlank()) {
105 """{"get_property": ["$nodeTemplateName", "$propertyId"]}""".jsonAsJsonType()
107 """{"get_property": ["$nodeTemplateName", "$propertyId", "$jsonPath"]}""".jsonAsJsonType()
113 fun getArtifact(artifactId: String): JsonNode {
114 return getNodeTemplateArtifact("SELF", artifactId)
117 fun getNodeTemplateArtifact(nodeTemplateName: String, artifactId: String): JsonNode {
118 return """{"get_artifact": ["$nodeTemplateName", "$artifactId"]}""".jsonAsJsonType()
121 // Operation Function
123 fun getNodeTemplateOperationOutput(nodeTemplateName: String, interfaceName: String, propertyId: String,
124 jsonPath: String? = null): JsonNode {
125 return """{"get_operation_output": ["$nodeTemplateName", "$interfaceName", "process","$propertyId","$jsonPath" ]}""".trimMargin().jsonAsJsonType()
128 /** Blueprint Type Extensions */
130 fun BluePrintTypes.nodeTypeComponent(): NodeType {
131 return nodeType(id = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
132 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
133 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
134 description = "This is default Component Node") {
138 fun BluePrintTypes.nodeTypeWorkflow(): NodeType {
139 return nodeType(id = BluePrintConstants.MODEL_TYPE_NODE_WORKFLOW,
140 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
141 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
142 description = "This is default Workflow Node") {
146 fun BluePrintTypes.nodeTypeVnf(): NodeType {
147 return nodeType(id = BluePrintConstants.MODEL_TYPE_NODE_VNF,
148 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
149 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
150 description = "This is default VNF Node") {
154 fun BluePrintTypes.nodeTypeResourceSource(): NodeType {
155 return nodeType(id = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
156 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
157 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
158 description = "This is default Resource Source Node") {
164 fun BluePrintTypes.artifactTypeTemplateVelocity(): ArtifactType {
165 return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_VELOCITY,
166 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
167 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
168 description = "Velocity Artifact") {
173 fun BluePrintTypes.artifactTypeTempleJinja(): ArtifactType {
174 return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA,
175 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
176 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
177 description = "Jinja Artifact") {
182 fun BluePrintTypes.artifactTypeMappingResource(): ArtifactType {
183 return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_MAPPING_RESOURCE,
184 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
185 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
186 description = "Mapping Resource Artifact") {
191 fun BluePrintTypes.artifactTypeScriptJython(): ArtifactType {
192 return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_JYTHON,
193 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
194 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
195 description = "Jython Script Artifact") {
200 fun BluePrintTypes.artifactTypeScriptKotlin(): ArtifactType {
201 return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_KOTLIN,
202 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
203 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
204 description = "Kotlin Script Artifact") {
209 fun BluePrintTypes.artifactTypeDirectedGraph(): ArtifactType {
210 return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_DIRECTED_GRAPH,
211 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
212 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
213 description = "Directed Graph Artifact") {
214 fileExt("xml", "json")
218 fun BluePrintTypes.artifactTypeComponentJar(): ArtifactType {
219 return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_COMPONENT_JAR,
220 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
221 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
222 description = "Component Artifact") {
227 /** Relationship Types */
229 fun BluePrintTypes.relationshipTypeConnectsTo(): RelationshipType {
230 return relationshipType(id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
231 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
232 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
233 description = "Relationship connects to") {
237 fun BluePrintTypes.relationshipTypeDependsOn(): RelationshipType {
238 return relationshipType(id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON,
239 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
240 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
241 description = "Relationship depends on") {