Add remote python executor DSL properties
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / services / execution-service / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / services / execution / ComponentScriptExecutorDSL.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution
18
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.AbstractNodeTemplateImplBuilder
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType
29
30 /** Component Extensions **/
31
32 fun BluePrintTypes.nodeTypeComponentScriptExecutor(): NodeType {
33     return nodeType(id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
34             derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
35             description = "Generic Script Component Executor") {
36         attribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false)
37         attribute(ComponentScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true)
38
39         operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") {
40             inputs {
41                 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING,
42                         true, "Script Type") {
43                     defaultValue(BluePrintConstants.SCRIPT_INTERNAL)
44                     constrain {
45                         validValues(listOf(BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(),
46                                 BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(),
47                                 BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive()))
48                     }
49                 }
50                 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING,
51                         true, "Kotlin Script class name or jython script name.")
52                 property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
53                         false, "Dynamic Json Content or DSL Json reference.")
54             }
55             outputs {
56                 property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON,
57                         false, "Output Response")
58                 property(ComponentScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
59                         true, "Status of the Component Execution ( success or failure )")
60             }
61         }
62     }
63 }
64
65 /** Component Builder */
66 fun BluePrintTypes.nodeTemplateComponentScriptExecutor(id: String,
67                                                        description: String,
68                                                        block: ComponentScriptExecutorNodeTemplateImplBuilder.() -> Unit)
69         : NodeTemplate {
70     return ComponentScriptExecutorNodeTemplateImplBuilder(id, description).apply(block).build()
71 }
72
73 class ComponentScriptExecutorNodeTemplateImplBuilder(id: String, description: String) :
74         AbstractNodeTemplateImplBuilder<ComponentScriptExecutorInputAssignmentBuilder,
75                 ComponentScriptExecutorOutputAssignmentBuilder>(id, "component-script-executor",
76                 "ComponentScriptExecutor",
77                 description)
78
79 class ComponentScriptExecutorInputAssignmentBuilder : PropertiesAssignmentBuilder() {
80
81     fun type(type: String) = type(type.asJsonPrimitive())
82
83     fun type(type: JsonNode) {
84         property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type)
85     }
86
87     fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive())
88
89     fun scriptClassReference(scriptClassReference: JsonNode) {
90         property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference)
91     }
92
93     fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
94
95     fun dynamicProperties(dynamicProperties: JsonNode) {
96         property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
97     }
98 }
99
100 class ComponentScriptExecutorOutputAssignmentBuilder : PropertiesAssignmentBuilder() {
101
102     fun status(status: String) = status(status.asJsonPrimitive())
103
104     fun status(status: JsonNode) {
105         property(ComponentScriptExecutor.OUTPUT_STATUS, status)
106     }
107
108     fun responseData(responseData: String) = responseData(responseData.asJsonType())
109
110     fun responseData(responseData: JsonNode) {
111         property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData)
112     }
113 }