2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Modifications Copyright © 2019 IBM, Bell Canada.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
21 import com.fasterxml.jackson.databind.node.ArrayNode
22 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
24 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
25 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
26 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
27 import org.onap.ccsdk.cds.controllerblueprints.core.getAsString
28 import org.springframework.beans.factory.config.ConfigurableBeanFactory
29 import org.springframework.context.annotation.Scope
30 import org.springframework.stereotype.Component
32 @Component("component-netconf-executor")
33 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
34 open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
35 AbstractComponentFunction() {
39 const val SCRIPT_TYPE = "script-type"
40 const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
41 const val INSTANCE_DEPENDENCIES = "instance-dependencies"
44 lateinit var scriptComponent: AbstractScriptComponentFunction
46 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
48 val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
49 val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
50 val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
52 val scriptDependencies: MutableList<String> = arrayListOf()
53 scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
55 instanceDependenciesNode?.forEach { instanceName ->
56 scriptDependencies.add(instanceName.textValue())
59 scriptComponent = componentFunctionScriptingService
60 .scriptInstance<AbstractScriptComponentFunction>(
62 scriptClassReference, scriptDependencies
65 checkNotNull(scriptComponent) { "failed to get netconf script component" }
67 // Handles both script processing and error handling
68 scriptComponent.executeScript(executionServiceInput)
70 componentFunctionScriptingService.cleanupInstance(
71 bluePrintRuntimeService.bluePrintContext(),
76 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
77 bluePrintRuntimeService.getBluePrintError()
78 .addError("Failed in ComponentNetconfExecutor : ${runtimeException.message}")