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