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

Separates bundle registry from the rest of the app

parent 5704237c
No related branches found
No related tags found
1 merge request!22Extracts registry from application plugin.
from envisage.extension_point import ExtensionPoint
from envisage.plugin import Plugin from envisage.plugin import Plugin
from traits.api import List from traits.trait_types import Instance
from force_bdss.data_sources.i_data_source_bundle import ( from force_bdss.bundle_registry import (
IDataSourceBundle) BundleRegistryPlugin,
from force_bdss.kpi.i_kpi_calculator_bundle import IKPICalculatorBundle BUNDLE_REGISTRY_PLUGIN_ID
from force_bdss.mco.i_multi_criteria_optimizer_bundle import ( )
IMultiCriteriaOptimizerBundle)
class BaseCoreDriver(Plugin): class BaseCoreDriver(Plugin):
...@@ -14,50 +12,7 @@ class BaseCoreDriver(Plugin): ...@@ -14,50 +12,7 @@ class BaseCoreDriver(Plugin):
or the evaluation. or the evaluation.
""" """
# Note: we are forced to declare these extensions points here instead bundle_registry = Instance(BundleRegistryPlugin)
# of the application object, and this is why we have to use this plugin.
# It is a workaround to an envisage bug that does not find the extension
# points if declared on the application.
#: A List of the available Multi Criteria Optimizers. def _bundle_registry_default(self):
#: This will be populated by MCO plugins. return self.application.get_plugin(BUNDLE_REGISTRY_PLUGIN_ID)
mco_bundles = ExtensionPoint(
List(IMultiCriteriaOptimizerBundle),
id='force.bdss.mco.bundles')
#: A list of the available Data Sources.
#: It will be populated by plugins.
data_source_bundles = ExtensionPoint(
List(IDataSourceBundle),
id='force.bdss.data_sources.bundles')
#: A list of the available Key Performance Indicator calculators.
#: It will be populated by plugins.
kpi_calculator_bundles = ExtensionPoint(
List(IKPICalculatorBundle),
id='force.bdss.kpi_calculators.bundles')
def _data_source_bundle_by_id(self, id):
for ds in self.data_source_bundles:
if ds.id == id:
return ds
raise Exception("Requested data source {} but don't know "
"to find it.".format(id))
def _kpi_calculator_bundle_by_id(self, id):
for kpic in self.kpi_calculator_bundles:
if kpic.id == id:
return kpic
raise Exception(
"Requested kpi calculator {} but don't know "
"to find it.".format(id))
def _mco_bundle_by_id(self, id):
for mco in self.mco_bundles:
if mco.id == id:
return mco
raise Exception("Requested MCO {} but it's not available"
"to compute it.".format(id))
...@@ -5,6 +5,7 @@ from stevedore.exception import NoMatches ...@@ -5,6 +5,7 @@ from stevedore.exception import NoMatches
from envisage.api import Application from envisage.api import Application
from envisage.core_plugin import CorePlugin from envisage.core_plugin import CorePlugin
from force_bdss.bundle_registry import BundleRegistryPlugin
from force_bdss.core_evaluation_driver import CoreEvaluationDriver from force_bdss.core_evaluation_driver import CoreEvaluationDriver
from force_bdss.core_mco_driver import CoreMCODriver from force_bdss.core_mco_driver import CoreMCODriver
...@@ -33,7 +34,7 @@ class BDSSApplication(Application): ...@@ -33,7 +34,7 @@ class BDSSApplication(Application):
self.evaluate = evaluate self.evaluate = evaluate
self.workflow_filepath = workflow_filepath self.workflow_filepath = workflow_filepath
plugins = [CorePlugin()] plugins = [CorePlugin(), BundleRegistryPlugin()]
if self.evaluate: if self.evaluate:
plugins.append(CoreEvaluationDriver()) plugins.append(CoreEvaluationDriver())
......
from envisage.extension_point import ExtensionPoint
from envisage.plugin import Plugin
from traits.api import List
from force_bdss.data_sources.i_data_source_bundle import (
IDataSourceBundle)
from force_bdss.kpi.i_kpi_calculator_bundle import IKPICalculatorBundle
from force_bdss.mco.i_multi_criteria_optimizer_bundle import (
IMultiCriteriaOptimizerBundle)
BUNDLE_REGISTRY_PLUGIN_ID = "force.bdss.plugins.bundle_registry"
class BundleRegistryPlugin(Plugin):
"""Main plugin that handles the execution of the MCO
or the evaluation.
"""
id = BUNDLE_REGISTRY_PLUGIN_ID
# Note: we are forced to declare these extensions points here instead
# of the application object, and this is why we have to use this plugin.
# It is a workaround to an envisage bug that does not find the extension
# points if declared on the application.
#: A List of the available Multi Criteria Optimizers.
#: This will be populated by MCO plugins.
mco_bundles = ExtensionPoint(
List(IMultiCriteriaOptimizerBundle),
id='force.bdss.mco.bundles')
#: A list of the available Data Sources.
#: It will be populated by plugins.
data_source_bundles = ExtensionPoint(
List(IDataSourceBundle),
id='force.bdss.data_sources.bundles')
#: A list of the available Key Performance Indicator calculators.
#: It will be populated by plugins.
kpi_calculator_bundles = ExtensionPoint(
List(IKPICalculatorBundle),
id='force.bdss.kpi_calculators.bundles')
def data_source_bundle_by_id(self, id):
for ds in self.data_source_bundles:
if ds.id == id:
return ds
raise Exception("Requested data source {} but don't know "
"to find it.".format(id))
def kpi_calculator_bundle_by_id(self, id):
for kpic in self.kpi_calculator_bundles:
if kpic.id == id:
return kpic
raise Exception(
"Requested kpi calculator {} but don't know "
"to find it.".format(id))
def mco_bundle_by_id(self, id):
for mco in self.mco_bundles:
if mco.id == id:
return mco
raise Exception("Requested MCO {} but it's not available"
"to compute it.".format(id))
...@@ -13,7 +13,7 @@ class CoreEvaluationDriver(BaseCoreDriver): ...@@ -13,7 +13,7 @@ class CoreEvaluationDriver(BaseCoreDriver):
workflow = self.application.workflow workflow = self.application.workflow
mco_data = workflow.multi_criteria_optimizer mco_data = workflow.multi_criteria_optimizer
mco_bundle = self._mco_bundle_by_id(mco_data.id) mco_bundle = self.bundle_registry.mco_bundle_by_id(mco_data.id)
mco_model = mco_bundle.create_model(mco_data.model_data) mco_model = mco_bundle.create_model(mco_data.model_data)
mco_communicator = mco_bundle.create_communicator( mco_communicator = mco_bundle.create_communicator(
self.application, self.application,
...@@ -23,7 +23,7 @@ class CoreEvaluationDriver(BaseCoreDriver): ...@@ -23,7 +23,7 @@ class CoreEvaluationDriver(BaseCoreDriver):
ds_results = [] ds_results = []
for requested_ds in workflow.data_sources: for requested_ds in workflow.data_sources:
ds_bundle = self._data_source_bundle_by_id( ds_bundle = self.bundle_registry.data_source_bundle_by_id(
requested_ds.id) requested_ds.id)
ds_model = ds_bundle.create_model(requested_ds.model_data) ds_model = ds_bundle.create_model(requested_ds.model_data)
data_source = ds_bundle.create_data_source( data_source = ds_bundle.create_data_source(
...@@ -32,7 +32,7 @@ class CoreEvaluationDriver(BaseCoreDriver): ...@@ -32,7 +32,7 @@ class CoreEvaluationDriver(BaseCoreDriver):
kpi_results = [] kpi_results = []
for requested_kpic in workflow.kpi_calculators: for requested_kpic in workflow.kpi_calculators:
kpic_bundle = self._kpi_calculator_bundle_by_id( kpic_bundle = self.bundle_registry.kpi_calculator_bundle_by_id(
requested_kpic.id) requested_kpic.id)
ds_model = kpic_bundle.create_model( ds_model = kpic_bundle.create_model(
requested_kpic.model_data) requested_kpic.model_data)
......
...@@ -13,7 +13,7 @@ class CoreMCODriver(BaseCoreDriver): ...@@ -13,7 +13,7 @@ class CoreMCODriver(BaseCoreDriver):
workflow = self.application.workflow workflow = self.application.workflow
mco_data = workflow.multi_criteria_optimizer mco_data = workflow.multi_criteria_optimizer
mco_bundle = self._mco_bundle_by_id(mco_data.id) mco_bundle = self.bundle_registry.mco_bundle_by_id(mco_data.id)
mco_model = mco_bundle.create_model(mco_data.model_data) mco_model = mco_bundle.create_model(mco_data.model_data)
mco = mco_bundle.create_optimizer(self.application, mco_model) mco = mco_bundle.create_optimizer(self.application, mco_model)
......
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