c88408f19fb256e2e7e43a4656824694c118dd0b
[ccsdk/cds.git] /
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.BluePrintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.*
23 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
24
25 // CDS DSLs
26 fun blueprint(name: String, version: String, author: String, tags: String,
27               block: DSLBluePrintBuilder.() -> Unit): DSLBluePrint {
28     return DSLBluePrintBuilder(name, version, author, tags).apply(block).build()
29 }
30
31 // TOSCA DSLs
32 fun serviceTemplate(name: String, version: String, author: String, tags: String,
33                     block: ServiceTemplateBuilder.() -> Unit): ServiceTemplate {
34     return ServiceTemplateBuilder(name, version, author, tags).apply(block).build()
35 }
36
37 fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit): Workflow {
38     return WorkflowBuilder(id, description).apply(block).build()
39 }
40
41 fun nodeTemplate(id: String, type: String, description: String,
42                  block: NodeTemplateBuilder.() -> Unit): NodeTemplate {
43     return NodeTemplateBuilder(id, type, description).apply(block).build()
44 }
45
46 fun nodeType(id: String, version: String, derivedFrom: String, description: String,
47              block: NodeTypeBuilder.() -> Unit): NodeType {
48     return NodeTypeBuilder(id, version, derivedFrom, description).apply(block).build()
49 }
50
51 fun dataType(id: String, version: String, derivedFrom: String, description: String,
52              block: DataTypeBuilder.() -> Unit): DataType {
53     return DataTypeBuilder(id, version, derivedFrom, description).apply(block).build()
54 }
55
56 fun artifactType(id: String, version: String, derivedFrom: String, description: String,
57                  block: ArtifactTypeBuilder.() -> Unit): ArtifactType {
58     return ArtifactTypeBuilder(id, version, derivedFrom, description).apply(block).build()
59 }
60
61 fun relationshipType(id: String, version: String, derivedFrom: String, description: String,
62                      block: RelationshipTypeBuilder.() -> Unit): RelationshipType {
63     return RelationshipTypeBuilder(id, version, derivedFrom, description).apply(block).build()
64 }
65
66 // Input Function
67
68 fun getInput(inputKey: String): JsonNode {
69     return """{"get_input": "$inputKey"}""".jsonAsJsonType()
70 }
71
72 fun getAttribute(attributeId: String): JsonNode {
73     return """{"get_attribute": ["SELF", "$attributeId"]}""".jsonAsJsonType()
74 }
75
76 fun getAttribute(attributeId: String, jsonPath: String): JsonNode {
77     return """{"get_attribute": ["SELF", "$attributeId", "$jsonPath"]}""".jsonAsJsonType()
78 }
79
80 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String): JsonNode {
81     return """{"get_attribute": ["$nodeTemplateId", "$attributeId"]}""".jsonAsJsonType()
82 }
83
84 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String, jsonPath: String): JsonNode {
85     return """{"get_attribute": ["$nodeTemplateId", "$attributeId", "$jsonPath]}""".jsonAsJsonType()
86 }
87
88 // Property Function
89
90 fun getProperty(propertyId: String): JsonNode {
91     return """{"get_property": ["SELF", "$propertyId"]}""".jsonAsJsonType()
92 }
93
94 fun getProperty(propertyId: String, jsonPath: String): JsonNode {
95     return """{"get_property": ["SELF", "$propertyId", "$jsonPath"]}""".jsonAsJsonType()
96 }
97
98 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String): JsonNode {
99     return """{"get_property": ["$nodeTemplateName", "$propertyId"]}""".jsonAsJsonType()
100 }
101
102 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String, jsonPath: String): JsonNode {
103     return """{"get_property": ["$nodeTemplateName", "$propertyId", "$jsonPath]}""".jsonAsJsonType()
104 }
105
106 // Artifact Function
107
108 fun getArtifact(artifactId: String): JsonNode {
109     return """{"get_artifact": ["SELF", "$artifactId"]}""".jsonAsJsonType()
110 }
111
112 fun getNodeTemplateArtifact(nodeTemplateName: String, artifactId: String): JsonNode {
113     return """{"get_artifact": ["$nodeTemplateName", "$artifactId"]}""".jsonAsJsonType()
114 }
115
116
117 /** Blueprint Type Extensions */
118
119 fun BluePrintTypes.nodeTypeComponent(): NodeType {
120     return nodeType(id = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
121             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
122             derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
123             description = "This is default Component Node") {
124     }
125 }
126
127 fun BluePrintTypes.nodeTypeWorkflow(): NodeType {
128     return nodeType(id = BluePrintConstants.MODEL_TYPE_NODE_WORKFLOW,
129             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
130             derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
131             description = "This is default Workflow Node") {
132     }
133 }
134
135 fun BluePrintTypes.nodeTypeVnf(): NodeType {
136     return nodeType(id = BluePrintConstants.MODEL_TYPE_NODE_VNF,
137             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
138             derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
139             description = "This is default VNF Node") {
140     }
141 }
142
143 fun BluePrintTypes.nodeTypeResourceSource(): NodeType {
144     return nodeType(id = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
145             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
146             derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
147             description = "This is default Resource Source Node") {
148     }
149 }
150
151 /** Artifacts */
152
153 fun BluePrintTypes.artifactTypeTemplateVelocity(): ArtifactType {
154     return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_VELOCITY,
155             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
156             derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
157             description = "Velocity Artifact") {
158         fileExt("vtl")
159     }
160 }
161
162 fun BluePrintTypes.artifactTypeTempleJinja(): ArtifactType {
163     return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA,
164             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
165             derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
166             description = "Jinja Artifact") {
167         fileExt("jinja")
168     }
169 }
170
171 fun BluePrintTypes.artifactTypeMappingResource(): ArtifactType {
172     return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_MAPPING_RESOURCE,
173             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
174             derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
175             description = "Mapping Resource Artifact") {
176         fileExt("json")
177     }
178 }
179
180 fun BluePrintTypes.artifactTypeScriptJython(): ArtifactType {
181     return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_JYTHON,
182             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
183             derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
184             description = "Jython Script Artifact") {
185         fileExt("py")
186     }
187 }
188
189 fun BluePrintTypes.artifactTypeScriptKotlin(): ArtifactType {
190     return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_KOTLIN,
191             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
192             derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
193             description = "Kotlin Script Artifact") {
194         fileExt("kts")
195     }
196 }
197
198 fun BluePrintTypes.artifactTypeDirectedGraph(): ArtifactType {
199     return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_DIRECTED_GRAPH,
200             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
201             derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
202             description = "Directed Graph Artifact") {
203         fileExt("xml", "json")
204     }
205 }
206
207 fun BluePrintTypes.artifactTypeComponentJar(): ArtifactType {
208     return artifactType(id = BluePrintConstants.MODEL_TYPE_ARTIFACT_COMPONENT_JAR,
209             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
210             derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
211             description = "Component Artifact") {
212         fileExt("jar")
213     }
214 }
215
216 /** Relationship Types */
217
218 fun BluePrintTypes.relationshipTypeConnectsTo(): RelationshipType {
219     return relationshipType(id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
220             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
221             derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
222             description = "Relationship connects to") {
223     }
224 }
225
226 fun BluePrintTypes.relationshipTypeDependsOn(): RelationshipType {
227     return relationshipType(id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON,
228             version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
229             derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
230             description = "Relationship depends on") {
231     }
232 }