diff --git a/doc/source/dev/plugin/cdmc-plugin.rst b/doc/source/dev/plugin/cdmc-plugin.rst index e04286ecb..26e015e2d 100644 --- a/doc/source/dev/plugin/cdmc-plugin.rst +++ b/doc/source/dev/plugin/cdmc-plugin.rst @@ -22,7 +22,7 @@ cluster data model collectors within Watcher. Creating a new plugin ===================== -In order to create a new model, you have to: +In order to create a new cluster data model collector, you have to: - Extend the :py:class:`~.base.BaseClusterDataModelCollector` class. - Implement its :py:meth:`~.BaseClusterDataModelCollector.execute` abstract @@ -65,6 +65,49 @@ This implementation is the most basic one. So in order to get a better understanding on how to implement a more advanced cluster data model collector, have a look at the :py:class:`~.NovaClusterDataModelCollector` class. +Define a custom model +===================== + +As you may have noticed in the above example, we are reusing an existing model +provided by Watcher. However, this model can be easily customized by +implementing a new class that would implement the :py:class:`~.Model` abstract +base class. Here below is simple example on how to proceed in implementing a +custom Model: + +.. code-block:: python + + # Filepath = /thirdparty/dummy.py + # Import path = thirdparty.dummy + + from watcher.decision_engine.model import base as modelbase + from watcher.decision_engine.model.collector import base + + + class MyModel(modelbase.Model): + + def to_string(self): + return 'MyModel' + + + class DummyClusterDataModelCollector(base.BaseClusterDataModelCollector): + + def execute(self): + model = MyModel() + # Do something here... + return model + + @property + def notification_endpoints(self): + return [] + +Here below is the abstract ``Model`` class that every single cluster data model +should implement: + +.. autoclass:: watcher.decision_engine.model.base.Model + :members: + :special-members: __init__ + :noindex: + Define configuration parameters =============================== diff --git a/doc/source/glossary.rst b/doc/source/glossary.rst index 986770e88..9450eb5b4 100644 --- a/doc/source/glossary.rst +++ b/doc/source/glossary.rst @@ -96,8 +96,8 @@ The :ref:`Cluster ` may be divided in one or several .. _cluster_data_model_definition: -Cluster Data Model -================== +Cluster Data Model (CDM) +======================== .. watcher-term:: watcher.decision_engine.model.collector.base @@ -164,7 +164,8 @@ Goal Host Aggregate ============== -Please, read `the official OpenStack definition of a Host Aggregate `_. +Please, read `the official OpenStack definition of a Host Aggregate +`_. .. _instance_definition: diff --git a/watcher/decision_engine/model/base.py b/watcher/decision_engine/model/base.py new file mode 100644 index 000000000..629cd800a --- /dev/null +++ b/watcher/decision_engine/model/base.py @@ -0,0 +1,36 @@ +# -*- encoding: utf-8 -*- +# Copyright (c) 2016 b<>com +# +# Authors: Vincent FRANCOISE +# +# 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. + +""" +This component is in charge of executing the +:ref:`Action Plan ` built by the +:ref:`Watcher Decision Engine `. + +See: :doc:`../architecture` for more details on this component. +""" + +import abc +import six + + +@six.add_metaclass(abc.ABCMeta) +class Model(object): + + @abc.abstractmethod + def to_string(self): + raise NotImplementedError() diff --git a/watcher/decision_engine/model/collector/base.py b/watcher/decision_engine/model/collector/base.py index 28e9f2141..dd696701c 100644 --- a/watcher/decision_engine/model/collector/base.py +++ b/watcher/decision_engine/model/collector/base.py @@ -19,8 +19,8 @@ # """ -A :ref:`Cluster Data Model ` is a logical -representation of the current state and topology of the :ref:`Cluster +A :ref:`Cluster Data Model ` (or CDM) is a +logical representation of the current state and topology of the :ref:`Cluster ` :ref:`Managed resources `. It is represented as a set of :ref:`Managed resources @@ -58,8 +58,11 @@ to know: In the Watcher project, we aim at providing a some generic and basic :ref:`Cluster Data Model ` for each :ref:`Goal `, usable in the associated :ref:`Strategies -` through a plugin-based mechanism that are directly -accessible from the strategies classes in order to: +` through a plugin-based mechanism which are called +cluster data model collectors (or CDMCs). These CDMCs are responsible for +loading and keeping up-to-date their associated CDM by listening to events and +also periodically rebuilding themselves from the ground up. They are also +directly accessible from the strategies classes. These CDMs are used to: - simplify the development of a new :ref:`Strategy ` for a given :ref:`Goal ` when there already are some existing diff --git a/watcher/decision_engine/model/model_root.py b/watcher/decision_engine/model/model_root.py index 054a287ed..3798b91e1 100644 --- a/watcher/decision_engine/model/model_root.py +++ b/watcher/decision_engine/model/model_root.py @@ -22,11 +22,13 @@ import six from watcher._i18n import _ from watcher.common import exception from watcher.common import utils +from watcher.decision_engine.model import base from watcher.decision_engine.model import element from watcher.decision_engine.model import mapping -class ModelRoot(object): +class ModelRoot(base.Model): + def __init__(self, stale=False): self._nodes = utils.Struct() self._instances = utils.Struct()