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
27 import kotlin.reflect.KClass
29 fun BluePrintTypes.nodeTypeSourceInput(): NodeType {
30 return nodeType(id = "source-input", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
31 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
32 description = "This is Input Resource Source Node Type") {}
35 fun BluePrintTypes.nodeTypeSourceDefault(): NodeType {
36 return nodeType(id = "source-default", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
37 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
38 description = "This is Default Resource Source Node Type") {}
41 fun BluePrintTypes.nodeTypeSourceDb(): NodeType {
42 return nodeType(id = "source-db", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
43 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
44 description = "This is Database Resource Source Node Type") {
45 property("type", BluePrintConstants.DATA_TYPE_STRING,
47 defaultValue("SQL".asJsonPrimitive())
49 validValues(arrayListOf("SQL".asJsonPrimitive(), "PLSQL".asJsonPrimitive()))
52 property("endpoint-selector", BluePrintConstants.DATA_TYPE_STRING,
54 property("query", BluePrintConstants.DATA_TYPE_STRING,
56 property("input-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
58 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
60 property("output-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
62 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
64 property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
65 true, "Resource Resolution dependency dictionary names.") {
66 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
71 fun BluePrintTypes.nodeTypeSourceRest(): NodeType {
72 return nodeType(id = "source-rest", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
73 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
74 description = "This is Rest Resource Source Node Type") {
75 property("type", BluePrintConstants.DATA_TYPE_STRING,
77 defaultValue("JSON".asJsonPrimitive())
79 validValues(arrayListOf("JSON".asJsonPrimitive(), "XML".asJsonPrimitive()))
82 property("verb", BluePrintConstants.DATA_TYPE_STRING,
84 defaultValue("GET".asJsonPrimitive())
86 validValues(arrayListOf("GET".asJsonPrimitive(), "POST".asJsonPrimitive(),
87 "DELETE".asJsonPrimitive(), "PUT".asJsonPrimitive()))
90 property("payload", BluePrintConstants.DATA_TYPE_STRING,
92 defaultValue("".asJsonPrimitive())
94 property("endpoint-selector", BluePrintConstants.DATA_TYPE_STRING,
96 property("url-path", BluePrintConstants.DATA_TYPE_STRING,
98 property("path", BluePrintConstants.DATA_TYPE_STRING,
100 property("expression-type", BluePrintConstants.DATA_TYPE_STRING,
102 defaultValue("JSON_PATH".asJsonPrimitive())
104 validValues(arrayListOf("JSON_PATH".asJsonPrimitive(), "JSON_POINTER".asJsonPrimitive()))
107 property("input-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
109 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
111 property("output-key-mapping", BluePrintConstants.DATA_TYPE_MAP,
113 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
115 property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
116 true, "Resource Resolution dependency dictionary names.") {
117 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
122 fun BluePrintTypes.nodeTypeSourceCapability(): NodeType {
123 return nodeType(id = "source-capability", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
124 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE,
125 description = "This is Component Resource Source Node Type") {
126 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING,
127 true, "Request Id, Unique Id for the request.") {
128 defaultValue(BluePrintConstants.SCRIPT_KOTLIN)
130 validValues(arrayListOf(BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive(),
131 BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(),
132 BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive()))
135 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING,
136 true, "Kotlin Script class name or jython script name.")
137 property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST,
138 true, "Resource Resolution dependency dictionary names.") {
139 entrySchema(BluePrintConstants.DATA_TYPE_STRING)
144 /** Node Template Source Input **/
145 fun BluePrintTypes.nodeTemplateSourceInput(id: String, description: String,
146 block: SourceInputNodeTemplateBuilder.() -> Unit): NodeTemplate {
147 return SourceInputNodeTemplateBuilder(id, description).apply(block).build()
150 class SourceInputNodeTemplateBuilder(id: String, description: String) :
151 AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>(id,
152 "source-input", description)
154 /** Node Template Source Default **/
155 fun BluePrintTypes.nodeTemplateSourceDefault(id: String, description: String,
156 block: SourceDefaultNodeTemplateBuilder.() -> Unit): NodeTemplate {
157 return SourceDefaultNodeTemplateBuilder(id, description).apply(block).build()
160 class SourceDefaultNodeTemplateBuilder(id: String, description: String) :
161 AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>(id,
162 "source-default", description)
164 /** Node Template Source DB **/
165 fun BluePrintTypes.nodeTemplateSourceDb(id: String, description: String,
166 block: SourceDbNodeTemplateBuilder.() -> Unit): NodeTemplate {
167 return SourceDbNodeTemplateBuilder(id, description).apply(block).build()
170 class SourceDbNodeTemplateBuilder(id: String, description: String) :
171 AbstractNodeTemplatePropertyImplBuilder<SourceDbNodeTemplateBuilder.PropertiesBuilder>(id,
172 "source-db", description) {
174 class PropertiesBuilder : PropertiesAssignmentBuilder() {
175 fun type(type: String) = type(type.asJsonPrimitive())
177 fun type(type: JsonNode) {
178 property("type", type)
181 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
183 fun endpointSelector(endpointSelector: JsonNode) {
184 property("endpoint-selector", endpointSelector)
187 fun query(query: String) = query(query.asJsonPrimitive())
189 fun query(query: JsonNode) {
190 property("query", query)
193 fun inputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
194 val map = KeyMappingBuilder().apply(block).build()
195 property("input-key-mapping", map.asJsonType())
198 fun outputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
199 val map = KeyMappingBuilder().apply(block).build()
200 property("output-key-mapping", map.asJsonType())
203 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
205 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
207 fun keyDependencies(keyDependencies: JsonNode) {
208 property("key-dependencies", keyDependencies)
213 class KeyMappingBuilder() {
214 val map: MutableMap<String, String> = hashMapOf()
215 fun map(key: String, value: String) {
219 fun build(): MutableMap<String, String> {
225 /** Node Template Source Rest **/
226 fun BluePrintTypes.nodeTemplateSourceRest(id: String, description: String,
227 block: SourceRestNodeTemplateBuilder.() -> Unit): NodeTemplate {
228 return SourceRestNodeTemplateBuilder(id, description).apply(block).build()
231 class SourceRestNodeTemplateBuilder(id: String, description: String) :
232 AbstractNodeTemplatePropertyImplBuilder<SourceRestNodeTemplateBuilder.PropertiesBuilder>(id,
233 "source-rest", description) {
235 class PropertiesBuilder : PropertiesAssignmentBuilder() {
236 fun type(type: String) = type(type.asJsonPrimitive())
238 fun type(type: JsonNode) {
239 property("type", type)
242 fun endpointSelector(endpointSelector: String) = endpointSelector(endpointSelector.asJsonPrimitive())
244 fun endpointSelector(endpointSelector: JsonNode) {
245 property("endpoint-selector", endpointSelector)
248 fun verb(verb: String) = verb(verb.asJsonPrimitive())
250 fun verb(verb: JsonNode) {
251 property("verb", verb)
254 fun payload(payload: String) = payload(payload.asJsonPrimitive())
256 fun payload(payload: JsonNode) {
257 property("payload", payload)
260 fun urlPath(urlPath: String) = urlPath(urlPath.asJsonPrimitive())
262 fun urlPath(urlPath: JsonNode) {
263 property("url-path", urlPath)
266 fun path(path: String) = path(path.asJsonPrimitive())
268 fun path(path: JsonNode) {
269 property("path", path)
272 fun expressionType(expressionType: String) = expressionType(expressionType.asJsonPrimitive())
274 fun expressionType(expressionType: JsonNode) {
275 property("expression-type", expressionType)
278 fun inputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
279 val map = KeyMappingBuilder().apply(block).build()
280 property("input-key-mapping", map.asJsonType())
283 fun outputKeyMapping(block: KeyMappingBuilder.() -> Unit) {
284 val map = KeyMappingBuilder().apply(block).build()
285 property("output-key-mapping", map.asJsonType())
288 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
290 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
292 fun keyDependencies(keyDependencies: JsonNode) {
293 property("key-dependencies", keyDependencies)
298 /** Node Template Source Rest **/
299 fun BluePrintTypes.nodeTemplateSourceCapability(id: String, description: String,
300 block: SourceCapabilityNodeTemplateBuilder.() -> Unit): NodeTemplate {
301 return SourceCapabilityNodeTemplateBuilder(id, description).apply(block).build()
304 class SourceCapabilityNodeTemplateBuilder(id: String, description: String) :
305 AbstractNodeTemplatePropertyImplBuilder<SourceCapabilityNodeTemplateBuilder.PropertiesBuilder>(id,
306 "source-capability", description) {
308 class PropertiesBuilder : PropertiesAssignmentBuilder() {
309 fun type(type: String) = type(type.asJsonPrimitive())
311 fun type(type: JsonNode) {
312 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type)
315 fun scriptClassReference(scriptClassReference: KClass<*>) {
316 scriptClassReference(scriptClassReference.qualifiedName!!)
319 fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive())
321 fun scriptClassReference(scriptClassReference: JsonNode) {
322 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference)
325 fun keyDependencies(keyDependencies: String) = keyDependencies(keyDependencies.asJsonType())
327 fun keyDependencies(keyDependencies: List<String>) = keyDependencies(keyDependencies.asJsonString())
329 fun keyDependencies(keyDependencies: JsonNode) {
330 property("key-dependencies", keyDependencies)