Commit f84147d6 authored by Daniele Venzano's avatar Daniele Venzano

Fix sonarqube warnings

parent 8e73d34a
......@@ -42,13 +42,15 @@ class OldSwarmBackend(zoe_master.backends.base.BaseBackend):
super().__init__(opts)
self.swarm = SwarmClient(opts)
def init(self, state):
@classmethod
def init(cls, state):
"""Initializes Swarm backend starting the event monitoring thread."""
global _monitor, _checker
_monitor = SwarmMonitor(state)
_checker = SwarmStateSynchronizer(state)
def shutdown(self):
@classmethod
def shutdown(cls):
"""Performs a clean shutdown of the resources used by Swarm backend."""
_monitor.quit()
_checker.quit()
......@@ -88,7 +90,7 @@ class OldSwarmBackend(zoe_master.backends.base.BaseBackend):
for port in service.ports:
if port.expose:
copts.ports.append(port.port_number) # FIXME UDP ports?
copts.ports.append(port.port_number)
for volume in service.volumes:
if volume.type == "host_directory":
......@@ -109,12 +111,7 @@ class OldSwarmBackend(zoe_master.backends.base.BaseBackend):
copts.set_command(service.command.format(**env_subst_dict))
try:
swarm = SwarmClient(get_conf())
except Exception as e:
raise ZoeStartExecutionFatalException(str(e))
try:
cont_info = swarm.spawn_container(service.image_name, copts)
cont_info = self.swarm.spawn_container(service.image_name, copts)
except ZoeNotEnoughResourcesException:
service.set_error('Not enough free resources to satisfy reservation request')
raise ZoeStartExecutionRetryException('Not enough free resources to satisfy reservation request for service {}'.format(service.name))
......
......@@ -105,6 +105,18 @@ class SwarmStateSynchronizer(threading.Thread):
self.start()
def _find_dead_service(self, container_list, service: Service):
"""Loop through the containers and try to update the service status."""
found = False
for container in container_list:
if container['id'] == service.backend_id:
found = True
if container['status'] == 'exited':
log.info('resetting status of service {}, died with no event'.format(service.name))
service.set_backend_status(service.BACKEND_DIE_STATUS)
if not found:
service.set_backend_status(service.BACKEND_DESTROY_STATUS)
def run(self):
"""The thread loop."""
log.info("Checker thread started")
......@@ -117,15 +129,7 @@ class SwarmStateSynchronizer(threading.Thread):
assert isinstance(service, Service)
if service.backend_status == service.BACKEND_DESTROY_STATUS or service.backend_status == service.BACKEND_DIE_STATUS:
continue
found = False
for container in container_list:
if container['id'] == service.backend_id:
found = True
if container['status'] == 'exited':
log.info('resetting status of service {}, died with no event'.format(service.name))
service.set_backend_status(service.BACKEND_DIE_STATUS)
if not found:
service.set_backend_status(service.BACKEND_DESTROY_STATUS)
self._find_dead_service(container_list, service)
time.sleep(CHECK_INTERVAL)
......
......@@ -192,11 +192,6 @@ class ZoeElasticScheduler:
current_free_resources = cluster_status_snapshot.aggregated_free_memory()
if current_free_resources >= free_resources:
# job_aux = jobs_to_launch.pop()
# cluster_status_snapshot.deallocate_essential(job_aux)
# cluster_status_snapshot.deallocate_elastic(job_aux)
# for job_aux in jobs_to_launch:
# cluster_status_snapshot.allocate_elastic(job_aux)
jobs_to_launch = jobs_to_launch_copy
break
free_resources = current_free_resources
......
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