Fix a bug in which deleting the cluster doesn't stop its launcher and elector.
diff --git a/mysos/scheduler/elector.py b/mysos/scheduler/elector.py
index fa55bbe..4d4c08b 100644
--- a/mysos/scheduler/elector.py
+++ b/mysos/scheduler/elector.py
@@ -172,8 +172,9 @@
return
self._master_callback(self._master) # Invoke the callback from the elector thread.
- log.info("Stopping the elector thread for cluster %s because the election has completed" %
- self._cluster_name)
+ log.info(
+ "Stopping the elector thread for cluster %s (epoch %s) because the election has completed" %
+ (self._cluster_name, self._epoch))
def _elect(self, timedout=False):
"""
diff --git a/mysos/scheduler/launcher.py b/mysos/scheduler/launcher.py
index 7a5908e..87923f5 100644
--- a/mysos/scheduler/launcher.py
+++ b/mysos/scheduler/launcher.py
@@ -531,6 +531,11 @@
log.info("Received framework message '%s' from task %s (%s) when there is no pending "
"election" % (message, task_id, slave_id))
+ def stop(self):
+ """Called when the launcher is being shut down (due to removal of the cluster)."""
+ if self._elector:
+ self._elector.abort()
+
# --- Utility methods. ---
def create_resources(cpus, mem, disk, ports, role='*'):
diff --git a/mysos/scheduler/scheduler.py b/mysos/scheduler/scheduler.py
index 52986ae..9e7de37 100644
--- a/mysos/scheduler/scheduler.py
+++ b/mysos/scheduler/scheduler.py
@@ -434,6 +434,7 @@
assert launcher.terminated
self._state.clusters.discard(launcher.cluster_name)
self._state_provider.dump_scheduler_state(self._state)
+ self._launchers[launcher.cluster_name].stop()
del self._launchers[launcher.cluster_name]
@logged