bubble up python error to CDS output 70/91570/1
authorOleg Mitsura <oleg.mitsura@amdocs.com>
Tue, 16 Jul 2019 22:18:05 +0000 (18:18 -0400)
committerOleg Mitsura <oleg.mitsura@amdocs.com>
Tue, 16 Jul 2019 22:19:03 +0000 (18:19 -0400)
Issue-ID: CCSDK-1494

Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Change-Id: Iac9fc47ef51d92da507cc6d2dfee252490a2313a

ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt

index 6003089..78b7556 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
 
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.python.core.PyObject
 import org.python.util.PythonInterpreter
 
@@ -38,9 +39,12 @@ open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython){
         bluePrintPython.content = content!!
         bluePrintPython.pythonClassName = interfaceName
         bluePrintPython.moduleName = "Blueprint Python Script [Class Name = $interfaceName]"
-
-        return blueprintPythonInterpreterProxy.getPythonInstance(properties)
+        try {
+            return blueprintPythonInterpreterProxy.getPythonInstance(properties)
+        } catch (e: Exception) {
+            throw BluePrintProcessorException("Failed to execute Jython component ${e.toString()}", e)
+        }
     }
 
     //TODO Check potential errors in python scripts
-}
\ No newline at end of file
+}
index 8998337..6e514de 100644 (file)
  */
 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
 
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.python.core.PyObject
+import org.python.core.PySyntaxError
 import org.python.util.PythonInterpreter
 
-open class BlueprintPythonInterpreterProxy(private val bluePrintPython: BluePrintPython): PythonInterpreter(){
+open class BlueprintPythonInterpreterProxy(private val bluePrintPython: BluePrintPython) : PythonInterpreter() {
 
-    fun getPythonInstance(properties: MutableMap<String, Any>?): PyObject{
+    fun getPythonInstance(properties: MutableMap<String, Any>?): PyObject {
         properties?.forEach { (name, value) ->
             this.set(name, value)
         }
@@ -28,13 +30,17 @@ open class BlueprintPythonInterpreterProxy(private val bluePrintPython: BluePrin
         this.exec("import sys")
 
         bluePrintPython.content.let {
-            this.exec(bluePrintPython.content)
+            try {
+                this.exec(bluePrintPython.content)
+            } catch (e: PySyntaxError) {
+                throw BluePrintProcessorException("Error executing Jython code! Python error: '${e.toString()}'", e)
+            }
         }
 
         val initCommand = bluePrintPython.pythonClassName.plus(" = ").plus(
-                                                        bluePrintPython.pythonClassName).plus("()")
+            bluePrintPython.pythonClassName).plus("()")
         this.exec(initCommand)
 
         return this.get(bluePrintPython.pythonClassName)
     }
-}
\ No newline at end of file
+}