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
30 /** Component Extensions **/
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)
39 operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") {
41 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING,
42 true, "Script Type") {
43 defaultValue(BluePrintConstants.SCRIPT_INTERNAL)
45 validValues(listOf(BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(),
46 BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(),
47 BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive()))
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.")
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 )")
65 /** Component Builder */
66 fun BluePrintTypes.nodeTemplateComponentScriptExecutor(id: String,
68 block: ComponentScriptExecutorNodeTemplateBuilder.() -> Unit)
70 return ComponentScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
73 class ComponentScriptExecutorNodeTemplateBuilder(id: String, description: String) :
74 AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
75 ComponentScriptExecutorNodeTemplateBuilder.InputsBuilder,
76 ComponentScriptExecutorNodeTemplateBuilder.OutputsBuilder>(id, "component-script-executor",
77 "ComponentScriptExecutor",
80 class InputsBuilder : PropertiesAssignmentBuilder() {
82 fun type(type: String) = type(type.asJsonPrimitive())
84 fun type(type: JsonNode) {
85 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type)
88 fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive())
90 fun scriptClassReference(scriptClassReference: JsonNode) {
91 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference)
94 fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
96 fun dynamicProperties(dynamicProperties: JsonNode) {
97 property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
101 class OutputsBuilder : PropertiesAssignmentBuilder() {
103 fun status(status: String) = status(status.asJsonPrimitive())
105 fun status(status: JsonNode) {
106 property(ComponentScriptExecutor.OUTPUT_STATUS, status)
109 fun responseData(responseData: String) = responseData(responseData.asJsonType())
111 fun responseData(responseData: JsonNode) {
112 property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData)