Merge "coordination: use tooz builtin heartbeat manager"

This commit is contained in:
Jenkins authored and Gerrit Code Review committed 2017-03-10 14:27:37 +00:00
commit cc928ef73f
5 files changed
+2 -66

No files matched your search

-7
View File
@@ -277,10 +277,6 @@ class AgentManager(cotyledon.Service):
self.partition_coordinator = coordination.PartitionCoordinator(
self.conf)
self.heartbeat_timer = utils.create_periodic(
target=self.partition_coordinator.heartbeat,
spacing=self.conf.coordination.heartbeat,
run_immediately=True)
# Compose coordination group prefix.
# We'll use namespaces as the basement for this partitioning.
@@ -356,11 +352,9 @@ class AgentManager(cotyledon.Service):
if not self.groups and self.partition_coordinator.is_active():
self.partition_coordinator.stop()
self.heartbeat_timer.stop()
if self.groups and not self.partition_coordinator.is_active():
self.partition_coordinator.start()
utils.spawn_thread(self.heartbeat_timer.start)
for group in self.groups:
self.partition_coordinator.join_group(group)
@@ -427,7 +421,6 @@ class AgentManager(cotyledon.Service):
def terminate(self):
self.stop_pollsters_tasks()
self.heartbeat_timer.stop()
self.partition_coordinator.stop()
super(AgentManager, self).terminate()
+1 -19
View File
@@ -33,10 +33,6 @@ OPTS = [
'compute agent won\'t do workload '
'partitioning and will only function correctly if a '
'single instance of that service is running.'),
cfg.FloatOpt('heartbeat',
default=1.0,
help='Number of seconds between heartbeats for distributed '
'coordination.'),
cfg.FloatOpt('check_watchers',
default=10.0,
help='Number of seconds between checks to see if group '
@@ -65,9 +61,6 @@ class PartitionCoordinator(object):
This class uses the `tooz` library to manage group membership.
To ensure that the other agents know this agent is still alive,
the `heartbeat` method should be called periodically.
Coordination errors and reconnects are handled under the hood, so the
service using the partition coordinator need not care whether the
coordination backend is down. The `extract_my_subset` will simply return an
@@ -86,7 +79,7 @@ class PartitionCoordinator(object):
try:
self._coordinator = tooz.coordination.get_coordinator(
backend_url, self._my_id)
self._coordinator.start()
self._coordinator.start(start_heart=True)
LOG.info(_LI('Coordination backend started successfully.'))
except tooz.coordination.ToozError:
LOG.exception(_LE('Error connecting to coordination backend.'))
@@ -105,17 +98,6 @@ class PartitionCoordinator(object):
def is_active(self):
return self._coordinator is not None
def heartbeat(self):
if self._coordinator:
if not self._coordinator.is_started:
# re-connect
self.start()
try:
self._coordinator.heartbeat()
except tooz.coordination.ToozError:
LOG.exception(_LE('Error sending a heartbeat to coordination '
'backend.'))
def watch_group(self, namespace, callback):
if self._coordinator:
self._coordinator.watch_join_group(namespace, callback)
-6
View File
@@ -200,11 +200,6 @@ class NotificationService(cotyledon.Service):
self.partition_coordinator.watch_group(self.group_id,
self._refresh_agent)
@periodics.periodic(spacing=self.conf.coordination.heartbeat,
run_immediately=True)
def heartbeat():
self.partition_coordinator.heartbeat()
@periodics.periodic(spacing=self.conf.coordination.check_watchers,
run_immediately=True)
def run_watchers():
@@ -213,7 +208,6 @@ class NotificationService(cotyledon.Service):
self.periodic = periodics.PeriodicWorker.create(
[], executor_factory=lambda:
futures.ThreadPoolExecutor(max_workers=10))
self.periodic.add(heartbeat)
self.periodic.add(run_watchers)
utils.spawn_thread(self.periodic.start)
-14
View File
@@ -21,7 +21,6 @@ import copy
import datetime
import os
import tempfile
import time
import mock
from oslo_config import fixture as fixture_config
@@ -253,7 +252,6 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
'cfg_file',
self.path_get('etc/ceilometer/polling.yaml'), group='polling'
)
self.CONF.set_override('heartbeat', 1.0, group='coordination')
self.CONF(args=[])
self.mgr = self.create_manager()
self.mgr.extensions = self.create_extension_list()
@@ -296,23 +294,11 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
self.mgr.setup_polling_tasks = mock.MagicMock()
mpc = self.mgr.partition_coordinator
mpc.is_active.return_value = False
self.CONF.set_override('heartbeat', 1.0, group='coordination')
self.mgr.partition_coordinator.heartbeat = mock.MagicMock()
self.mgr.run()
setup_polling.assert_called_once_with(self.CONF)
mpc.start.assert_called_once_with()
self.assertEqual(2, mpc.join_group.call_count)
self.mgr.setup_polling_tasks.assert_called_once_with()
# Wait first heatbeat
runs = 0
for i in six.moves.range(10):
runs = list(self.mgr.heartbeat_timer.iter_watchers())[0].runs
if runs > 0:
break
time.sleep(0.5)
self.assertGreaterEqual(1, runs)
self.mgr.terminate()
mpc.stop.assert_called_once_with()
+1 -20
View File
@@ -59,7 +59,7 @@ class MockToozCoordinator(tooz.coordination.CoordinationDriver):
class MockToozCoordExceptionRaiser(MockToozCoordinator):
def start(self):
def start(self, start_heart=False):
raise tooz.coordination.ToozError('error')
def heartbeat(self):
@@ -237,25 +237,6 @@ class TestPartitioning(base.BaseTestCase):
' re-trying']
self.assertEqual(expected_errors, self.str_handler.messages['error'])
def test_reconnect(self):
coord = self._get_new_started_coordinator({}, 'a',
MockToozCoordExceptionRaiser)
with mock.patch('tooz.coordination.get_coordinator',
return_value=MockToozCoordExceptionRaiser('a', {})):
coord.heartbeat()
expected_errors = ['Error connecting to coordination backend.',
'Error sending a heartbeat to coordination '
'backend.']
for e in expected_errors:
self.assertIn(e, self.str_handler.messages['error'])
self.str_handler.messages['error'] = []
with mock.patch('tooz.coordination.get_coordinator',
return_value=MockToozCoordinator('a', {})):
coord.heartbeat()
for e in expected_errors:
self.assertNotIn(e, self.str_handler.messages['error'])
def test_group_id_none(self):
coord = self._get_new_started_coordinator({}, 'a')
self.assertTrue(coord._coordinator.is_started)