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 {
35 id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
36 derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT,
37 description = "Generic Script Component Executor"
39 attribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false)
40 attribute(ComponentScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true)
42 operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") {
45 ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING,
48 defaultValue(BluePrintConstants.SCRIPT_INTERNAL)
52 BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(),
53 BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(),
54 BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive()
60 ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING,
61 true, "Kotlin Script class name or jython script name."
64 ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON,
65 false, "Dynamic Json Content or DSL Json reference."
70 ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON,
71 false, "Output Response"
74 ComponentScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING,
75 true, "Status of the Component Execution ( success or failure )"
82 /** Component Builder */
83 fun BluePrintTypes.nodeTemplateComponentScriptExecutor(
86 block: ComponentScriptExecutorNodeTemplateBuilder.() -> Unit
89 return ComponentScriptExecutorNodeTemplateBuilder(id, description).apply(block).build()
92 class ComponentScriptExecutorNodeTemplateBuilder(id: String, description: String) :
93 AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder,
94 ComponentScriptExecutorNodeTemplateBuilder.InputsBuilder,
95 ComponentScriptExecutorNodeTemplateBuilder.OutputsBuilder>(
96 id, "component-script-executor",
97 "ComponentScriptExecutor",
101 class InputsBuilder : PropertiesAssignmentBuilder() {
103 fun type(type: String) = type(type.asJsonPrimitive())
105 fun type(type: JsonNode) {
106 property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type)
109 fun scriptClassReference(scriptClassReference: KClass<*>) {
110 scriptClassReference(scriptClassReference.qualifiedName!!)
113 fun scriptClassReference(scriptClassReference: String) = scriptClassReference(scriptClassReference.asJsonPrimitive())
115 fun scriptClassReference(scriptClassReference: JsonNode) {
116 property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference)
119 fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
121 fun dynamicProperties(dynamicProperties: JsonNode) {
122 property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, dynamicProperties)
126 class OutputsBuilder : PropertiesAssignmentBuilder() {
128 fun status(status: String) = status(status.asJsonPrimitive())
130 fun status(status: JsonNode) {
131 property(ComponentScriptExecutor.OUTPUT_STATUS, status)
134 fun responseData(responseData: String) = responseData(responseData.asJsonType())
136 fun responseData(responseData: JsonNode) {
137 property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData)