Add blueprint domain DSL
[ccsdk/cds.git] / ms / controllerblueprints / modules / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / dsl / BluePrintDSL.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.controllerblueprints.core.dsl
18
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.data.*
21 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
22
23 // CDS DSLs
24 fun blueprint(name: String, version: String, author: String, tags: String,
25               block: DSLBluePrintBuilder.() -> Unit): DSLBluePrint {
26     return DSLBluePrintBuilder(name, version, author, tags).apply(block).build()
27 }
28
29 // TOSCA DSLs
30 fun serviceTemplate(name: String, version: String, author: String, tags: String,
31                     block: ServiceTemplateBuilder.() -> Unit): ServiceTemplate {
32     return ServiceTemplateBuilder(name, version, author, tags).apply(block).build()
33 }
34
35 fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit): Workflow {
36     return WorkflowBuilder(id, description).apply(block).build()
37 }
38
39 fun nodeTemplate(id: String, type: String, description: String,
40                  block: NodeTemplateBuilder.() -> Unit): NodeTemplate {
41     return NodeTemplateBuilder(id, type, description).apply(block).build()
42 }
43
44 fun nodeType(id: String, version: String, derivedFrom: String, description: String,
45              block: NodeTypeBuilder.() -> Unit): NodeType {
46     return NodeTypeBuilder(id, version, derivedFrom, description).apply(block).build()
47 }
48
49 fun dataType(id: String, version: String, derivedFrom: String, description: String,
50              block: DataTypeBuilder.() -> Unit): DataType {
51     return DataTypeBuilder(id, version, derivedFrom, description).apply(block).build()
52 }
53
54 fun artifactType(id: String, version: String, derivedFrom: String, description: String,
55                  block: ArtifactTypeBuilder.() -> Unit): ArtifactType {
56     return ArtifactTypeBuilder(id, version, derivedFrom, description).apply(block).build()
57 }
58
59 // Input Function
60
61 fun getInput(inputKey: String): JsonNode {
62     return """{"get_input": "$inputKey"}""".jsonAsJsonType()
63 }
64
65 fun getAttribute(attributeId: String): JsonNode {
66     return """{"get_attribute": ["SELF", "$attributeId"]}""".jsonAsJsonType()
67 }
68
69 fun getAttribute(attributeId: String, jsonPath: String): JsonNode {
70     return """{"get_attribute": ["SELF", "$attributeId", "$jsonPath"]}""".jsonAsJsonType()
71 }
72
73 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String): JsonNode {
74     return """{"get_attribute": ["$nodeTemplateId", "$attributeId"]}""".jsonAsJsonType()
75 }
76
77 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String, jsonPath: String): JsonNode {
78     return """{"get_attribute": ["$nodeTemplateId", "$attributeId", "$jsonPath]}""".jsonAsJsonType()
79 }
80
81 // Property Function
82
83 fun getProperty(propertyId: String): JsonNode {
84     return """{"get_property": ["SELF", "$propertyId"]}""".jsonAsJsonType()
85 }
86
87 fun getProperty(propertyId: String, jsonPath: String): JsonNode {
88     return """{"get_property": ["SELF", "$propertyId", "$jsonPath"]}""".jsonAsJsonType()
89 }
90
91 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String): JsonNode {
92     return """{"get_property": ["$nodeTemplateName", "$propertyId"]}""".jsonAsJsonType()
93 }
94
95 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String, jsonPath: String): JsonNode {
96     return """{"get_property": ["$nodeTemplateName", "$propertyId", "$jsonPath]}""".jsonAsJsonType()
97 }
98
99 // Artifact Function
100
101 fun getArtifact(artifactId: String): JsonNode {
102     return """{"get_artifact": ["SELF", "$artifactId"]}""".jsonAsJsonType()
103 }
104
105 fun getNodeTemplateArtifact(nodeTemplateName: String, artifactId: String): JsonNode {
106     return """{"get_artifact": ["$nodeTemplateName", "$artifactId"]}""".jsonAsJsonType()
107 }