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

Savepoint. Moving to granta plugin

parent a31a6a1d
No related branches found
No related tags found
1 merge request!137Communicative workflow reader
This commit is part of merge request !137. Comments created here will be created in the context of that merge request.
...@@ -9,20 +9,34 @@ from force_bdss.core.output_slot_info import OutputSlotInfo ...@@ -9,20 +9,34 @@ from force_bdss.core.output_slot_info import OutputSlotInfo
from force_bdss.core.workflow import Workflow from force_bdss.core.workflow import Workflow
from ..factory_registry_plugin import IFactoryRegistryPlugin from ..factory_registry_plugin import IFactoryRegistryPlugin
log = logging.getLogger(__name__) logger = logging.getLogger(__name__)
SUPPORTED_FILE_VERSIONS = ["1"] SUPPORTED_FILE_VERSIONS = ["1"]
class InvalidFileException(Exception): class BaseWorkflowReaderException(Exception):
"""Raised if the file is invalid for some reason""" """Base exception for the reader errors."""
class InvalidVersionException(InvalidFileException): class InvalidFileException(BaseWorkflowReaderException):
"""Raised for a generic file being invalid for some
reason, e.g. incorrect format or missing keys.
"""
class InvalidVersionException(BaseWorkflowReaderException):
"""Raised if the version tag does not satisfy the currently """Raised if the version tag does not satisfy the currently
supported list.""" supported list."""
class MissingPluginException(BaseWorkflowReaderException):
"""Raised if the file requires a plugin we cannot find."""
class ModelInstantiationFailedException(BaseWorkflowReaderException):
"""Raised if we can't instantiate the model from a plugin"""
class WorkflowReader(HasStrictTraits): class WorkflowReader(HasStrictTraits):
""" """
Reads the workflow from a file. Reads the workflow from a file.
...@@ -73,12 +87,12 @@ class WorkflowReader(HasStrictTraits): ...@@ -73,12 +87,12 @@ class WorkflowReader(HasStrictTraits):
try: try:
version = json_data["version"] version = json_data["version"]
except KeyError: except KeyError:
log.error("File missing version information") logger.error("File missing version information")
raise InvalidFileException("Corrupted input file, no version" raise InvalidFileException("Corrupted input file, no version"
" specified") " specified")
if version not in SUPPORTED_FILE_VERSIONS: if version not in SUPPORTED_FILE_VERSIONS:
log.error( logger.error(
"File contains version {} that is not in the " "File contains version {} that is not in the "
"list of supported versions {}".format( "list of supported versions {}".format(
version, SUPPORTED_FILE_VERSIONS) version, SUPPORTED_FILE_VERSIONS)
...@@ -95,12 +109,12 @@ class WorkflowReader(HasStrictTraits): ...@@ -95,12 +109,12 @@ class WorkflowReader(HasStrictTraits):
wf.notification_listeners[:] = \ wf.notification_listeners[:] = \
self._extract_notification_listeners(wf_data) self._extract_notification_listeners(wf_data)
except KeyError as e: except KeyError as e:
log.error("Could not read file {}".format(file), exc_info=True) logger.exception("Could not read file {}".format(file))
raise InvalidFileException( raise InvalidFileException(
"Could not read file {}. " "Could not read file. "
"Unable to find key {}." "Unable to find key {}."
"The plugin responsible for the missing " "It might be corrupted or unsupported."
"key may be missing or broken.".format(file, e) "key may be missing or broken.".format(e)
) )
return wf return wf
...@@ -127,13 +141,25 @@ class WorkflowReader(HasStrictTraits): ...@@ -127,13 +141,25 @@ class WorkflowReader(HasStrictTraits):
return None return None
mco_id = mco_data["id"] mco_id = mco_data["id"]
mco_factory = registry.mco_factory_by_id(mco_id) try:
mco_factory = registry.mco_factory_by_id(mco_id)
except KeyError:
raise MissingPluginException(
"Could not read file. "
"The plugin responsible for the missing "
"key '{}' may be missing or broken.".format(mco_id)
)
model_data = wf_data["mco"]["model_data"] model_data = wf_data["mco"]["model_data"]
model_data["parameters"] = self._extract_mco_parameters( model_data["parameters"] = self._extract_mco_parameters(
mco_id, mco_id,
model_data["parameters"]) model_data["parameters"])
model = mco_factory.create_model(
wf_data["mco"]["model_data"]) try:
model = mco_factory.create_model(model_data)
except Exception as e:
logger.exception("Unable to create model for MCO {}".format(mco_id))
raise ModelInstantiationFailedException(
"Unable to create model for MCO {}: {}".format(mco_id, e))
return model return model
def _extract_execution_layers(self, wf_data): def _extract_execution_layers(self, wf_data):
......
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