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.services.execution
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.asJsonPrimitive
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
29 import kotlin.reflect.KClass
31 /** Component Extensions **/
33 fun BluePrintTypes.nodeTypeComponentScriptExecutor(): NodeType {
34 return nodeType(id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
35 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
36 description = "Generic Script Component Executor") {
37 attribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false)
38 attribute(ComponentScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true)
40 operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") {
42 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING,
43 true, "Script Type") {
44 defaultValue(BluePrintConstants.SCRIPT_INTERNAL)
46 validValues(listOf(BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(),
47 BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(),
48 BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive()))
51 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING,
52 true, "Kotlin Script class name or jython script name.")
53 property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
54 false, "Dynamic Json Content or DSL Json reference.")
57 property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON,
58 false, "Output Response")
59 property(ComponentScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
60 true, "Status of the Component Execution ( success or failure )")
66 /** Component Builder */
67 fun BluePrintTypes.nodeTemplateComponentScriptExecutor(id: String,
69 block: ComponentScriptExecutorNodeTemplateBuilder.() -> Unit)
71 return ComponentScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
74 class ComponentScriptExecutorNodeTemplateBuilder(id: String, description: String) :
75 AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
76 ComponentScriptExecutorNodeTemplateBuilder.InputsBuilder,
77 ComponentScriptExecutorNodeTemplateBuilder.OutputsBuilder>(id, "component-script-executor",
78 "ComponentScriptExecutor",
81 class InputsBuilder : PropertiesAssignmentBuilder() {
83 fun type(type: String) = type(type.asJsonPrimitive())
85 fun type(type: JsonNode) {
86 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type)
89 fun scriptClassReference(scriptClassReference: KClass<*>) {
90 scriptClassReference(scriptClassReference.qualifiedName!!)
93 fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive())
95 fun scriptClassReference(scriptClassReference: JsonNode) {
96 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference)
99 fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
101 fun dynamicProperties(dynamicProperties: JsonNode) {
102 property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
106 class OutputsBuilder : PropertiesAssignmentBuilder() {
108 fun status(status: String) = status(status.asJsonPrimitive())
110 fun status(status: JsonNode) {
111 property(ComponentScriptExecutor.OUTPUT_STATUS, status)
114 fun responseData(responseData: String) = responseData(responseData.asJsonType())
116 fun responseData(responseData: JsonNode) {
117 property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData)