2 * Copyright © 2018 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.apps.blueprintsprocessor.functions.restconf.executor
19 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
20 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
21 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
22 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
24 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
25 import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
26 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService
27 import org.slf4j.LoggerFactory
28 import org.springframework.beans.factory.config.ConfigurableBeanFactory
29 import org.springframework.context.ApplicationContext
30 import org.springframework.context.annotation.Scope
31 import org.springframework.stereotype.Component
33 @Component("component-restconf-executor")
34 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
35 open class ComponentRestconfExecutor(private var applicationContext: ApplicationContext,
36 private val blueprintJythonService: BlueprintJythonService,
37 private val bluePrintScriptsService: BluePrintScriptsService,
38 private var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService) :
39 AbstractComponentFunction() {
41 private val log = LoggerFactory.getLogger(ComponentRestconfExecutor::class.java)
43 lateinit var scriptComponent: RestconfComponentFunction
46 const val SCRIPT_TYPE = "script-type"
47 const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
50 override fun process(executionRequest: ExecutionServiceInput) {
52 val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
53 val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
55 * Populate the Script Instance based on the Type
57 restconfComponentFunction(scriptType, scriptClassReference)
58 checkNotNull(scriptComponent) { "failed to get restconf script component" }
60 scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
61 scriptComponent.processId = processId
62 scriptComponent.workflowName = workflowName
63 scriptComponent.stepName = stepName
64 scriptComponent.interfaceName = interfaceName
65 scriptComponent.operationName = operationName
66 scriptComponent.nodeTemplateName = nodeTemplateName
67 scriptComponent.operationInputs = operationInputs
69 // Set the Rest Lib Property Service
70 scriptComponent.bluePrintRestLibPropertyService = bluePrintRestLibPropertyService
72 scriptComponent.process(executionServiceInput)
75 override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
76 scriptComponent.recover(runtimeException, executionRequest)
79 fun restconfComponentFunction(scriptType: String, scriptClassReference: String): RestconfComponentFunction {
80 log.info("processing restconf script type($scriptType), reference name($scriptClassReference)")
82 BluePrintConstants.SCRIPT_INTERNAL -> {
83 scriptComponent = bluePrintScriptsService.scriptInstance<RestconfComponentFunction>(scriptClassReference)
85 BluePrintConstants.SCRIPT_KOTLIN -> {
86 scriptComponent = bluePrintScriptsService.scriptInstance<RestconfComponentFunction>(bluePrintRuntimeService
87 .bluePrintContext(), scriptClassReference, false)
89 BluePrintConstants.SCRIPT_JYTHON -> {
90 scriptComponent = blueprintJythonService.jythonComponentInstance(this) as RestconfComponentFunction
93 throw BluePrintProcessorException("script type($scriptType) is not supported")
96 return scriptComponent