Commit b77acb3e authored by Iustin Pop's avatar Iustin Pop
Browse files

Change client protocol to raise exception on failures

Currently the luxi.client.SubmitJob and Query methods return the unserialized
result without processing it at all. This patch changes this by adding a
'RequestException' error that is raised if the query itself or the
submission of the job failed, and (if not) returning only the 'result'
field from the message.

The patch also does processing on the result of a query if we queried
for jobs, as the 'op_list' field in the result has serialized opcodes
and we need the de-serialized.

Reviewed-by: ultrotter
parent 35049ff2
......@@ -68,6 +68,19 @@ class DecodingError(ProtocolError):
"""Decoding failure on the receiving side"""
class RequestError(ProtocolError):
"""Error on request
This signifies an error in the request format or request handling,
but not (e.g.) an error in starting up an instance.
Some common conditions that can trigger this exception:
- job submission failed because the job data was wrong
- query failed because required fields were missing
def SerializeJob(job):
"""Convert a job description to a string format.
......@@ -252,8 +265,21 @@ class Client(object):
def SubmitJob(self, job):
"""Submit a job"""
return self.SendRequest(REQ_SUBMIT, SerializeJob(job))
result = self.SendRequest(REQ_SUBMIT, SerializeJob(job))
if not result['success']:
raise RequestError(result['result'])
return result['result']
def Query(self, data):
"""Make a query"""
return self.SendRequest(REQ_QUERY, data)
result = self.SendRequest(REQ_QUERY, data)
if not result['success']:
raise RequestError(result[result])
result = result['result']
if data["object"] == "jobs":
# custom job processing of query values
for row in result:
for idx, field in enumerate(data["fields"]):
if field == "op_list":
row[idx] = [opcodes.OpCode.LoadOpCode(i) for i in row[idx]]
return result
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