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 org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
20 import org.onap.ccsdk.cds.controllerblueprints.core.getAsString
21 import org.springframework.beans.factory.config.ConfigurableBeanFactory
22 import org.springframework.context.annotation.Scope
23 import org.springframework.stereotype.Component
26 * This is generic Script Component Executor function
27 * @author Brinda Santh
29 @Component("component-script-executor")
30 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
31 open class ComponentScriptExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
32 AbstractComponentFunction() {
36 const val INPUT_SCRIPT_TYPE = "script-type"
37 const val INPUT_SCRIPT_CLASS_REFERENCE = "script-class-reference"
38 const val INPUT_DYNAMIC_PROPERTIES = "dynamic-properties"
40 const val ATTRIBUTE_RESPONSE_DATA = "response-data"
41 const val ATTRIBUTE_STATUS = "status"
43 const val OUTPUT_RESPONSE_DATA = "response-data"
44 const val OUTPUT_STATUS = "status"
47 lateinit var scriptComponentFunction: AbstractScriptComponentFunction
49 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
51 val scriptType = operationInputs.getAsString(INPUT_SCRIPT_TYPE)
52 val scriptClassReference = operationInputs.getAsString(INPUT_SCRIPT_CLASS_REFERENCE)
54 val scriptDependencies: MutableList<String> = arrayListOf()
55 populateScriptDependencies(scriptDependencies)
57 scriptComponentFunction = componentFunctionScriptingService.scriptInstance(
59 scriptClassReference, scriptDependencies
62 // Handles both script processing and error handling
63 scriptComponentFunction.executeScript(executionServiceInput)
66 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
67 bluePrintRuntimeService.getBlueprintError()
68 .addError("Failed in ComponentScriptExecutor : ${runtimeException.message}")
71 open fun populateScriptDependencies(scriptDependencies: MutableList<String>) {
72 /** Place holder for Child to add extra dependencies */