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.blueprintsprocessor.functions.resource.resolution
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor
21 import org.onap.ccsdk.cds.controllerblueprints.core.*
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
24 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplatePropertyImplBuilder
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
28 fun BluePrintTypes.nodeTypeSourceInput(): NodeType {
29 return nodeType(id = "source-input", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
30 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
31 description = "This is Input Resource Source Node Type") {}
34 fun BluePrintTypes.nodeTypeSourceDefault(): NodeType {
35 return nodeType(id = "source-default", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
36 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
37 description = "This is Default Resource Source Node Type") {}
40 fun BluePrintTypes.nodeTypeSourceDb(): NodeType {
41 return nodeType(id = "source-db", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
42 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
43 description = "This is Database Resource Source Node Type") {
44 property("type", BluePrintConstants.DATA_TYPE_STRING,
46 defaultValue("SQL".asJsonPrimitive())
48 validValues(arrayListOf("SQL".asJsonPrimitive(), "PLSQL".asJsonPrimitive()))
51 property("endpoint-selector", BluePrintConstants.DATA_TYPE_STRING,
53 property("query", BluePrintConstants.DATA_TYPE_STRING,
55 property("input-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
57 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
59 property("output-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
61 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
63 property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
64 true, "Resource Resolution dependency dictionary names.") {
65 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
70 fun BluePrintTypes.nodeTypeSourceRest(): NodeType {
71 return nodeType(id = "source-rest", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
72 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
73 description = "This is Rest Resource Source Node Type") {
74 property("type", BluePrintConstants.DATA_TYPE_STRING,
76 defaultValue("JSON".asJsonPrimitive())
78 validValues(arrayListOf("JSON".asJsonPrimitive(), "XML".asJsonPrimitive()))
81 property("verb", BluePrintConstants.DATA_TYPE_STRING,
83 defaultValue("GET".asJsonPrimitive())
85 validValues(arrayListOf("GET".asJsonPrimitive(), "POST".asJsonPrimitive(),
86 "DELETE".asJsonPrimitive(), "PUT".asJsonPrimitive()))
89 property("payload", BluePrintConstants.DATA_TYPE_STRING,
91 defaultValue("".asJsonPrimitive())
93 property("endpoint-selector", BluePrintConstants.DATA_TYPE_STRING,
95 property("url-path", BluePrintConstants.DATA_TYPE_STRING,
97 property("path", BluePrintConstants.DATA_TYPE_STRING,
99 property("expression-type", BluePrintConstants.DATA_TYPE_STRING,
101 defaultValue("JSON_PATH".asJsonPrimitive())
103 validValues(arrayListOf("JSON_PATH".asJsonPrimitive(), "JSON_POINTER".asJsonPrimitive()))
106 property("input-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
108 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
110 property("output-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
112 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
114 property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
115 true, "Resource Resolution dependency dictionary names.") {
116 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
121 fun BluePrintTypes.nodeTypeSourceCapability(): NodeType {
122 return nodeType(id = "source-capability", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
123 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
124 description = "This is Component Resource Source Node Type") {
125 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING,
126 true, "Request Id, Unique Id for the request.") {
127 defaultValue(BluePrintConstants.SCRIPT_KOTLIN)
129 validValues(arrayListOf(BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive(),
130 BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(),
131 BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive()))
134 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING,
135 true, "Kotlin Script class name or jython script name.")
136 property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
137 true, "Resource Resolution dependency dictionary names.") {
138 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
143 /** Node Template Source Input **/
144 fun BluePrintTypes.nodeTemplateSourceInput(id: String, description: String,
145 block: SourceInputNodeTemplateBuilder.() -> Unit): NodeTemplate {
146 return SourceInputNodeTemplateBuilder(id, description).apply(block).build()
149 class SourceInputNodeTemplateBuilder(id: String, description: String) :
150 AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>(id,
151 "source-input", description)
153 /** Node Template Source Default **/
154 fun BluePrintTypes.nodeTemplateSourceDefault(id: String, description: String,
155 block: SourceDefaultNodeTemplateBuilder.() -> Unit): NodeTemplate {
156 return SourceDefaultNodeTemplateBuilder(id, description).apply(block).build()
159 class SourceDefaultNodeTemplateBuilder(id: String, description: String) :
160 AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>(id,
161 "source-default", description)
163 /** Node Template Source DB **/
164 fun BluePrintTypes.nodeTemplateSourceDb(id: String, description: String,
165 block: SourceDbNodeTemplateBuilder.() -> Unit): NodeTemplate {
166 return SourceDbNodeTemplateBuilder(id, description).apply(block).build()
169 class SourceDbNodeTemplateBuilder(id: String, description: String) :
170 AbstractNodeTemplatePropertyImplBuilder<SourceDbNodeTemplateBuilder.PropertiesBuilder>(id,
171 "source-db", description) {
173 class PropertiesBuilder : PropertiesAssignmentBuilder() {
174 fun type(type: String) = type(type.asJsonPrimitive())
176 fun type(type: JsonNode) {
177 property("type", type)
180 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
182 fun endpointSelector(endpointSelector: JsonNode) {
183 property("endpoint-selector", endpointSelector)
186 fun query(query: String) = query(query.asJsonPrimitive())
188 fun query(query: JsonNode) {
189 property("query", query)
192 fun inputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
193 val map = KeyMappingBuilder().apply(block).build()
194 property("input-key-mapping", map.asJsonType())
197 fun outputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
198 val map = KeyMappingBuilder().apply(block).build()
199 property("output-key-mapping", map.asJsonType())
202 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
204 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
206 fun keyDependencies(keyDependencies: JsonNode) {
207 property("key-dependencies", keyDependencies)
212 class KeyMappingBuilder() {
213 val map: MutableMap<String, String> = hashMapOf()
214 fun map(key: String, value: String) {
218 fun build(): MutableMap<String, String> {
224 /** Node Template Source Rest **/
225 fun BluePrintTypes.nodeTemplateSourceRest(id: String, description: String,
226 block: SourceRestNodeTemplateBuilder.() -> Unit): NodeTemplate {
227 return SourceRestNodeTemplateBuilder(id, description).apply(block).build()
230 class SourceRestNodeTemplateBuilder(id: String, description: String) :
231 AbstractNodeTemplatePropertyImplBuilder<SourceRestNodeTemplateBuilder.PropertiesBuilder>(id,
232 "source-rest", description) {
234 class PropertiesBuilder : PropertiesAssignmentBuilder() {
235 fun type(type: String) = type(type.asJsonPrimitive())
237 fun type(type: JsonNode) {
238 property("type", type)
241 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
243 fun endpointSelector(endpointSelector: JsonNode) {
244 property("endpoint-selector", endpointSelector)
247 fun verb(verb: String) = verb(verb.asJsonPrimitive())
249 fun verb(verb: JsonNode) {
250 property("verb", verb)
253 fun payload(payload: String) = payload(payload.asJsonPrimitive())
255 fun payload(payload: JsonNode) {
256 property("payload", payload)
259 fun urlPath(urlPath: String) = urlPath(urlPath.asJsonPrimitive())
261 fun urlPath(urlPath: JsonNode) {
262 property("url-path", urlPath)
265 fun path(path: String) = path(path.asJsonPrimitive())
267 fun path(path: JsonNode) {
268 property("path", path)
271 fun expressionType(expressionType: String) = expressionType(expressionType.asJsonPrimitive())
273 fun expressionType(expressionType: JsonNode) {
274 property("expression-type", expressionType)
277 fun inputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
278 val map = KeyMappingBuilder().apply(block).build()
279 property("input-key-mapping", map.asJsonType())
282 fun outputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
283 val map = KeyMappingBuilder().apply(block).build()
284 property("output-key-mapping", map.asJsonType())
287 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
289 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
291 fun keyDependencies(keyDependencies: JsonNode) {
292 property("key-dependencies", keyDependencies)
297 /** Node Template Source Rest **/
298 fun BluePrintTypes.nodeTemplateSourceCapability(id: String, description: String,
299 block: SourceCapabilityNodeTemplateBuilder.() -> Unit): NodeTemplate {
300 return SourceCapabilityNodeTemplateBuilder(id, description).apply(block).build()
303 class SourceCapabilityNodeTemplateBuilder(id: String, description: String) :
304 AbstractNodeTemplatePropertyImplBuilder<SourceCapabilityNodeTemplateBuilder.PropertiesBuilder>(id,
305 "source-capability", description) {
307 class PropertiesBuilder : PropertiesAssignmentBuilder() {
308 fun type(type: String) = type(type.asJsonPrimitive())
310 fun type(type: JsonNode) {
311 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type)
314 fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive())
316 fun scriptClassReference(scriptClassReference: JsonNode) {
317 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference)
320 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
322 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
324 fun keyDependencies(keyDependencies: JsonNode) {
325 property("key-dependencies", keyDependencies)