Coverage for watcher/decision_engine/solution/base.py: 100%
22 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2015 b<>com
3#
4# Authors: Jean-Emile DARTOIS <jean-emile.dartois@b-com.com>
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15# implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
20"""
21A :ref:`Solution <solution_definition>` is the result of execution of a
22:ref:`strategy <strategy_definition>` (i.e., an algorithm).
23Each solution is composed of many pieces of information:
25- A set of :ref:`actions <action_definition>` generated by the strategy in
26 order to achieve the :ref:`goal <goal_definition>` of an associated
27 :ref:`audit <audit_definition>`.
28- A set of :ref:`efficacy indicators <efficacy_indicator_definition>` as
29 defined by the associated goal
30- A :ref:`global efficacy <efficacy_definition>` which is computed by the
31 associated goal using the aforementioned efficacy indicators.
33A :ref:`Solution <solution_definition>` is different from an
34:ref:`Action Plan <action_plan_definition>` because it contains the
35non-scheduled list of :ref:`Actions <action_definition>` which is produced by a
36:ref:`Strategy <strategy_definition>`. In other words, the list of Actions in
37a :ref:`Solution <solution_definition>` has not yet been re-ordered by the
38:ref:`Watcher Planner <watcher_planner_definition>`.
40Note that some algorithms (i.e. :ref:`Strategies <strategy_definition>`) may
41generate several :ref:`Solutions <solution_definition>`. This gives rise to the
42problem of determining which :ref:`Solution <solution_definition>` should be
43applied.
45Two approaches to dealing with this can be envisaged:
47- **fully automated mode**: only the :ref:`Solution <solution_definition>`
48 with the highest ranking (i.e., the highest
49 :ref:`Optimization Efficacy <efficacy_definition>`) will be sent to the
50 :ref:`Watcher Planner <watcher_planner_definition>` and translated into
51 concrete :ref:`Actions <action_definition>`.
52- **manual mode**: several :ref:`Solutions <solution_definition>` are proposed
53 to the :ref:`Administrator <administrator_definition>` with a detailed
54 measurement of the estimated :ref:`Optimization Efficacy
55 <efficacy_definition>` and he/she decides which one will be launched.
56"""
58import abc
60from watcher.decision_engine.solution import efficacy
63class BaseSolution(object, metaclass=abc.ABCMeta):
64 def __init__(self, goal, strategy):
65 """Base Solution constructor
67 :param goal: Goal associated to this solution
68 :type goal: :py:class:`~.base.Goal` instance
69 :param strategy: Strategy associated to this solution
70 :type strategy: :py:class:`~.BaseStrategy` instance
71 """
72 self.goal = goal
73 self._strategy = strategy
74 self.origin = None
75 self.model = None
76 self.efficacy = efficacy.Efficacy(self.goal, self.strategy)
78 @property
79 def global_efficacy(self):
80 return self.efficacy.global_efficacy
82 @property
83 def efficacy_indicators(self):
84 return self.efficacy.indicators
86 @property
87 def strategy(self):
88 return self._strategy
90 def compute_global_efficacy(self):
91 """Compute the global efficacy given a map of efficacy indicators"""
92 self.efficacy.compute_global_efficacy()
94 def set_efficacy_indicators(self, **indicators_map):
95 """Set the efficacy indicators mapping (no validation)
97 :param indicators_map: mapping between the indicator name and its value
98 :type indicators_map: dict {`str`: `object`}
99 """
100 self.efficacy.set_efficacy_indicators(**indicators_map)
102 @abc.abstractmethod
103 def add_action(self, action_type, resource_id, input_parameters=None):
104 """Add a new Action in the Solution
106 :param action_type: the unique id of an action type defined in
107 entry point 'watcher_actions'
108 :param resource_id: the unique id of the resource to which the
109 `Action` applies.
110 :param input_parameters: An array of input parameters provided as
111 key-value pairs of strings. Each key-pair contains names and
112 values that match what was previously defined in the `Action`
113 type schema.
114 """
115 raise NotImplementedError()
117 @property
118 @abc.abstractmethod
119 def actions(self):
120 raise NotImplementedError()