Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / python-executor / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / python / executor / ComponentJythonExecutor.kt
index 527f9dc..e2b6f65 100644 (file)
@@ -21,11 +21,12 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor
 import com.fasterxml.jackson.databind.node.ArrayNode
 import org.apache.commons.io.FilenameUtils
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.scripts.BlueprintJythonServiceImpl
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.scripts.PythonExecutorConstants
 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
-import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
-import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.PythonExecutorConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow
+import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
 import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
@@ -35,53 +36,51 @@ import org.springframework.stereotype.Component
 
 @Component("component-jython-executor")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentJythonExecutor(private var applicationContext: ApplicationContext,
-                                   private val blueprintJythonService: BlueprintJythonService) : AbstractComponentFunction() {
+open class ComponentJythonExecutor(
+    private var applicationContext: ApplicationContext,
+    private val blueprintJythonService: BlueprintJythonServiceImpl
+) : AbstractComponentFunction() {
 
     private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java)
 
-    private var componentFunction: AbstractComponentFunction? = null
+    private lateinit var componentFunction: JythonComponentFunction
 
-    override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
-        val request = super.prepareRequest(executionRequest)
+    override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+
+        log.info("Processing : $operationInputs")
         // Populate Component Instance
         populateJythonComponentInstance()
-        return request
-    }
 
-    override fun process(executionRequest: ExecutionServiceInput) {
-        log.info("Processing : $operationInputs")
         // Invoke Jython Component Script
-        componentFunction!!.process(executionServiceInput)
-
+        componentFunction.executeScript(executionServiceInput)
     }
 
-    override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
-        componentFunction!!.recover(runtimeException, executionRequest)
+    override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+        addError("Failed in ComponentJythonExecutor : ${runtimeException.message}")
     }
 
-    private fun populateJythonComponentInstance() {
+    private suspend fun populateJythonComponentInstance() {
         val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
 
         val operationAssignment: OperationAssignment = bluePrintContext
-                .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName)
+            .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName)
 
         val artifactName: String = operationAssignment.implementation?.primary
-                ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)")
+            ?: 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)")
+            ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)")
 
         val pythonClassName = FilenameUtils.getBaseName(pythonFileName)
 
         val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
 
-        checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty")
+        checkNotEmpty(content) { "artifact ($artifactName) content is empty" }
 
         val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode
-                ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})")
+            ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})")
 
         val jythonInstance: MutableMap<String, Any> = hashMapOf()
         jythonInstance["log"] = LoggerFactory.getLogger(pythonClassName)
@@ -92,14 +91,14 @@ open class ComponentJythonExecutor(private var applicationContext: ApplicationCo
         }
 
         // Setup componentFunction
-        componentFunction = blueprintJythonService.jythonInstance(bluePrintContext, pythonClassName,
-                content!!, jythonInstance)
-        componentFunction?.bluePrintRuntimeService = bluePrintRuntimeService
-        componentFunction?.executionServiceInput = executionServiceInput
-        componentFunction?.stepName = stepName
-        componentFunction?.interfaceName = interfaceName
-        componentFunction?.operationName = operationName
-        componentFunction?.processId = processId
-        componentFunction?.workflowName = workflowName
+        componentFunction = blueprintJythonService.jythonInstance(bluePrintContext, pythonClassName, content!!, jythonInstance)
+        componentFunction.bluePrintRuntimeService = bluePrintRuntimeService
+        componentFunction.executionServiceInput = executionServiceInput
+        componentFunction.stepName = stepName
+        componentFunction.interfaceName = interfaceName
+        componentFunction.operationName = operationName
+        componentFunction.processId = processId
+        componentFunction.workflowName = workflowName
+        componentFunction.scriptType = BluePrintConstants.SCRIPT_JYTHON
     }
-}
\ No newline at end of file
+}