From 47dd8e2e69f8a754c620a22b926faad2a02439f5 Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Tue, 16 Jul 2019 18:18:05 -0400 Subject: bubble up python error to CDS output Issue-ID: CCSDK-1494 Signed-off-by: Oleg Mitsura Change-Id: Iac9fc47ef51d92da507cc6d2dfee252490a2313a --- .../services/execution/scripts/BlueprintPythonHost.kt | 10 +++++++--- .../execution/scripts/BlueprintPythonInterpreterProxy.kt | 16 +++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'ms') diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt index 600308959..78b7556f3 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt @@ -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 +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt index 8998337c9..6e514de49 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt @@ -15,12 +15,14 @@ */ 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?): PyObject{ + fun getPythonInstance(properties: MutableMap?): 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 +} -- cgit 1.2.3-korg