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.ArtifactType
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
29 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
30 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
38 block: DSLBluePrintBuilder.() -> Unit
40 return DSLBluePrintBuilder(name, version, author, tags).apply(block).build()
49 block: ServiceTemplateBuilder.() -> Unit
51 return ServiceTemplateBuilder(name, version, author, tags).apply(block).build()
54 fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit): Workflow {
55 return WorkflowBuilder(id, description).apply(block).build()
62 block: NodeTemplateBuilder.() -> Unit
64 return NodeTemplateBuilder(id, type, description).apply(block).build()
72 block: NodeTypeBuilder.() -> Unit
74 return NodeTypeBuilder(id, version, derivedFrom, description).apply(block).build()
82 block: DataTypeBuilder.() -> Unit
84 return DataTypeBuilder(id, version, derivedFrom, description).apply(block).build()
92 block: ArtifactTypeBuilder.() -> Unit
94 return ArtifactTypeBuilder(id, version, derivedFrom, description).apply(block).build()
102 block: RelationshipTypeBuilder.() -> Unit
103 ): RelationshipType {
104 return RelationshipTypeBuilder(id, version, derivedFrom, description).apply(block).build()
108 fun dslExpression(key: String): JsonNode {
109 return ("*$key").asJsonPrimitive()
113 fun getInput(inputKey: String, jsonPath: String? = null): JsonNode {
114 return """{"get_input": "$inputKey"}""".jsonAsJsonType()
117 fun getAttribute(attributeId: String, jsonPath: String? = null): JsonNode {
118 return getNodeTemplateAttribute("SELF", attributeId, jsonPath)
121 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String): JsonNode {
122 return getNodeTemplateAttribute(nodeTemplateId, attributeId, null)
125 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String, jsonPath: String?): JsonNode {
126 return if (jsonPath.isNullOrEmpty() || jsonPath.isNullOrBlank()) {
127 """{"get_attribute": ["$nodeTemplateId", "$attributeId"]}""".jsonAsJsonType()
129 """{"get_attribute": ["$nodeTemplateId", "$attributeId", "$jsonPath"]}""".jsonAsJsonType()
135 fun getProperty(propertyId: String, jsonPath: String? = null): JsonNode {
136 return getNodeTemplateProperty("SELF", propertyId, jsonPath)
139 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String): JsonNode {
140 return getNodeTemplateProperty(nodeTemplateName, propertyId, null)
143 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String, jsonPath: String?): JsonNode {
144 return if (jsonPath.isNullOrEmpty() || jsonPath.isNullOrBlank()) {
145 """{"get_property": ["$nodeTemplateName", "$propertyId"]}""".jsonAsJsonType()
147 """{"get_property": ["$nodeTemplateName", "$propertyId", "$jsonPath"]}""".jsonAsJsonType()
153 fun getArtifact(artifactId: String): JsonNode {
154 return getNodeTemplateArtifact("SELF", artifactId)
157 fun getNodeTemplateArtifact(nodeTemplateName: String, artifactId: String): JsonNode {
158 return """{"get_artifact": ["$nodeTemplateName", "$artifactId"]}""".jsonAsJsonType()
161 // Operation Function
163 fun getNodeTemplateOperationOutput(
164 nodeTemplateName: String,
165 interfaceName: String,
167 jsonPath: String? = null
169 return """{"get_operation_output": ["$nodeTemplateName", "$interfaceName", "process","$propertyId","$jsonPath" ]}""".trimMargin()
173 /** Blueprint Type Extensions */
174 fun ServiceTemplateBuilder.nodeTypeComponent() {
175 val nodeType = BluePrintTypes.nodeTypeComponent()
176 if (this.nodeTypes == null) this.nodeTypes = hashMapOf()
177 this.nodeTypes!![nodeType.id!!] = nodeType
180 fun BluePrintTypes.nodeTypeComponent(): NodeType {
182 id = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
183 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
184 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
185 description = "This is default Component Node"
190 @Deprecated("CDS won't support, use implerative workflow definitions.")
191 fun BluePrintTypes.nodeTypeWorkflow(): NodeType {
193 id = BluePrintConstants.MODEL_TYPE_NODE_WORKFLOW,
194 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
195 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
196 description = "This is default Workflow Node"
201 fun ServiceTemplateBuilder.nodeTypeVnf() {
202 val nodeType = BluePrintTypes.nodeTypeVnf()
203 if (this.nodeTypes == null) this.nodeTypes = hashMapOf()
204 this.nodeTypes!![nodeType.id!!] = nodeType
207 fun BluePrintTypes.nodeTypeVnf(): NodeType {
209 id = BluePrintConstants.MODEL_TYPE_NODE_VNF,
210 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
211 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
212 description = "This is default VNF Node"
217 fun ServiceTemplateBuilder.nodeTypeResourceSource() {
218 val nodeType = BluePrintTypes.nodeTypeResourceSource()
219 if (this.nodeTypes == null) this.nodeTypes = hashMapOf()
220 this.nodeTypes!![nodeType.id!!] = nodeType
223 fun BluePrintTypes.nodeTypeResourceSource(): NodeType {
225 id = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
226 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
227 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
228 description = "This is default Resource Source Node"
234 fun ServiceTemplateBuilder.artifactTypeTemplateVelocity() {
235 val artifactType = BluePrintTypes.artifactTypeTemplateVelocity()
236 if (this.artifactTypes == null) this.artifactTypes = hashMapOf()
237 this.artifactTypes!![artifactType.id!!] = artifactType
240 fun BluePrintTypes.artifactTypeTemplateVelocity(): ArtifactType {
242 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_VELOCITY,
243 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
244 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
245 description = "Velocity Artifact"
251 fun ServiceTemplateBuilder.artifactTypeTempleJinja() {
252 val artifactType = BluePrintTypes.artifactTypeTempleJinja()
253 if (this.artifactTypes == null) this.artifactTypes = hashMapOf()
254 this.artifactTypes!![artifactType.id!!] = artifactType
257 fun BluePrintTypes.artifactTypeTempleJinja(): ArtifactType {
259 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA,
260 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
261 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
262 description = "Jinja Artifact"
268 fun ServiceTemplateBuilder.artifactTypeMappingResource() {
269 val artifactType = BluePrintTypes.artifactTypeMappingResource()
270 if (this.artifactTypes == null) this.artifactTypes = hashMapOf()
271 this.artifactTypes!![artifactType.id!!] = artifactType
274 fun BluePrintTypes.artifactTypeMappingResource(): ArtifactType {
276 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_MAPPING_RESOURCE,
277 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
278 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
279 description = "Mapping Resource Artifact"
285 @Deprecated("CDS won't support", replaceWith = ReplaceWith("artifactTypeScriptKotlin"))
286 fun BluePrintTypes.artifactTypeScriptJython(): ArtifactType {
288 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_JYTHON,
289 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
290 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
291 description = "Jython Script Artifact"
297 fun ServiceTemplateBuilder.artifactTypeScriptKotlin() {
298 val artifactType = BluePrintTypes.artifactTypeScriptKotlin()
299 if (this.artifactTypes == null) this.artifactTypes = hashMapOf()
300 this.artifactTypes!![artifactType.id!!] = artifactType
303 fun BluePrintTypes.artifactTypeScriptKotlin(): ArtifactType {
305 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_KOTLIN,
306 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
307 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
308 description = "Kotlin Script Artifact"
314 @Deprecated("CDS won't support, use implerative workflow definitions.")
315 fun BluePrintTypes.artifactTypeDirectedGraph(): ArtifactType {
317 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_DIRECTED_GRAPH,
318 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
319 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
320 description = "Directed Graph Artifact"
322 fileExt("xml", "json")
326 fun ServiceTemplateBuilder.artifactTypeComponentJar() {
327 val artifactType = BluePrintTypes.artifactTypeComponentJar()
328 if (this.artifactTypes == null) this.artifactTypes = hashMapOf()
329 this.artifactTypes!![artifactType.id!!] = artifactType
332 fun BluePrintTypes.artifactTypeComponentJar(): ArtifactType {
334 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_COMPONENT_JAR,
335 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
336 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
337 description = "Component Artifact"
343 /** Relationship Types */
345 fun ServiceTemplateBuilder.relationshipTypeConnectsTo() {
346 val relationshipType = BluePrintTypes.relationshipTypeConnectsTo()
347 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
348 this.relationshipTypes!![relationshipType.id!!] = relationshipType
351 fun BluePrintTypes.relationshipTypeConnectsTo(): RelationshipType {
352 return relationshipType(
353 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
354 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
355 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
356 description = "Relationship connects to"
358 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
362 fun ServiceTemplateBuilder.relationshipTypeDependsOn() {
363 val relationshipType = BluePrintTypes.relationshipTypeDependsOn()
364 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
365 this.relationshipTypes!![relationshipType.id!!] = relationshipType
368 fun BluePrintTypes.relationshipTypeDependsOn(): RelationshipType {
369 return relationshipType(
370 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON,
371 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
372 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
373 description = "Relationship depends on"
378 fun ServiceTemplateBuilder.relationshipTypeHostedOn() {
379 val relationshipType = BluePrintTypes.relationshipTypeHostedOn()
380 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
381 this.relationshipTypes!![relationshipType.id!!] = relationshipType
384 fun BluePrintTypes.relationshipTypeHostedOn(): RelationshipType {
385 return relationshipType(
386 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_HOSTED_ON,
387 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
388 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
389 description = "Relationship hosted on"