Extend cluster events
This patch extends adds a new field 'instance_ids' in payloads of two cluster events: - DBaaSClusterShrink (during start and end notification), - DBaaSClusterGrow (during end notification). Moreover, additional end notifications after growing and shrinking cluster have been added. The purpose of this change if to enable better integration with tools for monitoring resources usage. Change-Id: I2c39b2c3bff65f88e46944eda22209bdc92803bc Signed-off-by: Kasper Hasior <k.hasior@samsung.com> Co-Authored-By: Kasper Hasior <k.hasior@samsung.com> Story: #2005520 Task: #30639
This commit is contained in:
parent
d5d84653cf
commit
59e8cb7e75
@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- Adds new fields "instance_ids", which is supposed to contain ids of
|
||||
cluster instances, in payloads of two cluster events -
|
||||
DBaaSClusterShrink and DBaaSClusterGrow. Moreover, additional end
|
||||
notifications after growing and shrinking cluster have been added.
|
||||
It allows better integration with tools for monitoring resources
|
||||
usage.
|
@ -331,7 +331,9 @@ class Cluster(object):
|
||||
return self.grow(instances)
|
||||
elif action == 'shrink':
|
||||
context.notification = DBaaSClusterShrink(context, request=req)
|
||||
with StartNotification(context, cluster_id=self.id):
|
||||
instance_ids = [instance['id'] for instance in param]
|
||||
with StartNotification(context, cluster_id=self.id,
|
||||
instance_ids=instance_ids):
|
||||
instance_ids = [instance['id'] for instance in param]
|
||||
return self.shrink(instance_ids)
|
||||
elif action == "reset-status":
|
||||
|
@ -649,6 +649,10 @@ class DBaaSClusterGrow(DBaaSAPINotification):
|
||||
def required_start_traits(self):
|
||||
return ['cluster_id']
|
||||
|
||||
@abc.abstractmethod
|
||||
def required_end_traits(self):
|
||||
return ['cluster_id']
|
||||
|
||||
|
||||
class DBaaSClusterShrink(DBaaSAPINotification):
|
||||
|
||||
@ -660,6 +664,10 @@ class DBaaSClusterShrink(DBaaSAPINotification):
|
||||
def required_start_traits(self):
|
||||
return ['cluster_id']
|
||||
|
||||
@abc.abstractmethod
|
||||
def required_end_traits(self):
|
||||
return ['cluster_id']
|
||||
|
||||
|
||||
class DBaaSBackupCreate(DBaaSAPINotification):
|
||||
|
||||
|
@ -428,12 +428,16 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
cluster_tasks.create_cluster(context, cluster_id)
|
||||
|
||||
def grow_cluster(self, context, cluster_id, new_instance_ids):
|
||||
cluster_tasks = models.load_cluster_tasks(context, cluster_id)
|
||||
cluster_tasks.grow_cluster(context, cluster_id, new_instance_ids)
|
||||
with EndNotification(context, cluster_id=cluster_id,
|
||||
instance_ids=new_instance_ids):
|
||||
cluster_tasks = models.load_cluster_tasks(context, cluster_id)
|
||||
cluster_tasks.grow_cluster(context, cluster_id, new_instance_ids)
|
||||
|
||||
def shrink_cluster(self, context, cluster_id, instance_ids):
|
||||
cluster_tasks = models.load_cluster_tasks(context, cluster_id)
|
||||
cluster_tasks.shrink_cluster(context, cluster_id, instance_ids)
|
||||
with EndNotification(context, cluster_id=cluster_id,
|
||||
instance_ids=instance_ids):
|
||||
cluster_tasks = models.load_cluster_tasks(context, cluster_id)
|
||||
cluster_tasks.shrink_cluster(context, cluster_id, instance_ids)
|
||||
|
||||
def restart_cluster(self, context, cluster_id):
|
||||
cluster_tasks = models.load_cluster_tasks(context, cluster_id)
|
||||
|
@ -14,7 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from mock import Mock, patch, PropertyMock
|
||||
from mock import MagicMock, Mock, patch, PropertyMock
|
||||
from proboscis.asserts import assert_equal
|
||||
|
||||
from trove.backup.models import Backup
|
||||
@ -274,6 +274,42 @@ class TestManager(trove_testtools.TestCase):
|
||||
mock_tasks.delete_cluster.assert_called_with(self.context,
|
||||
'some-cluster-id')
|
||||
|
||||
def test_shrink_cluster_with_success(self):
|
||||
self._assert_shrink_cluster(True)
|
||||
|
||||
def test_shrink_cluster_with_error(self):
|
||||
self._assert_shrink_cluster(False)
|
||||
|
||||
@patch('trove.taskmanager.manager.EndNotification')
|
||||
@patch('trove.taskmanager.manager.models.load_cluster_tasks')
|
||||
def _assert_shrink_cluster(self, success, mock_load, mock_notification):
|
||||
if success:
|
||||
mock_load.side_effect = Mock()
|
||||
else:
|
||||
mock_load.side_effect = Exception
|
||||
|
||||
end_notification = MagicMock()
|
||||
mock_notification.return_value = end_notification
|
||||
context = Mock()
|
||||
cluster_id = Mock()
|
||||
instance_ids = Mock()
|
||||
|
||||
try:
|
||||
self.manager.shrink_cluster(context, cluster_id, instance_ids)
|
||||
self.assertTrue(success)
|
||||
except Exception:
|
||||
self.assertFalse(success)
|
||||
|
||||
mock_load.assert_called_once_with(context, cluster_id)
|
||||
mock_notification.assert_called_once_with(context,
|
||||
cluster_id=cluster_id,
|
||||
instance_ids=instance_ids)
|
||||
exit_error_type = end_notification.__exit__.call_args_list[0][0][0]
|
||||
if success:
|
||||
self.assertFalse(exit_error_type)
|
||||
else:
|
||||
self.assertTrue(exit_error_type)
|
||||
|
||||
|
||||
class TestTaskManagerService(trove_testtools.TestCase):
|
||||
def test_app_factory(self):
|
||||
|
Loading…
Reference in New Issue
Block a user