Commit fbcf666b authored by Daniele Venzano's avatar Daniele Venzano

A few bug fixes

parent 077926e7
......@@ -26,4 +26,6 @@ class ContainerState(Base):
}
for p in self.proxies:
ret['proxies'].append(p.to_dict)
ret['proxies'].append(p.to_dict())
return ret
......@@ -59,10 +59,14 @@ class ExecutionState(Base):
'time_finished': self.time_finished,
'status': self.status,
'termination_notice': self.termination_notice,
'type': self.type,
'assigned_resources': self.assigned_resources.to_dict()
'type': self.type
}
if self.assigned_resources is None:
ret['assigned_resources'] = None
else:
ret['assigned_resources'] = self.assigned_resources.to_dict()
if self.cluster is not None:
ret['cluster_id'] = self.cluster.id
ret['containers'] = [c.to_dict() for c in self.cluster.containers]
......
import dateutil.parser
def deserialize_datetime(isoformat):
if isoformat is None:
return None
else:
return dateutil.parser.parse(isoformat)
class User:
def __init__(self, user: dict):
self.id = user['id']
......@@ -10,9 +20,9 @@ class Execution:
self.name = execution['name']
self.assigned_resources = execution['assigned_resources']
self.application_id = execution['application_id']
self.time_started = execution['time_started']
self.time_scheduled = execution['time_scheduled']
self.time_finished = execution['time_finished']
self.time_started = deserialize_datetime(execution['time_started'])
self.time_scheduled = deserialize_datetime(execution['time_scheduled'])
self.time_finished = deserialize_datetime(execution['time_finished'])
self.status = execution['status']
self.termination_notice = execution['termination_notice']
self.cluster_id = execution['cluster_id']
......@@ -49,7 +59,7 @@ class Proxy:
self.cluster_id = proxy['cluster_id']
self.container_id = proxy['container_id']
self.service_name = proxy['service_name']
self.last_access = proxy['last_access']
self.last_access = deserialize_datetime(proxy['last_access'])
class Application:
......
......@@ -9,12 +9,17 @@ class ZoeIPCClient:
def __init__(self, server, port=8723):
self.context = zmq.Context()
self.socket = self.context.socket(zmq.REQ)
self.socket.RCVTIMEO = 2000
self.socket.connect("tcp://%s:%d" % (server, port))
log.debug("ZMQ socket connected")
def _ask(self, message: dict) -> dict:
self.socket.send_json(message)
answer = self.socket.recv_json()
try:
answer = self.socket.recv_json()
except zmq.ZMQError as e:
log.error("IPC server error: {}".format(e.msg))
return None
if self._is_error(answer):
log.info("IPC error: {}".format(self._error(answer)))
return None
......
import base64
from datetime import datetime
import json
import logging
import threading
......@@ -34,16 +36,27 @@ class ZoeIPCServer:
self.th.start()
def _loop(self):
self.state = AlchemySession() # thread-local session
log.debug("IPC server thread started")
while True:
message = self.socket.recv_json()
self.state = AlchemySession()
try:
reply = self._dispatch(message)
except:
log.exception("Uncaught exception in IPC server thread")
reply = self._reply_error('exception')
self.socket.send_json(reply)
finally:
self.state.close()
self.state = None
json_reply = json.dumps(reply, default=self._json_default_serializer)
self.socket.send_string(json_reply)
def _json_default_serializer(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
else:
log.error('Cannot serialize type {}'.format(type(obj)))
raise TypeError
def _dispatch(self, message: dict) -> dict:
if "command" not in message or "args" not in message:
......@@ -247,6 +260,7 @@ class ZoeIPCServer:
application_id=application.id,
status="submitted")
self.state.add(execution)
self.state.flush()
ret = self.sched.incoming(execution)
if ret:
......
......@@ -30,7 +30,6 @@ class PlatformManager:
except CannotCreateCluster:
return False
execution.set_started()
print(execution.status)
state.commit()
pm.update_proxy()
return True
......
......@@ -2,6 +2,9 @@
{% block title %}Inspect execution {{ execution.name }}{% endblock %}
{% block content %}
<h2>Detailed information for execution {{ execution.name }}</h2>
{% if execution.containers|count == 0 %}
<p>This application execution has no running containers</p>
{% else %}
<div id="contents">
<div id="container_list">
<ul>
......@@ -73,5 +76,6 @@
get_log({{ (execution.containers|first).id }});
get_stats({{ (execution.containers|first).id }});
</script>
{% endif %}
{% endblock %}
\ No newline at end of file
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