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: BluePrintServiceDSLBuilder.() -> Unit
51 return BluePrintServiceDSLBuilder(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().jsonAsJsonType()
172 /** Blueprint Type Extensions */
174 fun BluePrintTypes.nodeTypeComponent(): NodeType {
176 id = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
177 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
178 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
179 description = "This is default Component Node"
184 fun BluePrintTypes.nodeTypeWorkflow(): NodeType {
186 id = BluePrintConstants.MODEL_TYPE_NODE_WORKFLOW,
187 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
188 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
189 description = "This is default Workflow Node"
194 fun BluePrintTypes.nodeTypeVnf(): NodeType {
196 id = BluePrintConstants.MODEL_TYPE_NODE_VNF,
197 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
198 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
199 description = "This is default VNF Node"
204 fun BluePrintTypes.nodeTypeResourceSource(): NodeType {
206 id = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
207 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
208 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
209 description = "This is default Resource Source Node"
216 fun BluePrintTypes.artifactTypeTemplateVelocity(): ArtifactType {
218 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_VELOCITY,
219 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
220 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
221 description = "Velocity Artifact"
227 fun BluePrintTypes.artifactTypeTempleJinja(): ArtifactType {
229 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA,
230 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
231 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
232 description = "Jinja Artifact"
238 fun BluePrintTypes.artifactTypeMappingResource(): ArtifactType {
240 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_MAPPING_RESOURCE,
241 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
242 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
243 description = "Mapping Resource Artifact"
249 fun BluePrintTypes.artifactTypeScriptJython(): ArtifactType {
251 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_JYTHON,
252 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
253 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
254 description = "Jython Script Artifact"
260 fun BluePrintTypes.artifactTypeScriptKotlin(): ArtifactType {
262 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_KOTLIN,
263 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
264 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
265 description = "Kotlin Script Artifact"
271 fun BluePrintTypes.artifactTypeDirectedGraph(): ArtifactType {
273 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_DIRECTED_GRAPH,
274 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
275 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
276 description = "Directed Graph Artifact"
278 fileExt("xml", "json")
282 fun BluePrintTypes.artifactTypeComponentJar(): ArtifactType {
284 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_COMPONENT_JAR,
285 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
286 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
287 description = "Component Artifact"
293 /** Relationship Types */
295 fun BluePrintTypes.relationshipTypeConnectsTo(): RelationshipType {
296 return relationshipType(
297 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
298 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
299 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
300 description = "Relationship connects to"
305 fun BluePrintTypes.relationshipTypeDependsOn(): RelationshipType {
306 return relationshipType(
307 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON,
308 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
309 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
310 description = "Relationship depends on"