Merge scoring base files

Merge scoring_engine.py and scoring_container.py to base.py

Change-Id: I5cada2c9f7832827c1bccfdea1b0a2138b18bfc9
Closes-Bug: #1617376
This commit is contained in:
Alexandr Stavitskiy
2016-08-29 12:38:03 +03:00
parent 3ed44383ab
commit 6e8dc5297e
4 changed files with 34 additions and 57 deletions

View File

@@ -95,3 +95,32 @@ class ScoringEngine(loadable.Loadable):
:rtype: list of :class:`oslo_config.cfg.Opt` instances :rtype: list of :class:`oslo_config.cfg.Opt` instances
""" """
return [] return []
@six.add_metaclass(abc.ABCMeta)
class ScoringEngineContainer(loadable.Loadable):
"""A base class for all the Scoring Engines Containers.
A Scoring Engine Container is an abstraction which allows to plugin
multiple Scoring Engines as a single Stevedore plugin. This enables some
more advanced scenarios like dynamic reloading of Scoring Engine
implementations without having to restart any Watcher services.
"""
@classmethod
@abc.abstractmethod
def get_scoring_engine_list(self):
"""Returns a list of Scoring Engine instances.
:return: A list of Scoring Engine instances
:rtype: :class: `~.scoring_engine.ScoringEngine`
"""
@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

@@ -22,12 +22,12 @@ from oslo_serialization import jsonutils
from oslo_utils import units from oslo_utils import units
from watcher._i18n import _ from watcher._i18n import _
from watcher.decision_engine.scoring import scoring_engine from watcher.decision_engine.scoring import base
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
class DummyScorer(scoring_engine.ScoringEngine): class DummyScorer(base.ScoringEngine):
"""Sample Scoring Engine implementing simplified workload classification. """Sample Scoring Engine implementing simplified workload classification.
Typically a scoring engine would be implemented using machine learning Typically a scoring engine would be implemented using machine learning

View File

@@ -21,13 +21,12 @@ from oslo_log import log
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from watcher._i18n import _ from watcher._i18n import _
from watcher.decision_engine.scoring import scoring_container from watcher.decision_engine.scoring import base
from watcher.decision_engine.scoring import scoring_engine
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
class DummyScoringContainer(scoring_container.ScoringEngineContainer): class DummyScoringContainer(base.ScoringEngineContainer):
"""Sample Scoring Engine container returning a list of scoring engines. """Sample Scoring Engine container returning a list of scoring engines.
Please note that it can be used in dynamic scenarios and the returned list Please note that it can be used in dynamic scenarios and the returned list
@@ -55,7 +54,7 @@ class DummyScoringContainer(scoring_container.ScoringEngineContainer):
] ]
class SimpleFunctionScorer(scoring_engine.ScoringEngine): class SimpleFunctionScorer(base.ScoringEngine):
"""A simple generic scoring engine for demonstration purposes only. """A simple generic scoring engine for demonstration purposes only.
A generic scoring engine implementation, which is expecting a JSON A generic scoring engine implementation, which is expecting a JSON

View File

@@ -1,51 +0,0 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2016 Intel
#
# Authors: Tomasz Kaczynski <tomasz.kaczynski@intel.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 watcher.common.loader import loadable
@six.add_metaclass(abc.ABCMeta)
class ScoringEngineContainer(loadable.Loadable):
"""A base class for all the Scoring Engines Containers.
A Scoring Engine Container is an abstraction which allows to plugin
multiple Scoring Engines as a single Stevedore plugin. This enables some
more advanced scenarios like dynamic reloading of Scoring Engine
implementations without having to restart any Watcher services.
"""
@classmethod
@abc.abstractmethod
def get_scoring_engine_list(self):
"""Returns a list of Scoring Engine instances.
:return: A list of Scoring Engine instances
:rtype: :class: `~.scoring_engine.ScoringEngine`
"""
@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 []