Commit fb80641c authored by Daniele Venzano's avatar Daniele Venzano

Expose service status in the web and CLI interfaces

parent 4e2e3ca4
...@@ -31,14 +31,13 @@ ...@@ -31,14 +31,13 @@
{% for s in services_info %} {% for s in services_info %}
<li class="container_name" id="{{ s['id'] }}">{{ s['name'] }}</li> <li class="container_name" id="{{ s['id'] }}">{{ s['name'] }}</li>
<ul> <ul>
<li>Status: {{ s['status'] }}</li> <li>Zoe status: {{ s['status'] }}</li>
{% for p in s['description']['ports'] %} <li>Docker status: {{ s['docker_status'] }}</li>
{% if s['ip_address'] == None %} {% if s['docker_status'] == 'started' %}
<li>Inactive</li> {% for p in s['description']['ports'] %}
{% else %} <li><a href="{{ p['protocol'] }}://{{ s['ip_address'] }}:{{ p['port_number'] }}{{ p['path'] }}">{{ p['name'] }}</a></li>
<li><a href="{{ p['protocol'] }}://{{ s['ip_address'] }}:{{ p['port_number'] }}{{ p['path'] }}">{{ p['name'] }}</a></li> {% endfor %}
{% endif %} {% endif %}
{% endfor %}
</ul> </ul>
{% endfor %} {% endfor %}
</ul> </ul>
......
...@@ -109,10 +109,13 @@ def exec_get_cmd(args): ...@@ -109,10 +109,13 @@ def exec_get_cmd(args):
print('Application name: {}'.format(app['name'])) print('Application name: {}'.format(app['name']))
for c_id in execution['services']: for c_id in execution['services']:
service = cont_api.get(c_id) service = cont_api.get(c_id)
ip = service['ip_address'] print('Service {} (ID: {})'.format(service['name'], service['id']))
print('Service {} (ID: {}, {})'.format(service['name'], service['id'], service['status'])) print(' - zoe status: {}'.format(service['status']))
for port in service['description']['ports']: print(' - docker status: {}'.format(service['docker_status']))
print(' - {}: {}://{}:{}{}'.format(port['name'], port['protocol'], ip, port['port_number'], port['path'])) if service['docker_status'] == 'started':
ip = service['ip_address']
for port in service['description']['ports']:
print(' - {}: {}://{}:{}{}'.format(port['name'], port['protocol'], ip, port['port_number'], port['path']))
def exec_kill_cmd(args): def exec_kill_cmd(args):
......
...@@ -319,10 +319,10 @@ class Service(Base): ...@@ -319,10 +319,10 @@ class Service(Base):
STARTING_STATUS = "starting" STARTING_STATUS = "starting"
DOCKER_UNDEFINED_STATUS = 'undefined' DOCKER_UNDEFINED_STATUS = 'undefined'
DOCKER_CREATE_STATUS = 'create' DOCKER_CREATE_STATUS = 'created'
DOCKER_START_STATUS = 'start' DOCKER_START_STATUS = 'started'
DOCKER_DIE_STATUS = 'die' DOCKER_DIE_STATUS = 'dead'
DOCKER_DESTROY_STATUS = 'destroy' DOCKER_DESTROY_STATUS = 'destroyed'
def __init__(self, d, sql_manager): def __init__(self, d, sql_manager):
super().__init__(d, sql_manager) super().__init__(d, sql_manager)
...@@ -377,24 +377,13 @@ class Service(Base): ...@@ -377,24 +377,13 @@ class Service(Base):
def set_docker_status(self, new_status): def set_docker_status(self, new_status):
"""Docker has emitted an event related to this service.""" """Docker has emitted an event related to this service."""
if new_status == 'create':
new_status = self.DOCKER_CREATE_STATUS
elif new_status == 'start':
new_status = self.DOCKER_START_STATUS
elif new_status == 'die':
new_status = self.DOCKER_DIE_STATUS
elif new_status == 'destroy':
new_status = self.DOCKER_DESTROY_STATUS
else:
log.error('Unknown docker status: {}'.format(new_status))
return
self.sql_manager.service_update(self.id, docker_status=new_status) self.sql_manager.service_update(self.id, docker_status=new_status)
log.debug("service {}, status updated to {}".format(self.id, new_status))
@property @property
def ip_address(self): def ip_address(self):
"""Getter for the service IP address, queries Swarm as the IP address changes outside our control.""" """Getter for the service IP address, queries Swarm as the IP address changes outside our control."""
if self.status != self.ACTIVE_STATUS: if self.docker_status != self.DOCKER_START_STATUS:
return {} return {}
swarm = SwarmClient(get_conf()) swarm = SwarmClient(get_conf())
s_info = swarm.inspect_container(self.docker_id) s_info = swarm.inspect_container(self.docker_id)
......
...@@ -69,13 +69,13 @@ class ZoeMonitor(threading.Thread): ...@@ -69,13 +69,13 @@ class ZoeMonitor(threading.Thread):
if 'exec' in event['Action']: if 'exec' in event['Action']:
pass pass
elif 'create' in event['Action']: elif 'create' in event['Action']:
service.set_docker_status('create') service.set_docker_status(service.DOCKER_CREATE_STATUS)
elif 'start' in event['Action']: elif 'start' in event['Action']:
service.set_docker_status('start') service.set_docker_status(service.DOCKER_START_STATUS)
elif 'die' in event['Action']: elif 'die' in event['Action']:
service.set_docker_status('die') service.set_docker_status(service.DOCKER_DIE_STATUS)
elif 'destroy' in event['Action']: elif 'destroy' in event['Action']:
service.set_docker_status('destroy') service.set_docker_status(service.DOCKER_DESTROY_STATUS)
else: else:
log.debug('Unmanaged container action: {}'.format(event['Action'])) log.debug('Unmanaged container action: {}'.format(event['Action']))
......
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