Create restconf component function module
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / restconf-executor / src / main / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / functions / restconf / executor / ComponentRestconfExecutor.kt
1 /*
2  *  Copyright © 2018 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
18
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.slf4j.LoggerFactory
24 import org.springframework.beans.factory.config.ConfigurableBeanFactory
25 import org.springframework.context.ApplicationContext
26 import org.springframework.context.annotation.Scope
27 import org.springframework.stereotype.Component
28
29 @Component("component-restconf-executor")
30 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
31 open class ComponentRestconfExecutor(private var applicationContext: ApplicationContext,
32                                      private val blueprintJythonService: BlueprintJythonService,
33                                      var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService) :
34         AbstractComponentFunction() {
35
36     private val log = LoggerFactory.getLogger(ComponentRestconfExecutor::class.java)
37
38     lateinit var scriptComponent: RestconfComponentFunction
39
40     override fun process(executionRequest: ExecutionServiceInput) {
41         scriptComponent = blueprintJythonService.jythonComponentInstance(this) as RestconfComponentFunction
42         checkNotNull(scriptComponent) { "failed to get netconf script component" }
43
44         scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
45         scriptComponent.processId = processId
46         scriptComponent.workflowName = workflowName
47         scriptComponent.stepName = stepName
48         scriptComponent.interfaceName = interfaceName
49         scriptComponent.operationName = operationName
50         scriptComponent.nodeTemplateName = nodeTemplateName
51         scriptComponent.operationInputs = operationInputs
52
53         // Set the Rest Lib Property Service
54         scriptComponent.bluePrintRestLibPropertyService = bluePrintRestLibPropertyService
55
56         scriptComponent.process(executionServiceInput)
57     }
58
59     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
60         scriptComponent.recover(runtimeException, executionRequest)
61     }
62 }