Commit 01d3df55 authored by Daniele Venzano's avatar Daniele Venzano

Download image list in the synchro thread to speed-up scheduler

parent 8d83c5bb
......@@ -193,34 +193,8 @@ class DockerEngineBackend(zoe_master.backends.base.BaseBackend):
def list_available_images(self, node_name):
"""List the images available on the specified node."""
host_conf = None
for conf in self.docker_config:
if conf.name == node_name:
host_conf = conf
break
if host_conf is None:
log.error('Unknown node {}, returning empty image list'.format(node_name))
return []
try:
my_engine = DockerClient(host_conf)
except ZoeException as e:
log.error(str(e))
return []
image_list = []
for dk_image in my_engine.list_images():
image = {
'id': dk_image.attrs['Id'],
'size': dk_image.attrs['Size'],
'names': dk_image.tags # type: list
}
for name in image['names']:
if name[-7:] == ':latest': # add an image with the name without 'latest' to fake Docker image lookup algorithm
image['names'].append(name[:-7])
break
image_list.append(image)
return image_list
node_stats = _checker.host_stats[node_name]
return node_stats.images
def update_service(self, service, cores=None, memory=None):
"""Update a service reservation."""
......
......@@ -100,6 +100,19 @@ class DockerStateSynchronizer(threading.Thread):
}
self.host_stats[host_config.name].service_stats = stats
self.host_stats[host_config.name].images = []
for dk_image in my_engine.list_images():
image = {
'id': dk_image.attrs['Id'],
'size': dk_image.attrs['Size'],
'names': dk_image.tags # type: list
}
for name in image['names']:
if name[-7:] == ':latest': # add an image with the name without 'latest' to fake Docker image lookup algorithm
image['names'].append(name[:-7])
break
self.host_stats[host_config.name].images.append(image)
sleep_time = CHECK_INTERVAL - (time.time() - time_start)
if sleep_time <= 0:
log.warning('synchro thread for host {} is late by {:.2f} seconds'.format(host_config.name, sleep_time * -1))
......
......@@ -44,6 +44,7 @@ class NodeStats(Stats):
self.labels = []
self.status = 'offline'
self.service_stats = {}
self.images = []
def serialize(self):
"""Convert the object into a dict."""
......@@ -60,7 +61,8 @@ class NodeStats(Stats):
'memory_in_use': self.memory_in_use,
'labels': list(self.labels),
'status': self.status,
'service_stats': self.service_stats
'service_stats': self.service_stats,
'images': self.images
}
return ret
......
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