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() {
251 fun type(type: String) = type(type.asJsonPrimitive())
253 fun type(type: JsonNode) {
254 property("type", type)
257 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
259 fun endpointSelector(endpointSelector: JsonNode) {
260 property("endpoint-selector", endpointSelector)
263 fun query(query: String) = query(query.asJsonPrimitive())
265 fun query(query: JsonNode) {
266 property("query", query)
269 fun inputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
270 val map = KeyMappingBuilder().apply(block).build()
271 property("input-key-mapping", map.asJsonType())
274 fun outputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
275 val map = KeyMappingBuilder().apply(block).build()
276 property("output-key-mapping", map.asJsonType())
279 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
281 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
283 fun keyDependencies(keyDependencies: JsonNode) {
284 property("key-dependencies", keyDependencies)
289 class KeyMappingBuilder() {
291 val map: MutableMap<String, String> = hashMapOf()
292 fun map(key: String, value: String) {
296 fun build(): MutableMap<String, String> {
301 /** Node Template Source Rest **/
302 fun BlueprintTypes.nodeTemplateSourceRest(
305 block: SourceRestNodeTemplateBuilder.() -> Unit
307 return SourceRestNodeTemplateBuilder(id, description).apply(block).build()
310 class SourceRestNodeTemplateBuilder(id: String, description: String) :
311 AbstractNodeTemplatePropertyImplBuilder<SourceRestNodeTemplateBuilder.PropertiesBuilder>(
313 "source-rest", description
316 class PropertiesBuilder : PropertiesAssignmentBuilder() {
318 fun type(type: String) = type(type.asJsonPrimitive())
320 fun type(type: JsonNode) {
321 property("type", type)
324 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
326 fun endpointSelector(endpointSelector: JsonNode) {
327 property("endpoint-selector", endpointSelector)
330 fun verb(verb: String) = verb(verb.asJsonPrimitive())
332 fun verb(verb: JsonNode) {
333 property("verb", verb)
336 fun payload(payload: String) = payload(payload.asJsonPrimitive())
338 fun payload(payload: JsonNode) {
339 property("payload", payload)
342 fun urlPath(urlPath: String) = urlPath(urlPath.asJsonPrimitive())
344 fun urlPath(urlPath: JsonNode) {
345 property("url-path", urlPath)
348 fun path(path: String) = path(path.asJsonPrimitive())
350 fun path(path: JsonNode) {
351 property("path", path)
354 fun expressionType(expressionType: String) = expressionType(expressionType.asJsonPrimitive())
356 fun expressionType(expressionType: JsonNode) {
357 property("expression-type", expressionType)
360 fun inputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
361 val map = KeyMappingBuilder().apply(block).build()
362 property("input-key-mapping", map.asJsonType())
365 fun outputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
366 val map = KeyMappingBuilder().apply(block).build()
367 property("output-key-mapping", map.asJsonType())
370 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
372 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
374 fun keyDependencies(keyDependencies: JsonNode) {
375 property("key-dependencies", keyDependencies)
380 /** Node Template Source Rest **/
381 fun BlueprintTypes.nodeTemplateSourceCapability(
384 block: SourceCapabilityNodeTemplateBuilder.() -> Unit
386 return SourceCapabilityNodeTemplateBuilder(id, description).apply(block).build()
389 class SourceCapabilityNodeTemplateBuilder(id: String, description: String) :
390 AbstractNodeTemplatePropertyImplBuilder<SourceCapabilityNodeTemplateBuilder.PropertiesBuilder>(
392 "source-capability", description
395 class PropertiesBuilder : PropertiesAssignmentBuilder() {
397 fun type(type: String) = type(type.asJsonPrimitive())
399 fun type(type: JsonNode) {
400 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type)
403 fun scriptClassReference(scriptClassReference: KClass<*>) {
404 scriptClassReference(scriptClassReference.qualifiedName!!)
407 fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive())
409 fun scriptClassReference(scriptClassReference: JsonNode) {
410 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference)
413 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
415 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
417 fun keyDependencies(keyDependencies: JsonNode) {
418 property("key-dependencies", keyDependencies)