Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / netconf-executor / src / main / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / functions / netconf / executor / ComponentNetconfExecutor.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Modifications Copyright © 2019 IBM, Bell Canada.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
20
21 import com.fasterxml.jackson.databind.node.ArrayNode
22 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
23 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
24 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
25 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
26 import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
27 import org.slf4j.LoggerFactory
28 import org.springframework.beans.factory.config.ConfigurableBeanFactory
29 import org.springframework.context.annotation.Scope
30 import org.springframework.stereotype.Component
31
32 @Component("component-netconf-executor")
33 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
34 open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService)
35     : AbstractComponentFunction() {
36
37     private val log = LoggerFactory.getLogger(ComponentNetconfExecutor::class.java)
38
39     companion object {
40         const val SCRIPT_TYPE = "script-type"
41         const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
42         const val INSTANCE_DEPENDENCIES = "instance-dependencies"
43     }
44
45
46     lateinit var scriptComponent: NetconfComponentFunction
47
48     override fun process(executionRequest: ExecutionServiceInput) {
49
50         val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
51         val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
52         val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
53
54         val scriptDependencies: MutableList<String> = arrayListOf()
55         scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
56
57         instanceDependenciesNode?.forEach { instanceName ->
58             scriptDependencies.add(instanceName.textValue())
59         }
60
61         scriptComponent = componentFunctionScriptingService.scriptInstance<NetconfComponentFunction>(this, scriptType,
62                 scriptClassReference, scriptDependencies)
63
64
65         checkNotNull(scriptComponent) { "failed to get netconf script component" }
66
67         scriptComponent.process(executionServiceInput)
68     }
69
70     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
71         scriptComponent.recover(runtimeException, executionRequest)
72     }
73
74
75 }