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.BluePrintConstants
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
25 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplatePropertyImplBuilder
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
30 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
31 import kotlin.reflect.KClass
33 fun BluePrintTypes.nodeTypeSourceInput(): NodeType {
35 id = "source-input", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
36 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
37 description = "This is Input Resource Source Node Type"
41 fun BluePrintTypes.nodeTypeSourceDefault(): NodeType {
43 id = "source-default", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
44 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
45 description = "This is Default Resource Source Node Type"
49 fun BluePrintTypes.nodeTypeSourceDb(): NodeType {
51 id = "source-db", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
52 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
53 description = "This is Database Resource Source Node Type"
56 "type", BluePrintConstants.DATA_TYPE_STRING,
59 defaultValue("SQL".asJsonPrimitive())
61 validValues(arrayListOf("SQL".asJsonPrimitive(), "PLSQL".asJsonPrimitive()))
65 "endpoint-selector", BluePrintConstants.DATA_TYPE_STRING,
69 "query", BluePrintConstants.DATA_TYPE_STRING,
73 "input-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
76 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
79 "output-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
82 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
85 "key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
86 true, "Resource Resolution dependency dictionary names."
88 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
93 fun BluePrintTypes.nodeTypeSourceRest(): NodeType {
95 id = "source-rest", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
96 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
97 description = "This is Rest Resource Source Node Type"
100 "type", BluePrintConstants.DATA_TYPE_STRING,
103 defaultValue("JSON".asJsonPrimitive())
105 validValues(arrayListOf("JSON".asJsonPrimitive(), "XML".asJsonPrimitive()))
109 "verb", BluePrintConstants.DATA_TYPE_STRING,
112 defaultValue("GET".asJsonPrimitive())
116 "GET".asJsonPrimitive(), "POST".asJsonPrimitive(),
117 "DELETE".asJsonPrimitive(), "PUT".asJsonPrimitive()
123 "payload", BluePrintConstants.DATA_TYPE_STRING,
126 defaultValue("".asJsonPrimitive())
129 "endpoint-selector", BluePrintConstants.DATA_TYPE_STRING,
133 "url-path", BluePrintConstants.DATA_TYPE_STRING,
137 "path", BluePrintConstants.DATA_TYPE_STRING,
141 "expression-type", BluePrintConstants.DATA_TYPE_STRING,
144 defaultValue("JSON_PATH".asJsonPrimitive())
146 validValues(arrayListOf("JSON_PATH".asJsonPrimitive(), "JSON_POINTER".asJsonPrimitive()))
150 "input-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
153 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
156 "output-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
159 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
162 "key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
163 true, "Resource Resolution dependency dictionary names."
165 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
170 fun BluePrintTypes.nodeTypeSourceCapability(): NodeType {
172 id = "source-capability", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
173 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
174 description = "This is Component Resource Source Node Type"
177 ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING,
178 true, "Request Id, Unique Id for the request."
180 defaultValue(BluePrintConstants.SCRIPT_KOTLIN)
184 BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive(),
185 BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(),
186 BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive()
192 ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING,
193 true, "Kotlin Script class name or jython script name."
196 "key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
197 true, "Resource Resolution dependency dictionary names."
199 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
204 /** Node Template Source Input **/
205 fun BluePrintTypes.nodeTemplateSourceInput(
208 block: SourceInputNodeTemplateBuilder.() -> Unit
210 return SourceInputNodeTemplateBuilder(id, description).apply(block).build()
213 class SourceInputNodeTemplateBuilder(id: String, description: String) :
214 AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>(
216 "source-input", description
219 /** Node Template Source Default **/
220 fun BluePrintTypes.nodeTemplateSourceDefault(
223 block: SourceDefaultNodeTemplateBuilder.() -> Unit
225 return SourceDefaultNodeTemplateBuilder(id, description).apply(block).build()
228 class SourceDefaultNodeTemplateBuilder(id: String, description: String) :
229 AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>(
231 "source-default", description
234 /** Node Template Source DB **/
235 fun BluePrintTypes.nodeTemplateSourceDb(
238 block: SourceDbNodeTemplateBuilder.() -> Unit
240 return SourceDbNodeTemplateBuilder(id, description).apply(block).build()
243 class SourceDbNodeTemplateBuilder(id: String, description: String) :
244 AbstractNodeTemplatePropertyImplBuilder<SourceDbNodeTemplateBuilder.PropertiesBuilder>(
246 "source-db", description
249 class PropertiesBuilder : PropertiesAssignmentBuilder() {
250 fun type(type: String) = type(type.asJsonPrimitive())
252 fun type(type: JsonNode) {
253 property("type", type)
256 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
258 fun endpointSelector(endpointSelector: JsonNode) {
259 property("endpoint-selector", endpointSelector)
262 fun query(query: String) = query(query.asJsonPrimitive())
264 fun query(query: JsonNode) {
265 property("query", query)
268 fun inputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
269 val map = KeyMappingBuilder().apply(block).build()
270 property("input-key-mapping", map.asJsonType())
273 fun outputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
274 val map = KeyMappingBuilder().apply(block).build()
275 property("output-key-mapping", map.asJsonType())
278 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
280 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
282 fun keyDependencies(keyDependencies: JsonNode) {
283 property("key-dependencies", keyDependencies)
288 class KeyMappingBuilder() {
289 val map: MutableMap<String, String> = hashMapOf()
290 fun map(key: String, value: String) {
294 fun build(): MutableMap<String, String> {
299 /** Node Template Source Rest **/
300 fun BluePrintTypes.nodeTemplateSourceRest(
303 block: SourceRestNodeTemplateBuilder.() -> Unit
305 return SourceRestNodeTemplateBuilder(id, description).apply(block).build()
308 class SourceRestNodeTemplateBuilder(id: String, description: String) :
309 AbstractNodeTemplatePropertyImplBuilder<SourceRestNodeTemplateBuilder.PropertiesBuilder>(
311 "source-rest", description
314 class PropertiesBuilder : PropertiesAssignmentBuilder() {
315 fun type(type: String) = type(type.asJsonPrimitive())
317 fun type(type: JsonNode) {
318 property("type", type)
321 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
323 fun endpointSelector(endpointSelector: JsonNode) {
324 property("endpoint-selector", endpointSelector)
327 fun verb(verb: String) = verb(verb.asJsonPrimitive())
329 fun verb(verb: JsonNode) {
330 property("verb", verb)
333 fun payload(payload: String) = payload(payload.asJsonPrimitive())
335 fun payload(payload: JsonNode) {
336 property("payload", payload)
339 fun urlPath(urlPath: String) = urlPath(urlPath.asJsonPrimitive())
341 fun urlPath(urlPath: JsonNode) {
342 property("url-path", urlPath)
345 fun path(path: String) = path(path.asJsonPrimitive())
347 fun path(path: JsonNode) {
348 property("path", path)
351 fun expressionType(expressionType: String) = expressionType(expressionType.asJsonPrimitive())
353 fun expressionType(expressionType: JsonNode) {
354 property("expression-type", expressionType)
357 fun inputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
358 val map = KeyMappingBuilder().apply(block).build()
359 property("input-key-mapping", map.asJsonType())
362 fun outputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
363 val map = KeyMappingBuilder().apply(block).build()
364 property("output-key-mapping", map.asJsonType())
367 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
369 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
371 fun keyDependencies(keyDependencies: JsonNode) {
372 property("key-dependencies", keyDependencies)
377 /** Node Template Source Rest **/
378 fun BluePrintTypes.nodeTemplateSourceCapability(
381 block: SourceCapabilityNodeTemplateBuilder.() -> Unit
383 return SourceCapabilityNodeTemplateBuilder(id, description).apply(block).build()
386 class SourceCapabilityNodeTemplateBuilder(id: String, description: String) :
387 AbstractNodeTemplatePropertyImplBuilder<SourceCapabilityNodeTemplateBuilder.PropertiesBuilder>(
389 "source-capability", description
392 class PropertiesBuilder : PropertiesAssignmentBuilder() {
393 fun type(type: String) = type(type.asJsonPrimitive())
395 fun type(type: JsonNode) {
396 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type)
399 fun scriptClassReference(scriptClassReference: KClass<*>) {
400 scriptClassReference(scriptClassReference.qualifiedName!!)
403 fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive())
405 fun scriptClassReference(scriptClassReference: JsonNode) {
406 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference)
409 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
411 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
413 fun keyDependencies(keyDependencies: JsonNode) {
414 property("key-dependencies", keyDependencies)