Skip to content
Snippets Groups Projects
Commit 058d4b23 authored by Stefano Borini's avatar Stefano Borini
Browse files

More robust logging for bdss

parent 5985701f
No related branches found
No related tags found
1 merge request!138More robust logging for BDSS
This commit is part of merge request !138. Comments created here will be created in the context of that merge request.
...@@ -31,7 +31,15 @@ class CoreEvaluationDriver(BaseCoreDriver): ...@@ -31,7 +31,15 @@ class CoreEvaluationDriver(BaseCoreDriver):
mco_factory = mco_model.factory mco_factory = mco_model.factory
log.info("Creating communicator") log.info("Creating communicator")
mco_communicator = mco_factory.create_communicator() try:
mco_communicator = mco_factory.create_communicator()
except Exception:
log.exception(
"Unable to create communicator from MCO factory '{}' "
"in plugin '{}'. This may indicate a programming "
"error in the plugin".format(
mco_factory.get_identifier(),
mco_factory.plugin.id))
mco_data_values = _get_data_values_from_mco( mco_data_values = _get_data_values_from_mco(
mco_model, mco_communicator) mco_model, mco_communicator)
...@@ -85,7 +93,16 @@ def _compute_layer_results(environment_data_values, ...@@ -85,7 +93,16 @@ def _compute_layer_results(environment_data_values,
for model in layer.data_sources: for model in layer.data_sources:
factory = model.factory factory = model.factory
data_source = factory.create_data_source() try:
data_source = factory.create_data_source()
except Exception:
log.exception(
"Unable to create data source from factory '{}' "
"in plugin '{}'. This may indicate a programming "
"error in the plugin".format(
factory.get_identifier(),
factory.plugin.id))
raise
# Get the slots for this data source. These must be matched to # Get the slots for this data source. These must be matched to
# the appropriate values in the environment data values. # the appropriate values in the environment data values.
...@@ -111,8 +128,9 @@ def _compute_layer_results(environment_data_values, ...@@ -111,8 +128,9 @@ def _compute_layer_results(environment_data_values,
try: try:
res = data_source.run(model, passed_data_values) res = data_source.run(model, passed_data_values)
except Exception: except Exception:
log.error("Evaluation could not be performed. Run method raised" log.exception(
"exception", exc_info=True) "Evaluation could not be performed. "
"Run method raised exception.")
raise raise
if len(res) != len(out_slots): if len(res) != len(out_slots):
......
...@@ -8,10 +8,6 @@ from force_bdss.mco.base_mco import BaseMCO ...@@ -8,10 +8,6 @@ from force_bdss.mco.base_mco import BaseMCO
from force_bdss.notification_listeners.base_notification_listener import \ from force_bdss.notification_listeners.base_notification_listener import \
BaseNotificationListener BaseNotificationListener
from .base_core_driver import BaseCoreDriver from .base_core_driver import BaseCoreDriver
from .io.workflow_reader import (
InvalidVersionException,
InvalidFileException
)
from .core_driver_events import MCOStartEvent, MCOFinishEvent, MCOProgressEvent from .core_driver_events import MCOStartEvent, MCOFinishEvent, MCOProgressEvent
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -40,8 +36,8 @@ class CoreMCODriver(BaseCoreDriver): ...@@ -40,8 +36,8 @@ class CoreMCODriver(BaseCoreDriver):
def _mco_default(self): def _mco_default(self):
try: try:
workflow = self.workflow workflow = self.workflow
except (InvalidVersionException, InvalidFileException) as e: except Exception:
log.exception(e) log.exception("Unable to open workflow file.")
sys.exit(1) sys.exit(1)
mco_model = workflow.mco mco_model = workflow.mco
...@@ -50,7 +46,18 @@ class CoreMCODriver(BaseCoreDriver): ...@@ -50,7 +46,18 @@ class CoreMCODriver(BaseCoreDriver):
sys.exit(0) sys.exit(0)
mco_factory = mco_model.factory mco_factory = mco_model.factory
return mco_factory.create_optimizer() try:
optimizer = mco_factory.create_optimizer()
except Exception:
factory_id = mco_factory.id,
plugin_id = mco_factory.plugin.id
log.exception("Unable to instantiate optimizer for mco '{}' in "
"plugin '{}'. An exception was raised. "
"This might indicate a programming error in the "
"plugin.".format(factory_id, plugin_id))
raise
return optimizer
@on_trait_change("mco:started") @on_trait_change("mco:started")
def _deliver_start_event(self): def _deliver_start_event(self):
...@@ -80,11 +87,13 @@ class CoreMCODriver(BaseCoreDriver): ...@@ -80,11 +87,13 @@ class CoreMCODriver(BaseCoreDriver):
for listener in self.listeners[:]: for listener in self.listeners[:]:
try: try:
listener.deliver(event) listener.deliver(event)
except Exception as e: except Exception:
log.error( log.exception(
"Exception while delivering to listener {}: {}".format( "Exception while delivering to listener "
listener.__class__.__name__, "'{}' in plugin '{}'. The listener will be dropped and "
str(e) "computation will continue.".format(
listener.factory.id,
listener.factory.plugin.id
)) ))
self._finalize_listener(listener) self._finalize_listener(listener)
self.listeners.remove(listener) self.listeners.remove(listener)
...@@ -96,14 +105,30 @@ class CoreMCODriver(BaseCoreDriver): ...@@ -96,14 +105,30 @@ class CoreMCODriver(BaseCoreDriver):
factory = nl_model.factory factory = nl_model.factory
try: try:
listener = factory.create_listener() listener = factory.create_listener()
except Exception:
log.exception(
"Failed to create listener with id '{}' in plugin '{}'. "
"This may indicate a programming error in the "
"plugin.".format(
factory.id,
factory.plugin.id
)
)
raise
try:
listener.initialize(nl_model) listener.initialize(nl_model)
except Exception as e: except Exception:
log.error( log.exception(
"Failed to create or initialize " "Failed to initialize listener with id '{}' in "
"listener with id {}: {}".format( "plugin '{}'. The listener will be dropped.".format(
factory.id, str(e))) factory.id,
else: factory.plugin.id
listeners.append(listener) )
)
continue
listeners.append(listener)
return listeners return listeners
...@@ -114,9 +139,10 @@ class CoreMCODriver(BaseCoreDriver): ...@@ -114,9 +139,10 @@ class CoreMCODriver(BaseCoreDriver):
""" """
try: try:
listener.finalize() listener.finalize()
except Exception as e: except Exception:
log.error( log.exception(
"Exception while finalizing listener {}: {}".format( "Exception while finalizing listener '{}'"
listener.__class__.__name__, " in plugin '{}'.".format(
str(e) listener.factory.id,
listener.factory.plugin.id
)) ))
...@@ -91,9 +91,11 @@ class TestCoreMCODriver(unittest.TestCase): ...@@ -91,9 +91,11 @@ class TestCoreMCODriver(unittest.TestCase):
capture.check( capture.check(
("force_bdss.core_mco_driver", ("force_bdss.core_mco_driver",
"ERROR", "ERROR",
"Failed to create or initialize listener with id " "Failed to initialize listener with id "
"force.bdss.enthought.plugin.test.v0" "'force.bdss.enthought.plugin.test.v0"
".factory.probe_notification_listener: ")) ".factory.probe_notification_listener' in plugin "
"'force.bdss.enthought.plugin.test.v0'. "
"The listener will be dropped."))
self.assertEqual(len(listeners), 0) self.assertEqual(len(listeners), 0)
...@@ -111,7 +113,10 @@ class TestCoreMCODriver(unittest.TestCase): ...@@ -111,7 +113,10 @@ class TestCoreMCODriver(unittest.TestCase):
("force_bdss.core_mco_driver", ("force_bdss.core_mco_driver",
"ERROR", "ERROR",
"Exception while delivering to listener " "Exception while delivering to listener "
"ProbeNotificationListener: ")) "'force.bdss.enthought.plugin.test.v0"
".factory.probe_notification_listener' in plugin "
"'force.bdss.enthought.plugin.test.v0'. The listener will "
"be dropped and computation will continue." ))
def test_finalize_error(self): def test_finalize_error(self):
driver = CoreMCODriver( driver = CoreMCODriver(
...@@ -127,4 +132,6 @@ class TestCoreMCODriver(unittest.TestCase): ...@@ -127,4 +132,6 @@ class TestCoreMCODriver(unittest.TestCase):
("force_bdss.core_mco_driver", ("force_bdss.core_mco_driver",
"ERROR", "ERROR",
"Exception while finalizing listener " "Exception while finalizing listener "
"ProbeNotificationListener: ")) "'force.bdss.enthought.plugin.test.v0"
".factory.probe_notification_listener' in plugin "
"'force.bdss.enthought.plugin.test.v0'."))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment