Tidy up - Watcher Decision Engine package

Some Python class and packages need to be renamed
for a better compliance with the shared terminology
which provides a better understanding of Watcher
objects and components by every contributor.

This patchset is there to change the code structure by adding the folder
"strategies" and "loading".

Partially implements: blueprint glossary-related-refactoring

Change-Id: I56fb24ee6762b3186eccde5983233e17bb227cc1
This commit is contained in:
Jean-Emile DARTOIS
2015-12-10 09:34:38 +01:00
parent 92940ba9e2
commit 62570525ad
30 changed files with 153 additions and 160 deletions

View File

@@ -17,9 +17,9 @@
# limitations under the License.
#
import abc
import six
from watcher.decision_engine.strategy.level import StrategyLevel
import six
from watcher.decision_engine.strategy.common.level import StrategyLevel
@six.add_metaclass(abc.ABCMeta)

View File

@@ -17,7 +17,7 @@ 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.selector.default import StrategySelector
from watcher.decision_engine.strategy.selection.default import StrategySelector
LOG = log.getLogger(__name__)

View File

@@ -0,0 +1,43 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2015 b<>com
#
# Authors: Jean-Emile DARTOIS <jean-emile.dartois@b-com.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import abc
from oslo_log import log
import six
LOG = log.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class BaseStrategyLoader(object):
@abc.abstractmethod
def load_available_strategies(self):
raise NotImplementedError() # pragma:no cover
def load(self, strategy_to_load=None):
strategy_selected = None
try:
available_strategies = self.load_available_strategies()
strategy_cls = available_strategies.get(
strategy_to_load, self.default_strategy_cls
)
strategy_selected = strategy_cls()
except Exception as exc:
LOG.exception(exc)
return strategy_selected

View File

@@ -21,32 +21,21 @@ from __future__ import unicode_literals
from oslo_log import log
from stevedore import ExtensionManager
from watcher.decision_engine.strategy.basic_consolidation import \
from watcher.decision_engine.strategy.loading.base import BaseStrategyLoader
from watcher.decision_engine.strategy.strategies.basic_consolidation import \
BasicConsolidation
LOG = log.getLogger(__name__)
class StrategyLoader(object):
class DefaultStrategyLoader(BaseStrategyLoader):
default_strategy_cls = BasicConsolidation
def load_strategies(self):
def load_available_strategies(self):
extension_manager = ExtensionManager(
namespace='watcher_strategies',
invoke_on_load=True,
)
return {ext.name: ext.plugin for ext in extension_manager.extensions}
def load(self, 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

View File

@@ -16,9 +16,12 @@
from oslo_config import cfg
from oslo_log import log
from watcher.common.exception import WatcherException
from watcher.decision_engine.strategy.loader import StrategyLoader
from watcher.decision_engine.strategy.selector.base import BaseSelector
from watcher.decision_engine.strategy.loading.default import \
DefaultStrategyLoader
from watcher.decision_engine.strategy.selection.base import BaseSelector
LOG = log.getLogger(__name__)
CONF = cfg.CONF
@@ -41,7 +44,7 @@ CONF.register_opts(WATCHER_GOALS_OPTS, goals_opt_group)
class StrategySelector(BaseSelector):
def __init__(self):
self.strategy_loader = StrategyLoader()
self.strategy_loader = DefaultStrategyLoader()
def define_from_goal(self, goal_name):
strategy_to_load = None

View File

@@ -16,12 +16,12 @@
import abc
from oslo_log import log
import six
from watcher.decision_engine.solution.default import DefaultSolution
from watcher.decision_engine.strategy.level import StrategyLevel
from watcher.decision_engine.solution.default import DefaultSolution
from watcher.decision_engine.strategy.common.level import StrategyLevel
LOG = log.getLogger(__name__)

View File

@@ -28,8 +28,8 @@ from watcher.decision_engine.model.hypervisor_state import HypervisorState
from watcher.decision_engine.model.power_state import PowerState
from watcher.decision_engine.model.resource import ResourceType
from watcher.decision_engine.model.vm_state import VMState
from watcher.decision_engine.strategy.base import BaseStrategy
from watcher.decision_engine.strategy.level import StrategyLevel
from watcher.decision_engine.strategy.common.level import StrategyLevel
from watcher.decision_engine.strategy.strategies.base import BaseStrategy
from watcher.metrics_engine.cluster_history.ceilometer import \
CeilometerClusterHistory
@@ -53,12 +53,12 @@ class BasicConsolidation(BaseStrategy):
and often tend to migrate from one physical machine to another.
Hence, the traditional and offline heuristics such as bin packing
are not applicable for the placement VM in cloud computing.
So, the decision Engine optimizer provide placement strategy considering
So, the decision Engine optimizer provides placement strategy considering
not only the performance effects but also the workload characteristics of
VMs and others metrics like the power consumption and
the tenants constraints (SLAs).
The watcher optimizer use an online VM placement technique
The watcher optimizer uses an online VM placement technique
based on machine learning and meta-heuristics that must handle :
- multi-objectives
- Contradictory objectives
@@ -121,9 +121,9 @@ class BasicConsolidation(BaseStrategy):
vm_to_mig):
'''check if the migration is possible
:param model: current state of the cluster
:param src_hypervisor: the current of the virtual machine
:param dest_hypervisor:the destination of the virtual machine
:param model: the current state of the cluster
:param src_hypervisor: the current node of the virtual machine
:param dest_hypervisor: the destination of the virtual machine
:param vm_to_mig: the virtual machine
:return: True if the there is enough place otherwise false
'''
@@ -167,7 +167,7 @@ class BasicConsolidation(BaseStrategy):
"""Check threshold
check the threshold value defined by the ratio of
aggregated CPU capacity of VMS on one node to CPU capacity
aggregated CPU capacity of VMs on one node to CPU capacity
of this node must not exceed the threshold value.
:param dest_hypervisor:
:param total_cores
@@ -213,7 +213,7 @@ class BasicConsolidation(BaseStrategy):
def calculate_weight(self, model, element, total_cores_used,
total_disk_used, total_memory_used):
"""Calculate weight of every
"""Calculate weight of every resource
:param model:
:param element:
@@ -248,7 +248,7 @@ class BasicConsolidation(BaseStrategy):
return (score_cores + score_disk + score_memory) / 3
def calculate_score_node(self, hypervisor, model):
"""calculate the score that reprensent the utilization level
"""calculate the score that represent the utilization level
:param hypervisor:
:param model:
@@ -331,7 +331,7 @@ class BasicConsolidation(BaseStrategy):
model)))
def execute(self, orign_model):
LOG.debug("initialize Sercon Consolidation")
LOG.debug("Initialize Sercon Consolidation")
if orign_model is None:
raise ClusterStateNotDefined()
@@ -411,7 +411,7 @@ class BasicConsolidation(BaseStrategy):
vm_score.append(
(vm_id, self.calculate_score_vm(vm, current_model)))
''' sort VM's by Score '''
''' sort VMs by Score '''
v = sorted(vm_score, reverse=True, key=lambda x: (x[1]))
LOG.debug("VM(s) BFD {0}".format(v))

View File

@@ -17,9 +17,9 @@
# limitations under the License.
#
from oslo_log import log
from watcher.decision_engine.strategy.strategies.base import BaseStrategy
from watcher.decision_engine.actions.nop import Nop
from watcher.decision_engine.strategy.base import BaseStrategy
LOG = log.getLogger(__name__)