Commit 303a970b authored by Jérome Perrin's avatar Jérome Perrin

Platform: simplify plugin registry

parent 893371a8
...@@ -133,26 +133,13 @@ def runSimulation(): ...@@ -133,26 +133,13 @@ def runSimulation():
def _runSimulation(parameter_dict): def _runSimulation(parameter_dict):
try: try:
return dict(success=True, data=getPluginRestistry(parameter_dict).run(parameter_dict)) registry = PluginRegistry(app.logger, parameter_dict)
return dict(success=True, data=registry.run(parameter_dict))
except Exception, e: except Exception, e:
tb = traceback.format_exc() tb = traceback.format_exc()
app.logger.error(tb) app.logger.error(tb)
return dict(error=tb) return dict(error=tb)
def getPluginRestistry(data):
# input plugins
input_plugin_list = data["application_configuration"]["preprocessing_plugin_list"]
# output plugins
output_plugin_list = data["application_configuration"]["postprocessing_plugin_list"]
# executor plugin
executor_name = data["application_configuration"]["processing_plugin"] # XXX default value ?
# remove the executor plugin from the input plugins list
registry = PluginRegistry(logger=app.logger,
input_preparation_class_list=input_plugin_list,
output_preparation_class_list=output_plugin_list,
execution_plugin_class=executor_name)
return registry
@app.route("/runKnowledgeExtraction", methods=["POST", "OPTIONS"]) @app.route("/runKnowledgeExtraction", methods=["POST", "OPTIONS"])
def runKnowledgeExtraction(): def runKnowledgeExtraction():
parameter_dict = request.json parameter_dict = request.json
......
...@@ -21,8 +21,9 @@ def getConfigurationDict(self): ...@@ -21,8 +21,9 @@ def getConfigurationDict(self):
class Plugin(object): class Plugin(object):
"""Base class for pre-post processing Plugin. """Base class for pre-post processing Plugin.
""" """
def __init__(self, logger=None): def __init__(self, logger, configuration_dict):
self.logger = logger self.logger = logger
self.configuration_dict = configuration_dict
class ExecutionPlugin(Plugin): class ExecutionPlugin(Plugin):
"""Plugin to handle the execution of multiple simulation runs. """Plugin to handle the execution of multiple simulation runs.
...@@ -64,25 +65,28 @@ class DefaultExecutionPlugin(ExecutionPlugin): ...@@ -64,25 +65,28 @@ class DefaultExecutionPlugin(ExecutionPlugin):
class PluginRegistry(object): class PluginRegistry(object):
"""Registry of plugins. """Registry of plugins.
""" """
def __init__(self, logger, def __init__(self, logger, data):
input_preparation_class_list,
output_preparation_class_list, self.input_preparation_list = []
execution_plugin_class): for plugin_data in data['application_configuration']['pre_processing_plugin_list']:
self.input_preparation_list = tuple([resolve(name)(logger) for name in self.input_preparation_list.append(resolve(plugin_data['_class'])(logger, plugin_data))
input_preparation_class_list])
self.output_preparation_list = tuple([resolve(name)(logger) for name in self.output_preparation_list = []
output_preparation_class_list]) for plugin_data in data['application_configuration']['post_processing_plugin_list']:
self.execution_plugin = resolve(execution_plugin_class)(logger) self.output_preparation_list.append(resolve(plugin_data['_class'])(logger, plugin_data))
plugin_data = data['application_configuration']['processing_plugin']
self.execution_plugin = resolve(plugin_data['_class'])(logger, plugin_data)
def run(self, data): def run(self, data):
"""Preprocess, execute & postprocess. """Preprocess, execute & postprocess.
""" """
for input_preparation in self.input_preparation_list: for input_preparation in self.input_preparation_list:
data = input_preparation.preprocess(deepcopy(data)) data = input_preparation.preprocess(deepcopy(data))
data = self.execution_plugin.run(data) data = self.execution_plugin.run(data)
for output_preparation in self.output_preparation_list: for output_preparation in self.output_preparation_list:
data = output_preparation.postprocess(deepcopy(data)) data = output_preparation.postprocess(deepcopy(data))
return data return data
\ No newline at end of file
...@@ -785,24 +785,20 @@ ...@@ -785,24 +785,20 @@
"gadget": "Output_viewDebugJson" "gadget": "Output_viewDebugJson"
} }
}, },
"preprocessing_plugin_list": [ "pre_processing_plugin_list": [
{ {
"plugin": "dream.plugins.Debug.Debug", "_class": "dream.plugins.Debug.Debug",
"argument": "Argument Value" "argument": "Argument Value"
}, },
{
"plugin": "dream.plugins.OldStylePartJobShopWIP.OldStylePartJobShopWIP",
"input_id": "Simulation"
}
],
"processing_plugin": {
"plugin": "ACO"
},
"postprocessing_plugin_list": [
{ {
"plugin": "CalculateConfidenceIntervals" "_class": "dream.plugins.OldStylePartJobShopWIP.OldStylePartJobShopWIP",
"input_id": "Simulation"
} }
], ],
"processing_plugin": {
"_class": "dream.plugins.ACO.ACO"
},
"post_processing_plugin_list": [],
"general": { "general": {
"properties": { "properties": {
"numberOfReplications": { "numberOfReplications": {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment