Add netconf script component function
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Tue, 12 Feb 2019 20:26:19 +0000 (15:26 -0500)
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Tue, 12 Feb 2019 20:26:19 +0000 (15:26 -0500)
Change-Id: I094025fba5626bae0b4b13320f1cbbb76cda3bfd
Issue-ID: CCSDK-790
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
16 files changed:
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfExecutionData.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfSshClientLib.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/DeviceInfo.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/NetconfRpcClientService.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/NetconfDeviceProperties.kt [deleted file]
ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt
ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonService.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonService.kt [deleted file]
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonServiceTest.kt [moved from ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonServiceTest.kt with 91% similarity]
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt

index c007914..ab3372e 100644 (file)
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
 
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.ComponentJythonExecutor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
-import org.springframework.context.ApplicationContext
 import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Component
 
 @Component("component-netconf-executor")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentNetconfExecutor(private var applicationContext: ApplicationContext, private val netconfExecutorConfiguration: NetconfExecutorConfiguration,
-                                    private val blueprintPythonService: BlueprintPythonService)
-    : ComponentJythonExecutor(applicationContext, blueprintPythonService) {
+open class ComponentNetconfExecutor(private val blueprintJythonService: BlueprintJythonService)
+    : AbstractComponentFunction() {
 
     private val log = LoggerFactory.getLogger(ComponentNetconfExecutor::class.java)
-    lateinit var deviceInfo: DeviceInfo
 
+    lateinit var scriptComponent: NetconfComponentFunction
 
     override fun process(executionServiceInput: ExecutionServiceInput) {
 
-         super.process(executionServiceInput)
+        scriptComponent = blueprintJythonService.jythonComponentInstance(this) as NetconfComponentFunction
+        checkNotNull(scriptComponent) { "failed to get netconf script component" }
 
+        scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
+        scriptComponent.processId = processId
+        scriptComponent.workflowName = workflowName
+        scriptComponent.stepName = stepName
+        scriptComponent.interfaceName = interfaceName
+        scriptComponent.operationName = operationName
+        scriptComponent.nodeTemplateName = nodeTemplateName
+        scriptComponent.operationInputs = operationInputs
 
+        scriptComponent.process(executionServiceInput)
     }
 
-    fun setdeviceInfo(deviceInfo: DeviceInfo) {
-        this.deviceInfo = deviceInfo
+    override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+        scriptComponent.recover(runtimeException, executionRequest)
     }
+
+
 }
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
new file mode 100644 (file)
index 0000000..d480bdd
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *  Copyright © 2018 IBM.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.NetconfRpcClientService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+
+
+abstract class NetconfComponentFunction : AbstractComponentFunction() {
+
+    fun deviceProperties(requirementName: String): DeviceInfo {
+
+        val blueprintContext = bluePrintRuntimeService.bluePrintContext()
+
+        val requirement = blueprintContext.nodeTemplateRequirement(nodeTemplateName, requirementName)
+
+        val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(requirement
+                .node!!, requirement.capability!!)
+
+        return deviceProperties(capabilityProperties)
+    }
+
+    fun deviceProperties(capabilityProperty: MutableMap<String, JsonNode>): DeviceInfo {
+        return JacksonUtils.getInstanceFromMap(capabilityProperty, DeviceInfo::class.java)
+    }
+
+    fun netconfRpcClientService(): NetconfRpcClientService {
+        return NetconfRpcService()
+    }
+
+    fun netconfRpcClientService(requirementName: String): NetconfRpcClientService {
+        val deviceProperties = deviceProperties(requirementName)
+        val netconfRpcClientService = NetconfRpcService()
+        netconfRpcClientService.connect(deviceProperties)
+        return netconfRpcClientService
+    }
+
+    fun generateMessage(): String {
+        TODO()
+    }
+
+    fun resolveAndGenerateMesssage(): String {
+        TODO()
+    }
+
+}
\ No newline at end of file
index d538505..0e264bc 100644 (file)
@@ -16,8 +16,6 @@
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
 
-import com.fasterxml.jackson.databind.JsonNode
-import com.google.common.base.Preconditions
 import org.apache.commons.collections.CollectionUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionFactory
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.data.DeviceResponse
@@ -26,7 +24,6 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interf
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.NetconfRpcClientService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.NetconfSession
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.RpcMessageUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
@@ -48,37 +45,20 @@ class NetconfRpcService : NetconfRpcClientService {
     private val recordedApplyConfigIds = ArrayList<String>()
     private val DEFAULT_MESSAGE_TIME_OUT = 30
 
-    @Throws(NetconfException::class)
-    fun NetconfRpcService(capabilityProperty: MutableMap<String, JsonNode> ) {
+
+    override fun connect(deviceInfo: DeviceInfo): NetconfSession {
         try {
-             Preconditions.checkNotNull(capabilityProperty, "missing netconfDeviceInfo in netconf rpc client")
-             connect(getNetconfDeviceInfo(capabilityProperty))
-             log.info("NetconfRpcService initialised with deviceInfo {}", deviceInfo)
-            //configPersistService = ConfigPersistService(configResourceService)
 
+            this.deviceInfo = deviceInfo
+
+            log.info("Connecting Netconf Device .....")
+            this.netconfSession = NetconfSessionFactory.instance("DEFAULT_NETCONF_SESSION", deviceInfo)
+            publishMessage("Netconf Device Connection Established")
+            return this.netconfSession
         } catch (e: NetconfException) {
             publishMessage(String.format("Netconf Device Connection Failed, %s", e.message))
             throw NetconfException("Netconf Device Connection Failed,$deviceInfo",e)
         }
-
-    }
-
-    fun setdeviceInfo(deviceInfo: DeviceInfo) {
-        this.deviceInfo = deviceInfo
-    }
-
-    fun getNetconfDeviceInfo(capabilityProperty: MutableMap<String, JsonNode> ):DeviceInfo{
-        val netconfDeviceInfo = JacksonUtils.getInstanceFromMap(capabilityProperty, DeviceInfo::class.java)
-        this.deviceInfo = netconfDeviceInfo
-        return netconfDeviceInfo
-    }
-
-    fun connect(netconfDeviceInfo: DeviceInfo) {
-        log.info("in the connect method")
-        setdeviceInfo(netconfDeviceInfo)
-        netconfSession = NetconfSessionFactory.instance("DEFAULT_NETCONF_SESSION", netconfDeviceInfo)
-        publishMessage("Netconf Device Connection Established");
-
     }
 
     override  fun disconnect() {
index 0b63ea5..f66c14a 100644 (file)
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.data
 
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo
-import java.io.IOException
 import java.util.*
 
 
-
-
-class NetconfExecutionRequest {
-    lateinit var requestId: String
-    val action: String? = null
-    val source: String? = null
-    val loginKey: String? = null
-    val loginAccount: String? = null
-    val targetIP: String? = null
-    val port: Int = 0
-    val connectionTimeoutSec: Int = 0
-    val implementationScript: String? = null
-    val context: MutableMap<String, Any> = mutableMapOf()
-}
-
 class DeviceResponse {
     lateinit var deviceInfo: DeviceInfo
     lateinit var status: String
@@ -52,13 +36,6 @@ class DeviceResponse {
     }
 }
 
-class NetconfExecutionResponse {
-    val status: String? = null
-    val errorMessage: String? = null
-    val responseData: Any = Any()
-}
-
-
 class NetconfDeviceOutputEvent {
 
         private var type: NetconfDeviceOutputEvent.Type
index 0a51787..f21cce4 100644 (file)
@@ -16,8 +16,8 @@
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.data
 
 enum class NetconfSshClientLib(val sshClientString :String) {
-     APACHE_MINA("apache-mina"),
-     ETHZ_SSH2("ethz-ssh2");
+    APACHE_MINA("apache-mina"),
+    ETHZ_SSH2("ethz-ssh2");
 
     fun getEnum(valueOf: String): NetconfSshClientLib {
         return NetconfSshClientLib.valueOf(valueOf.toUpperCase().replace('-', '_'))
index ca67b34..f4360c7 100644 (file)
@@ -19,27 +19,25 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.inter
 import com.fasterxml.jackson.annotation.JsonIgnore
 import com.fasterxml.jackson.annotation.JsonProperty
 
-data class DeviceInfo (
-        @get:JsonProperty("login-account")
-        var name: String? = null,
-        @get:JsonProperty("login-key")
-        var pass: String? = null,
-        @get:JsonProperty("target-ip-address")
-        var ipAddress: String? = null,
-        @get:JsonProperty("port-number")
-        var port: Int = 0,
-        @get:JsonIgnore
-        var key: String? = null,
-        @get:JsonProperty("source")
-        var source: String? = null,
-       // var sshClientLib: NetconfSshClientLib = NetconfSshClientLib,
-        @get:JsonProperty("connection-time-out")
-        var connectTimeoutSec: Long = 30,
-        @get:JsonIgnore
-        var replyTimeout: Int = 60,
-        @get:JsonIgnore
-        var idleTimeout: Int = 45,
-        @get:JsonIgnore
-        var deviceId: String =  ipAddress + ":" + port
-){
-    }
\ No newline at end of file
+class DeviceInfo {
+    @get:JsonProperty("login-account")
+    var name: String? = null
+    @get:JsonProperty("login-key")
+    var pass: String? = null
+    @get:JsonProperty("target-ip-address")
+    var ipAddress: String? = null
+    @get:JsonProperty("port-number")
+    var port: Int = 0
+    @get:JsonIgnore
+    var key: String? = null
+    @get:JsonProperty("source")
+    var source: String? = null
+    @get:JsonProperty("connection-time-out")
+    var connectTimeoutSec: Long = 30
+    @get:JsonIgnore
+    var replyTimeout: Int = 60
+    @get:JsonIgnore
+    var idleTimeout: Int = 45
+    @get:JsonIgnore
+    var deviceId: String = "$ipAddress:$port"
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/NetconfDeviceProperties.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/NetconfDeviceProperties.kt
deleted file mode 100644 (file)
index 4073351..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils
-
-data class NetconfDeviceProperties(val loginKey:String,val loginAccount:String,val targetIpAddress:String,val portNumber:Int,val connectiontimeOut:Int) {
-
-
-
-}
\ No newline at end of file
index c33bfcf..d6f737f 100644 (file)
@@ -22,7 +22,7 @@ import com.fasterxml.jackson.databind.JsonNode
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
@@ -35,10 +35,10 @@ import org.springframework.test.context.TestPropertySource
 import org.springframework.test.context.junit4.SpringRunner
 
 @RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [NetconfExecutorConfiguration::class, BlueprintPythonService::class,
+@ContextConfiguration(classes = [NetconfExecutorConfiguration::class, BlueprintJythonService::class,
     PythonExecutorProperty::class])
 @TestPropertySource(properties =
-["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf;./../../../../components/scripts/python/ccsdk_blueprints",
+["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints",
     "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_netconf"])
 class ComponentNetconfExecutorTest {
 
@@ -70,9 +70,7 @@ class ComponentNetconfExecutorTest {
 
         componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
         componentNetconfExecutor.stepName = "activate-netconf"
-        
-        //TODO to fix build issue
-        //componentNetconfExecutor.apply(executionServiceInput)
+        componentNetconfExecutor.apply(executionServiceInput)
 
     }
 }
index eefead2..4ee48bc 100644 (file)
@@ -18,7 +18,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
 import org.junit.After
 import org.junit.Assert
 import org.junit.Before
-import org.junit.Test
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfDeviceSimulator
@@ -31,7 +30,13 @@ class NetconfSessionImplTest {
 
     @Before
     fun before() {
-        deviceInfo =DeviceInfo("name", "password", "localhost", 2224, "10")
+        deviceInfo = DeviceInfo().apply {
+            name = "name"
+            pass = "password"
+            ipAddress = "localhost"
+            port = 2224
+            connectTimeoutSec = 10
+        }
 
         device = NetconfDeviceSimulator(deviceInfo!!.port)
         device!!.start()
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonService.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonService.kt
new file mode 100644 (file)
index 0000000..fcaa57b
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2019 IBM, Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ArrayNode
+import org.apache.commons.io.FilenameUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.plugin.BlueprintPythonHost
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.context.ApplicationContext
+import org.springframework.stereotype.Service
+
+@Service
+class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty,
+                             private val applicationContext: ApplicationContext) {
+
+    val log: Logger = LoggerFactory.getLogger(BlueprintJythonService::class.java)
+
+    inline fun <reified T> jythonInstance(blueprintContext: BluePrintContext, pythonClassName: String, content: String,
+                                          dependencyInstanceNames: MutableMap<String, Any>?): T {
+
+        val blueprintBasePath: String = blueprintContext.rootPath
+        val pythonPath: MutableList<String> = arrayListOf()
+        pythonPath.add(blueprintBasePath)
+        pythonPath.addAll(pythonExecutorProperty.modulePaths)
+
+        val blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf())
+
+        val blueprintPythonHost = BlueprintPythonHost(blueprintPythonConfigurations)
+        val pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames)
+
+        log.info("Component Object {}", pyObject)
+
+        return pyObject.__tojava__(T::class.java) as T
+    }
+
+    fun jythonComponentInstance(abstractComponentFunction: AbstractComponentFunction): AbstractComponentFunction {
+
+        val bluePrintRuntimeService = abstractComponentFunction.bluePrintRuntimeService
+        val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+        val nodeTemplateName: String = abstractComponentFunction.nodeTemplateName
+        val operationInputs: MutableMap<String, JsonNode> = abstractComponentFunction.operationInputs
+
+        val operationAssignment: OperationAssignment = bluePrintContext
+                .nodeTemplateInterfaceOperation(abstractComponentFunction.nodeTemplateName,
+                        abstractComponentFunction.interfaceName, abstractComponentFunction.operationName)
+
+        val blueprintBasePath: String = bluePrintContext.rootPath
+
+        val artifactName: String = operationAssignment.implementation?.primary
+                ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)")
+
+        val artifactDefinition = bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName)
+
+        val pythonFileName = artifactDefinition.file
+                ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)")
+
+        val pythonClassName = FilenameUtils.getBaseName(pythonFileName)
+        log.info("Getting Jython Script Class($pythonClassName)")
+
+        val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
+
+        checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty")
+
+        val pythonPath: MutableList<String> = operationAssignment.implementation?.dependencies ?: arrayListOf()
+        pythonPath.add(blueprintBasePath)
+        pythonPath.addAll(pythonExecutorProperty.modulePaths)
+
+        val jythonInstances: MutableMap<String, Any> = hashMapOf()
+        jythonInstances["log"] = LoggerFactory.getLogger(nodeTemplateName)
+
+        val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode
+                ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})")
+
+        instanceDependenciesNode.forEach { instanceName ->
+            jythonInstances[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue())
+        }
+
+        val scriptComponentFunction = jythonInstance<AbstractComponentFunction>(bluePrintContext, pythonClassName,
+                content!!, jythonInstances)
+
+        return scriptComponentFunction
+
+    }
+
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonService.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintPythonService.kt
deleted file mode 100644 (file)
index 21adcd5..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright © 2019 IBM, Bell Canada.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor
-
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.plugin.BlueprintPythonHost
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-import org.springframework.stereotype.Service
-
-@Service("jython-executor-service")
-class BlueprintPythonService(val pythonExecutorProperty: PythonExecutorProperty){
-
-    val log: Logger = LoggerFactory.getLogger(BlueprintPythonService::class.java)
-
-    inline fun <reified T> jythonInstance(blueprintContext: BluePrintContext, pythonClassName: String, content: String,
-                                          dependencyInstanceNames: MutableMap<String, Any>?): T {
-
-        val blueprintBasePath: String = blueprintContext.rootPath
-        val pythonPath: MutableList<String> = arrayListOf()
-        pythonPath.add(blueprintBasePath)
-        pythonPath.addAll(pythonExecutorProperty.modulePaths)
-
-        val blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf())
-
-        val blueprintPythonHost = BlueprintPythonHost(blueprintPythonConfigurations)
-        val pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames)
-
-        log.info("Component Object {}", pyObject)
-
-        return pyObject.__tojava__(T::class.java) as T
-    }
-
-}
\ No newline at end of file
index ba55638..a74a779 100644 (file)
@@ -26,7 +26,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
 import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment
 import org.slf4j.LoggerFactory
-import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.ApplicationContext
 import org.springframework.context.annotation.Scope
@@ -35,7 +34,7 @@ import org.springframework.stereotype.Component
 @Component("component-jython-executor")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 open class ComponentJythonExecutor(private var applicationContext: ApplicationContext,
-                                   private val blueprintPythonService: BlueprintPythonService) : AbstractComponentFunction() {
+                                   private val blueprintJythonService: BlueprintJythonService) : AbstractComponentFunction() {
 
     private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java)
 
@@ -91,7 +90,7 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo
         }
 
         // Setup componentFunction
-        componentFunction = blueprintPythonService.jythonInstance(bluePrintContext, pythonClassName,
+        componentFunction = blueprintJythonService.jythonInstance(bluePrintContext, pythonClassName,
                 content!!, jythonInstance)
         componentFunction?.bluePrintRuntimeService = bluePrintRuntimeService
         componentFunction?.executionServiceInput = executionServiceInput
@@ -28,14 +28,14 @@ import org.springframework.test.context.junit4.SpringRunner
 import kotlin.test.assertNotNull
 
 @RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [BlueprintPythonService::class, PythonExecutorProperty::class])
+@ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::class])
 @TestPropertySource(properties =
 ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
     "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"])
-class BlueprintPythonServiceTest {
+class BlueprintJythonServiceTest {
 
     @Autowired
-    private lateinit var blueprintPythonService: BlueprintPythonService
+    private lateinit var blueprintJythonService: BlueprintJythonService
 
     @Test
     fun testGetAbstractPythonPlugin() {
@@ -46,7 +46,7 @@ class BlueprintPythonServiceTest {
 
         val content = JacksonUtils.getContent("./../../../../components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py")
 
-        val abstractComponentFunction = blueprintPythonService.jythonInstance<AbstractComponentFunction>(bluePrintContext, "SampleBlueprintComponent", content, dependencies)
+        val abstractComponentFunction = blueprintJythonService.jythonInstance<AbstractComponentFunction>(bluePrintContext, "SampleBlueprintComponent", content, dependencies)
 
         assertNotNull(abstractComponentFunction, "failed to get python component")
 
index 013039d..162a7b4 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
@@ -33,7 +33,7 @@ import java.io.File
 @Service("resource-assignment-processor-capability")
 open class CapabilityResourceAssignmentProcessor(private var applicationContext: ApplicationContext,
                                                  private val bluePrintScriptsService: BluePrintScriptsService,
-                                                 private val bluePrintPythonService: BlueprintPythonService) :
+                                                 private val bluePrintJythonService: BlueprintJythonService) :
         ResourceAssignmentProcessor() {
 
     companion object {
@@ -167,7 +167,7 @@ open class CapabilityResourceAssignmentProcessor(private var applicationContext:
                                                      dependencyInstances: MutableMap<String, Any>):
             ResourceAssignmentProcessor {
 
-        val resourceAssignmentProcessor = bluePrintPythonService
+        val resourceAssignmentProcessor = bluePrintJythonService
                 .jythonInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(), pythonClassName,
                         content, dependencyInstances)
 
index 3dda795..f884456 100644 (file)
@@ -20,7 +20,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr
 
 import org.junit.Test
 import org.junit.runner.RunWith
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
@@ -37,7 +37,7 @@ import kotlin.test.assertNotNull
 
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [CapabilityResourceAssignmentProcessor::class, BluePrintScriptsServiceImpl::class,
-    BlueprintPythonService::class, PythonExecutorProperty::class, MockCapabilityService::class])
+    BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class])
 @TestPropertySource(properties =
 ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
     "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"])