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.data.*
23 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
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()
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()
37 fun workflow(id: String, description: String, block: WorkflowBuilder.() -> Unit): Workflow {
38 return WorkflowBuilder(id, description).apply(block).build()
41 fun nodeTemplate(id: String, type: String, description: String,
42 block: NodeTemplateBuilder.() -> Unit): NodeTemplate {
43 return NodeTemplateBuilder(id, type, description).apply(block).build()
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()
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()
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()
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()
68 fun getInput(inputKey: String): JsonNode {
69 return """{"get_input": "$inputKey"}""".jsonAsJsonType()
72 fun getAttribute(attributeId: String): JsonNode {
73 return """{"get_attribute": ["SELF", "$attributeId"]}""".jsonAsJsonType()
76 fun getAttribute(attributeId: String, jsonPath: String): JsonNode {
77 return """{"get_attribute": ["SELF", "$attributeId", "$jsonPath"]}""".jsonAsJsonType()
80 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String): JsonNode {
81 return """{"get_attribute": ["$nodeTemplateId", "$attributeId"]}""".jsonAsJsonType()
84 fun getNodeTemplateAttribute(nodeTemplateId: String, attributeId: String, jsonPath: String): JsonNode {
85 return """{"get_attribute": ["$nodeTemplateId", "$attributeId", "$jsonPath]}""".jsonAsJsonType()
90 fun getProperty(propertyId: String): JsonNode {
91 return """{"get_property": ["SELF", "$propertyId"]}""".jsonAsJsonType()
94 fun getProperty(propertyId: String, jsonPath: String): JsonNode {
95 return """{"get_property": ["SELF", "$propertyId", "$jsonPath"]}""".jsonAsJsonType()
98 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String): JsonNode {
99 return """{"get_property": ["$nodeTemplateName", "$propertyId"]}""".jsonAsJsonType()
102 fun getNodeTemplateProperty(nodeTemplateName: String, propertyId: String, jsonPath: String): JsonNode {
103 return """{"get_property": ["$nodeTemplateName", "$propertyId", "$jsonPath]}""".jsonAsJsonType()
108 fun getArtifact(artifactId: String): JsonNode {
109 return """{"get_artifact": ["SELF", "$artifactId"]}""".jsonAsJsonType()
112 fun getNodeTemplateArtifact(nodeTemplateName: String, artifactId: String): JsonNode {
113 return """{"get_artifact": ["$nodeTemplateName", "$artifactId"]}""".jsonAsJsonType()
117 /** Blueprint Type Extensions */
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") {
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") {
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") {
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") {
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") {
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") {
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") {
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") {
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") {
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")
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") {
216 /** Relationship Types */
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") {
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") {