Code refactoring - StrategyContext and Auditendpoint
This patchset aim to remove useless code in StrategyContext and AuditEndPoint. This patchset also add a parameter for strategy context to define the numbers of thread of execute the strategies. DocImpact Change-Id: I83e87165b03b42fe6b863921502a300bd94d2982
This commit is contained in:
@@ -23,5 +23,5 @@ import six
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class BaseStrategyContext(object):
|
||||
@abc.abstractmethod
|
||||
def execute_strategy(self, model):
|
||||
def execute_strategy(self, goal, cluster_data_model):
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -15,34 +15,23 @@
|
||||
# limitations under the License.
|
||||
from oslo_log import log
|
||||
|
||||
from watcher.decision_engine.planner.default import DefaultPlanner
|
||||
from watcher.decision_engine.strategy.context.base import BaseStrategyContext
|
||||
from watcher.decision_engine.strategy.selection.default import StrategySelector
|
||||
from watcher.decision_engine.strategy.selection.default import \
|
||||
DefaultStrategySelector
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class StrategyContext(BaseStrategyContext):
|
||||
def __init__(self, broker=None):
|
||||
LOG.debug("Initializing decision_engine Engine API ")
|
||||
self.strategies = {}
|
||||
self.selected_strategies = []
|
||||
self.broker = broker
|
||||
self.planner = DefaultPlanner()
|
||||
self.strategy_selector = StrategySelector()
|
||||
self.goal = None
|
||||
class DefaultStrategyContext(BaseStrategyContext):
|
||||
def __init__(self):
|
||||
super(DefaultStrategyContext, self).__init__()
|
||||
LOG.debug("Initializing Strategy Context")
|
||||
self._strategy_selector = DefaultStrategySelector()
|
||||
|
||||
def add_strategy(self, strategy):
|
||||
self.strategies[strategy.name] = strategy
|
||||
self.selected_strategy = strategy.name
|
||||
@property
|
||||
def strategy_selector(self):
|
||||
return self._strategy_selector
|
||||
|
||||
def remove_strategy(self, strategy):
|
||||
pass
|
||||
|
||||
def set_goal(self, goal):
|
||||
self.goal = goal
|
||||
|
||||
def execute_strategy(self, model):
|
||||
# todo(jed) create thread + refactoring
|
||||
selected_strategy = self.strategy_selector.define_from_goal(self.goal)
|
||||
return selected_strategy.execute(model)
|
||||
def execute_strategy(self, goal, cluster_data_model):
|
||||
selected_strategy = self.strategy_selector.define_from_goal(goal)
|
||||
return selected_strategy.execute(cluster_data_model)
|
||||
|
||||
@@ -41,9 +41,10 @@ CONF.register_group(goals_opt_group)
|
||||
CONF.register_opts(WATCHER_GOALS_OPTS, goals_opt_group)
|
||||
|
||||
|
||||
class StrategySelector(BaseSelector):
|
||||
class DefaultStrategySelector(BaseSelector):
|
||||
|
||||
def __init__(self):
|
||||
super(DefaultStrategySelector, self).__init__()
|
||||
self.strategy_loader = DefaultStrategyLoader()
|
||||
|
||||
def define_from_goal(self, goal_name):
|
||||
|
||||
Reference in New Issue
Block a user