2 * Copyright © 2019 IBM.
3 * Copyright © 2021 Orange.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution
20 import com.fasterxml.jackson.databind.node.ArrayNode
21 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
22 import org.onap.ccsdk.cds.controllerblueprints.core.getAsString
23 import org.springframework.beans.factory.config.ConfigurableBeanFactory
24 import org.springframework.context.annotation.Scope
25 import org.springframework.stereotype.Component
28 * This is generic Script Component Executor function
29 * @author Brinda Santh
31 @Component("component-script-executor")
32 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
33 open class ComponentScriptExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
34 AbstractComponentFunction() {
38 const val INPUT_SCRIPT_TYPE = "script-type"
39 const val INPUT_SCRIPT_CLASS_REFERENCE = "script-class-reference"
40 const val INPUT_DYNAMIC_PROPERTIES = "dynamic-properties"
41 const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies"
43 const val ATTRIBUTE_RESPONSE_DATA = "response-data"
44 const val ATTRIBUTE_STATUS = "status"
46 const val OUTPUT_RESPONSE_DATA = "response-data"
47 const val OUTPUT_STATUS = "status"
50 lateinit var scriptComponentFunction: AbstractScriptComponentFunction
52 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
54 val scriptType = operationInputs.getAsString(INPUT_SCRIPT_TYPE)
55 val scriptClassReference = operationInputs.getAsString(INPUT_SCRIPT_CLASS_REFERENCE)
57 val scriptDependencies: MutableList<String> = arrayListOf()
58 populateScriptDependencies(scriptDependencies)
60 scriptComponentFunction = componentFunctionScriptingService.scriptInstance(
62 scriptClassReference, scriptDependencies
65 // Handles both script processing and error handling
66 scriptComponentFunction.executeScript(executionServiceInput)
69 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
70 addError("Failed in ComponentScriptExecutor : ${runtimeException.message}")
73 open fun populateScriptDependencies(scriptDependencies: MutableList<String>) {
74 val instanceDependenciesNode = operationInputs.get(INPUT_INSTANCE_DEPENDENCIES) as? ArrayNode
75 instanceDependenciesNode?.forEach { instanceName ->
76 scriptDependencies.add(instanceName.textValue())