Decoupled Goal from Strategy

In this changeset, I decoupled the notion of Goal from the Strategy
by making it a distinct object. Goals are plugins that can be loaded
just like for the strategies.

Partially Implements: blueprint efficacy-indicator

Change-Id: I4378dccd508170b305aa968843228bbc8af78895
This commit is contained in:
Vincent Françoise
2016-04-18 16:31:35 +02:00
parent 2412df4b6c
commit 2544327979
27 changed files with 483 additions and 165 deletions

View File

@@ -0,0 +1,26 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2016 b<>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.
from watcher.decision_engine.goal import goals
Dummy = goals.Dummy
ServerConsolidation = goals.ServerConsolidation
ThermalOptimization = goals.ThermalOptimization
Unclassified = goals.Unclassified
WorkloadBalancing = goals.WorkloadBalancing
__all__ = ("Dummy", "ServerConsolidation", "ThermalOptimization",
"Unclassified", "WorkloadBalancing", )

View File

@@ -0,0 +1,62 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2016 b<>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
import six
from oslo_log import log
from watcher.common.loader import loadable
LOG = log.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class Goal(loadable.Loadable):
def __init__(self, config):
super(Goal, self).__init__(config)
self.name = self.get_name()
self.display_name = self.get_display_name()
@classmethod
@abc.abstractmethod
def get_name(cls):
"""Name of the goal: should be identical to the related entry point"""
raise NotImplementedError()
@classmethod
@abc.abstractmethod
def get_display_name(cls):
"""The goal display name for the goal"""
raise NotImplementedError()
@classmethod
@abc.abstractmethod
def get_translatable_display_name(cls):
"""The translatable msgid of the goal"""
# Note(v-francoise): Defined here to be used as the translation key for
# other services
raise NotImplementedError()
@classmethod
def get_config_opts(cls):
"""Defines the configuration options to be associated to this loadable
:return: A list of configuration options relative to this Loadable
:rtype: list of :class:`oslo_config.cfg.Opt` instances
"""
return []

View File

@@ -0,0 +1,93 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2016 b<>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.
from watcher._i18n import _
from watcher.decision_engine.goal import base
class Dummy(base.Goal):
@classmethod
def get_name(cls):
return "dummy"
@classmethod
def get_display_name(cls):
return _("Dummy goal")
@classmethod
def get_translatable_display_name(cls):
return "Dummy goal"
class Unclassified(base.Goal):
@classmethod
def get_name(cls):
return "unclassified"
@classmethod
def get_display_name(cls):
return _("Unclassified")
@classmethod
def get_translatable_display_name(cls):
return "Unclassified"
class ServerConsolidation(base.Goal):
@classmethod
def get_name(cls):
return "server_consolidation"
@classmethod
def get_display_name(cls):
return _("Server consolidation")
@classmethod
def get_translatable_display_name(cls):
return "Server consolidation"
class ThermalOptimization(base.Goal):
@classmethod
def get_name(cls):
return "thermal_optimization"
@classmethod
def get_display_name(cls):
return _("Thermal optimization")
@classmethod
def get_translatable_display_name(cls):
return "Thermal optimization"
class WorkloadBalancing(base.Goal):
@classmethod
def get_name(cls):
return "workload_balancing"
@classmethod
def get_display_name(cls):
return _("Workload balancing")
@classmethod
def get_translatable_display_name(cls):
return "Workload balancing"