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()
173 /** Blueprint Type Extensions */
175 fun BluePrintTypes.nodeTypeComponent(): NodeType {
177 id = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
178 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
179 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
180 description = "This is default Component Node"
185 fun BluePrintTypes.nodeTypeWorkflow(): NodeType {
187 id = BluePrintConstants.MODEL_TYPE_NODE_WORKFLOW,
188 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
189 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
190 description = "This is default Workflow Node"
195 fun BluePrintTypes.nodeTypeVnf(): NodeType {
197 id = BluePrintConstants.MODEL_TYPE_NODE_VNF,
198 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
199 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
200 description = "This is default VNF Node"
205 fun BluePrintTypes.nodeTypeResourceSource(): NodeType {
207 id = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
208 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
209 derivedFrom = BluePrintConstants.MODEL_TYPE_NODES_ROOT,
210 description = "This is default Resource Source Node"
217 fun BluePrintTypes.artifactTypeTemplateVelocity(): ArtifactType {
219 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_VELOCITY,
220 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
221 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
222 description = "Velocity Artifact"
228 fun BluePrintTypes.artifactTypeTempleJinja(): ArtifactType {
230 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA,
231 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
232 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
233 description = "Jinja Artifact"
239 fun BluePrintTypes.artifactTypeMappingResource(): ArtifactType {
241 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_MAPPING_RESOURCE,
242 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
243 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
244 description = "Mapping Resource Artifact"
250 @Deprecated("CDS won't support", replaceWith = ReplaceWith("artifactTypeScriptKotlin"))
251 fun BluePrintTypes.artifactTypeScriptJython(): ArtifactType {
253 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_JYTHON,
254 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
255 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
256 description = "Jython Script Artifact"
262 fun BluePrintTypes.artifactTypeScriptKotlin(): ArtifactType {
264 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_SCRIPT_KOTLIN,
265 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
266 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
267 description = "Kotlin Script Artifact"
273 @Deprecated("CDS won't support, use implerative workflow definitions.")
274 fun BluePrintTypes.artifactTypeDirectedGraph(): ArtifactType {
276 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_DIRECTED_GRAPH,
277 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
278 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
279 description = "Directed Graph Artifact"
281 fileExt("xml", "json")
285 fun BluePrintTypes.artifactTypeComponentJar(): ArtifactType {
287 id = BluePrintConstants.MODEL_TYPE_ARTIFACT_COMPONENT_JAR,
288 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
289 derivedFrom = BluePrintConstants.MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION,
290 description = "Component Artifact"
296 /** Relationship Types */
298 fun BluePrintTypes.relationshipTypeConnectsTo(): RelationshipType {
299 return relationshipType(
300 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
301 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
302 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
303 description = "Relationship connects to"
305 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
309 fun BluePrintTypes.relationshipTypeDependsOn(): RelationshipType {
310 return relationshipType(
311 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON,
312 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
313 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
314 description = "Relationship depends on"
319 fun BluePrintTypes.relationshipTypeHostedOn(): RelationshipType {
320 return relationshipType(
321 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_HOSTED_ON,
322 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
323 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROOT,
324 description = "Relationship hosted on"