Made Decision Engine extensible via stevedore
The objective for this is to give the ability to extend the default set of placement algorithms (i.e. strategies) currently available in Watcher using Stevedore. Now, you can add your new strategy as an entry point under the '[watcher_strategies]' section. Change-Id: I4aecf629015e41b0389d07e47220333e50bbbe1a
This commit is contained in:
@@ -26,7 +26,7 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Strategy(object):
|
||||
class BaseStrategy(object):
|
||||
def __init__(self, name=None, description=None):
|
||||
self._name = name
|
||||
self.description = description
|
||||
@@ -40,8 +40,10 @@ class Strategy(object):
|
||||
def execute(self, model):
|
||||
"""Execute a strategy
|
||||
|
||||
:param model:
|
||||
:return:
|
||||
:param model: The name of the strategy to execute (loaded dynamically)
|
||||
:type model: str
|
||||
:return: A computed solution (via a placement algorithm)
|
||||
:rtype: :class:`watcher.decision_engine.api.strategy.solution.Solution`
|
||||
"""
|
||||
|
||||
@property
|
||||
|
||||
@@ -16,53 +16,37 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from oslo_config import cfg
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from oslo_log import log
|
||||
from stevedore import driver
|
||||
from stevedore import ExtensionManager
|
||||
from watcher.decision_engine.strategies.basic_consolidation import \
|
||||
BasicConsolidation
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
|
||||
strategies = {
|
||||
'basic': 'watcher.decision_engine.strategies.'
|
||||
'basic_consolidation::BasicConsolidation'
|
||||
}
|
||||
WATCHER_STRATEGY_OPTS = [
|
||||
cfg.DictOpt('strategies',
|
||||
default=strategies,
|
||||
help='Strategies used for the optimization ')
|
||||
]
|
||||
strategies_opt_group = cfg.OptGroup(
|
||||
name='watcher_strategies',
|
||||
title='Defines strategies available for the optimization')
|
||||
CONF.register_group(strategies_opt_group)
|
||||
CONF.register_opts(WATCHER_STRATEGY_OPTS, strategies_opt_group)
|
||||
|
||||
|
||||
class StrategyLoader(object):
|
||||
|
||||
def __init__(self):
|
||||
'''Stevedor loader
|
||||
default_strategy_cls = BasicConsolidation
|
||||
|
||||
:return:
|
||||
'''
|
||||
|
||||
self.strategies = {
|
||||
None: BasicConsolidation("basic", "Basic offline consolidation"),
|
||||
"basic": BasicConsolidation(
|
||||
"basic",
|
||||
"Basic offline consolidation")
|
||||
}
|
||||
|
||||
def load_driver(self, algo):
|
||||
_algo = driver.DriverManager(
|
||||
def load_strategies(self):
|
||||
extension_manager = ExtensionManager(
|
||||
namespace='watcher_strategies',
|
||||
name=algo,
|
||||
invoke_on_load=True,
|
||||
)
|
||||
return _algo
|
||||
return {ext.name: ext.plugin for ext in extension_manager.extensions}
|
||||
|
||||
def load(self, model):
|
||||
return self.strategies[model]
|
||||
strategy = None
|
||||
try:
|
||||
available_strategies = self.load_strategies()
|
||||
strategy_cls = available_strategies.get(
|
||||
model, self.default_strategy_cls
|
||||
)
|
||||
strategy = strategy_cls()
|
||||
except Exception as exc:
|
||||
LOG.exception(exc)
|
||||
|
||||
return strategy
|
||||
|
||||
@@ -20,7 +20,7 @@ from oslo_log import log
|
||||
|
||||
from watcher.common.exception import ClusterEmpty
|
||||
from watcher.common.exception import ClusteStateNotDefined
|
||||
from watcher.decision_engine.api.strategy.strategy import Strategy
|
||||
from watcher.decision_engine.api.strategy.strategy import BaseStrategy
|
||||
from watcher.decision_engine.api.strategy.strategy import StrategyLevel
|
||||
|
||||
from watcher.decision_engine.framework.meta_actions.hypervisor_state import \
|
||||
@@ -42,8 +42,12 @@ from watcher.metrics_engine.cluster_history.ceilometer import \
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class BasicConsolidation(Strategy):
|
||||
def __init__(self, name=None, description=None):
|
||||
class BasicConsolidation(BaseStrategy):
|
||||
|
||||
DEFAULT_NAME = "basic"
|
||||
DEFAULT_DESCRIPTION = "Basic offline consolidation"
|
||||
|
||||
def __init__(self, name=DEFAULT_NAME, description=DEFAULT_DESCRIPTION):
|
||||
"""Basic offline Consolidation using live migration
|
||||
|
||||
The basic consolidation algorithm has several limitations.
|
||||
@@ -217,6 +221,7 @@ class BasicConsolidation(Strategy):
|
||||
def calculate_weight(self, model, element, total_cores_used,
|
||||
total_disk_used, total_memory_used):
|
||||
"""Calculate weight of every
|
||||
|
||||
:param model:
|
||||
:param element:
|
||||
:param total_cores_used:
|
||||
|
||||
@@ -18,13 +18,20 @@
|
||||
#
|
||||
from oslo_log import log
|
||||
|
||||
from watcher.decision_engine.api.strategy.strategy import Strategy
|
||||
from watcher.decision_engine.api.strategy.strategy import BaseStrategy
|
||||
from watcher.decision_engine.framework.meta_actions.nop import Nop
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class DummyStrategy(Strategy):
|
||||
class DummyStrategy(BaseStrategy):
|
||||
|
||||
DEFAULT_NAME = "dummy"
|
||||
DEFAULT_DESCRIPTION = "Dummy Strategy"
|
||||
|
||||
def __init__(self, name=DEFAULT_NAME, description=DEFAULT_DESCRIPTION):
|
||||
super(DummyStrategy, self).__init__(name, description)
|
||||
|
||||
def execute(self, model):
|
||||
n = Nop()
|
||||
self.solution.add_change_request(n)
|
||||
|
||||
Reference in New Issue
Block a user