Commit ecdf8b29 authored by Jérome Perrin's avatar Jérome Perrin

Platform: simplify plugin registry

parent 10ad9717
......@@ -133,26 +133,13 @@ def runSimulation():
def _runSimulation(parameter_dict):
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:
tb = traceback.format_exc()
app.logger.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"])
def runKnowledgeExtraction():
parameter_dict = request.json
......
......@@ -21,8 +21,9 @@ def getConfigurationDict(self):
class Plugin(object):
"""Base class for pre-post processing Plugin.
"""
def __init__(self, logger=None):
def __init__(self, logger, configuration_dict):
self.logger = logger
self.configuration_dict = configuration_dict
class ExecutionPlugin(Plugin):
"""Plugin to handle the execution of multiple simulation runs.
......@@ -64,25 +65,28 @@ class DefaultExecutionPlugin(ExecutionPlugin):
class PluginRegistry(object):
"""Registry of plugins.
"""
def __init__(self, logger,
input_preparation_class_list,
output_preparation_class_list,
execution_plugin_class):
self.input_preparation_list = tuple([resolve(name)(logger) for name in
input_preparation_class_list])
self.output_preparation_list = tuple([resolve(name)(logger) for name in
output_preparation_class_list])
self.execution_plugin = resolve(execution_plugin_class)(logger)
def __init__(self, logger, data):
self.input_preparation_list = []
for plugin_data in data['application_configuration']['pre_processing_plugin_list']:
self.input_preparation_list.append(resolve(plugin_data['_class'])(logger, plugin_data))
self.output_preparation_list = []
for plugin_data in data['application_configuration']['post_processing_plugin_list']:
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):
"""Preprocess, execute & postprocess.
"""
for input_preparation in self.input_preparation_list:
data = input_preparation.preprocess(deepcopy(data))
data = self.execution_plugin.run(data)
for output_preparation in self.output_preparation_list:
data = output_preparation.postprocess(deepcopy(data))
return data
\ No newline at end of file
return data
......@@ -785,24 +785,20 @@
"gadget": "Output_viewDebugJson"
}
},
"preprocessing_plugin_list": [
{
"plugin": "dream.plugins.Debug.Debug",
"argument": "Argument Value"
},
{
"plugin": "dream.plugins.OldStylePartJobShopWIP.OldStylePartJobShopWIP",
"input_id": "Simulation"
}
],
"processing_plugin": {
"plugin": "ACO"
},
"postprocessing_plugin_list": [
"pre_processing_plugin_list": [
{
"_class": "dream.plugins.Debug.Debug",
"argument": "Argument Value"
},
{
"plugin": "CalculateConfidenceIntervals"
"_class": "dream.plugins.OldStylePartJobShopWIP.OldStylePartJobShopWIP",
"input_id": "Simulation"
}
],
"processing_plugin": {
"_class": "dream.plugins.ACO.ACO"
},
"post_processing_plugin_list": [],
"general": {
"properties": {
"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