Commit 5eea477c authored by Daniele Venzano's avatar Daniele Venzano

Fix #67 by using the terminating state to mark services that need to be terminated

parent e4d56fab
......@@ -79,7 +79,12 @@ class DockerEngineBackend(zoe_master.backends.base.BaseBackend):
def terminate_service(self, service: Service) -> None:
"""Terminate and delete a container."""
conf = self._get_config(service.backend_host)
engine = DockerClient(conf)
service.set_terminating()
try:
engine = DockerClient(conf)
except ZoeException as e:
log.error('Cannot terminate service {}: {}'.format(service.id, str(e)))
return
if service.backend_id is not None:
engine.terminate_container(service.backend_id, delete=True)
else:
......
......@@ -91,6 +91,12 @@ class DockerStateSynchronizer(threading.Thread):
log.warning('Terminating dead and orphan container {}'.format(cont['name']))
my_engine.terminate_container(cont['id'], delete=True)
continue
if service.status == service.TERMINATING_STATUS:
if service.backend_id is not None:
my_engine.terminate_container(service.backend_id, delete=True)
else:
service.set_inactive()
self._update_service_status(service, cont)
self.host_stats[host_config.name].memory_reserved += service.resource_reservation.memory.min
self.host_stats[host_config.name].cores_reserved += service.resource_reservation.cores.min
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment