From 71730c0eaf14bab26e9cf39d52d6b1d9203d66ca Mon Sep 17 00:00:00 2001 From: aditi Date: Tue, 19 Sep 2017 08:09:11 +0000 Subject: [PATCH] Multiple global efficacy This patch update the global efficacy for server consolidation strategy, test cases and general format. Change-Id: I62af1e4be415998669f938b3d587c1ccf4293419 Implements: blueprint multiple-global-efficacy-indicator --- watcher/db/sqlalchemy/models.py | 2 +- watcher/decision_engine/goal/efficacy/base.py | 3 ++- watcher/decision_engine/goal/efficacy/specs.py | 8 +++++--- watcher/decision_engine/solution/efficacy.py | 2 +- watcher/objects/action_plan.py | 5 +++-- watcher/tests/db/utils.py | 2 +- .../strategy/strategies/test_basic_consolidation.py | 6 ++++-- watcher/tests/objects/test_objects.py | 2 +- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/watcher/db/sqlalchemy/models.py b/watcher/db/sqlalchemy/models.py index e7066c806..2121c9da1 100644 --- a/watcher/db/sqlalchemy/models.py +++ b/watcher/db/sqlalchemy/models.py @@ -199,7 +199,7 @@ class ActionPlan(Base): audit_id = Column(Integer, ForeignKey('audits.id'), nullable=False) strategy_id = Column(Integer, ForeignKey('strategies.id'), nullable=False) state = Column(String(20), nullable=True) - global_efficacy = Column(JSONEncodedDict, nullable=True) + global_efficacy = Column(JSONEncodedList, nullable=True) audit = orm.relationship(Audit, foreign_keys=audit_id, lazy=None) strategy = orm.relationship(Strategy, foreign_keys=strategy_id, lazy=None) diff --git a/watcher/decision_engine/goal/efficacy/base.py b/watcher/decision_engine/goal/efficacy/base.py index b51770062..f4c6b1587 100644 --- a/watcher/decision_engine/goal/efficacy/base.py +++ b/watcher/decision_engine/goal/efficacy/base.py @@ -57,7 +57,8 @@ class EfficacySpecification(object): efficacy indicators related to this spec :type indicators_map: :py:class:`~.IndicatorsMap` instance :raises: NotImplementedError - :returns: :py:class:`~.Indicator` instance + :returns: :py:class:`~.Indicator` instance list, each instance specify + global efficacy for different openstack resource. """ raise NotImplementedError() diff --git a/watcher/decision_engine/goal/efficacy/specs.py b/watcher/decision_engine/goal/efficacy/specs.py index 474459ebd..023a6e0a3 100644 --- a/watcher/decision_engine/goal/efficacy/specs.py +++ b/watcher/decision_engine/goal/efficacy/specs.py @@ -40,14 +40,16 @@ class ServerConsolidation(base.EfficacySpecification): def get_global_efficacy_indicator(self, indicators_map=None): value = 0 + global_efficacy = [] if indicators_map and indicators_map.compute_nodes_count > 0: value = (float(indicators_map.released_compute_nodes_count) / float(indicators_map.compute_nodes_count)) * 100 - - return efficacy.Indicator( + global_efficacy.append(efficacy.Indicator( name="released_nodes_ratio", description=_("Ratio of released compute nodes divided by the " "total number of enabled compute nodes."), unit='%', value=value, - ) + )) + + return global_efficacy diff --git a/watcher/decision_engine/solution/efficacy.py b/watcher/decision_engine/solution/efficacy.py index 31ff4f3bb..a0813d8d5 100644 --- a/watcher/decision_engine/solution/efficacy.py +++ b/watcher/decision_engine/solution/efficacy.py @@ -62,7 +62,7 @@ class Efficacy(object): self.indicators = [] # Used to compute the global efficacy self._indicators_mapping = IndicatorsMap() - self.global_efficacy = None + self.global_efficacy = [] def set_efficacy_indicators(self, **indicators_map): """Set the efficacy indicators diff --git a/watcher/objects/action_plan.py b/watcher/objects/action_plan.py index 4618ec953..1a165fa70 100644 --- a/watcher/objects/action_plan.py +++ b/watcher/objects/action_plan.py @@ -105,7 +105,8 @@ class ActionPlan(base.WatcherPersistentObject, base.WatcherObject, # Version 1.1: Added 'audit' and 'strategy' object field # Version 1.2: audit_id is not nullable anymore # Version 2.0: Removed 'first_action_id' object field - VERSION = '2.0' + # Version 2.1: Changed global_efficacy type + VERSION = '2.1' dbapi = db_api.get_instance() @@ -115,7 +116,7 @@ class ActionPlan(base.WatcherPersistentObject, base.WatcherObject, 'audit_id': wfields.IntegerField(), 'strategy_id': wfields.IntegerField(), 'state': wfields.StringField(nullable=True), - 'global_efficacy': wfields.FlexibleDictField(nullable=True), + 'global_efficacy': wfields.FlexibleListOfDictField(nullable=True), 'audit': wfields.ObjectField('Audit', nullable=True), 'strategy': wfields.ObjectField('Strategy', nullable=True), diff --git a/watcher/tests/db/utils.py b/watcher/tests/db/utils.py index ae1ab7968..6a47c382d 100644 --- a/watcher/tests/db/utils.py +++ b/watcher/tests/db/utils.py @@ -167,7 +167,7 @@ def get_test_action_plan(**kwargs): 'state': kwargs.get('state', objects.action_plan.State.ONGOING), 'audit_id': kwargs.get('audit_id', 1), 'strategy_id': kwargs.get('strategy_id', 1), - 'global_efficacy': kwargs.get('global_efficacy', {}), + 'global_efficacy': kwargs.get('global_efficacy', []), 'created_at': kwargs.get('created_at'), 'updated_at': kwargs.get('updated_at'), 'deleted_at': kwargs.get('deleted_at'), diff --git a/watcher/tests/decision_engine/strategy/strategies/test_basic_consolidation.py b/watcher/tests/decision_engine/strategy/strategies/test_basic_consolidation.py index 9f3cf424c..efe15d352 100644 --- a/watcher/tests/decision_engine/strategy/strategies/test_basic_consolidation.py +++ b/watcher/tests/decision_engine/strategy/strategies/test_basic_consolidation.py @@ -232,7 +232,7 @@ class TestBasicConsolidation(base.TestCase): num_node_state_change = actions_counter.get( "change_nova_service_state", 0) - global_efficacy_value = solution.global_efficacy.get("value", 0) + global_efficacy_value = solution.global_efficacy[0].get('value', 0) self.assertEqual(expected_num_migrations, num_migrations) self.assertEqual(expected_power_state, num_node_state_change) @@ -258,7 +258,9 @@ class TestBasicConsolidation(base.TestCase): ) as mock_score_call: mock_score_call.return_value = 0 solution = self.strategy.execute() - self.assertEqual(0, solution.efficacy.global_efficacy.value) + + self.assertEqual(0, + solution.efficacy.global_efficacy[0].get('value')) def test_check_parameters(self): model = self.fake_cluster.generate_scenario_3_with_2_nodes() diff --git a/watcher/tests/objects/test_objects.py b/watcher/tests/objects/test_objects.py index 924116d8c..8894956f8 100644 --- a/watcher/tests/objects/test_objects.py +++ b/watcher/tests/objects/test_objects.py @@ -413,7 +413,7 @@ expected_object_fingerprints = { 'Strategy': '1.1-73f164491bdd4c034f48083a51bdeb7b', 'AuditTemplate': '1.1-b291973ffc5efa2c61b24fe34fdccc0b', 'Audit': '1.4-f5f27510b8090bce7d1fb45416d58ff1', - 'ActionPlan': '2.0-394f1abbf5d73d7b6675a118fe1a0284', + 'ActionPlan': '2.1-d573f34f2e15da0743afcc38ae62cd22', 'Action': '2.0-1dd4959a7e7ac30c62ef170fe08dd935', 'EfficacyIndicator': '1.0-655b71234a82bc7478aff964639c4bb0', 'ScoringEngine': '1.0-4abbe833544000728e17bd9e83f97576',