Skip to content
Snippets Groups Projects
Commit 8a2cb6a1 authored by Megan Henning's avatar Megan Henning Committed by GitHub
Browse files

Merge pull request #598 from scitran/jobs-endpoint

Update session jobs endpoint
parents d778c1ee 732ea5d0
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,8 @@ class ContainerStorage(object):
except KeyError:
raise APINotFoundException('Children cannot be listed from the {0} level'.format(self.cont_name))
query = {self.cont_name[:-1]: bson.objectid.ObjectId(_id)}
if not projection:
projection = {'metadata': 0, 'files.metadata': 0, 'subject': 0}
return self.factory(child_name, use_object_id=True).get_all_el(query, None, projection)
def _from_mongo(self, cont):
......
......@@ -176,36 +176,51 @@ class ContainerHandler(base.RequestHandler):
# Only enabled for sessions container type per url rule in api.py
self.config = self.container_handler_configurations["sessions"]
self.storage = self.config['storage']
cont = self._get_container(cid, projection={'permissions': 0}, get_children=True)
cont = self._get_container(cid, projection={'permissions': 0, 'files': 0, 'metadata': 0}, get_children=True)
permchecker = self._get_permchecker(cont)
permchecker(noop)('GET', cid)
children = cont.get('acquisitions')
if not children:
return {}
id_array = [str(c['_id']) for c in children]
cont_array = [containerutil.ContainerReference('acquisition', cid) for cid in id_array]
states = self.request.GET.getall('states')
tags = self.request.GET.getall('tags')
jobs = Queue.search(cont_array, states=states, tags=tags)
response = {}
for j in jobs:
job = Job.load(j)
acqs = [] # acquisitions referenced by the current job inputs
for _,v in job.inputs.iteritems():
# Add job to the list of jobs for an acquisition if:
# - the input refers to an acquisition on this session
# - the job has not already been added to that acquisition's job array
if v.type == 'acquisition' and v.id in id_array and v.id not in acqs:
if response.get(v.id) is not None:
response[v.id].append(job)
else:
response[v.id] = [job]
acqs.append(v.id)
analyses = cont.get('analyses', [])
acquisitions = cont.get('acquisitions', [])
results = []
if not acquisitions and not analyses:
# no jobs
return {'jobs': results}
# Get query params
states = self.request.GET.getall('states')
tags = self.request.GET.getall('tags')
join_cont = 'containers' in self.request.params.getall('join')
# search for jobs
if acquisitions:
id_array = [str(c['_id']) for c in acquisitions]
cont_array = [containerutil.ContainerReference('acquisition', cid) for cid in id_array]
results += Queue.search(cont_array, states=states, tags=tags)
if analyses:
id_array = [str(c['_id']) for c in analyses]
cont_array = [containerutil.ContainerReference('analysis', cid) for cid in id_array]
results += Queue.search(cont_array, states=states, tags=tags)
# Ensure job uniqueness
seen_jobs = []
jobs = []
for j in results:
if j['_id'] not in seen_jobs:
job = Job.load(j)
jobs.append(job)
seen_jobs.append(job.id_)
jobs.sort(key=lambda j: j.created)
response = {'jobs': jobs}
if join_cont:
# create a map of analyses and acquisitions by _id
containers = dict((str(c['_id']), c) for c in analyses+acquisitions)
response['containers'] = containers
return response
......
{
"57ebe5adf0a2c90027d2bd44": [
{
"inputs": {
"dicom": {
"type": "acquisition",
"id": "57ebe5adf0a2c90027d2bd44",
"name": "1_1_dicom.zip"
}
},
"attempt": 1,
"name": "dcm_convert",
"tags": [
"dcm_convert",
"spectroscopy"
],
"destination": {
"type": "acquisition",
"id": "57ebe5adf0a2c90027d2bd44"
},
"request": {
"inputs": [
{
"type": "scitran",
"uri": "/jobs/57ebe5adf0a2c90027d2bd48/config.json",
"location": "/flywheel/v0"
},
{
"type": "scitran",
"uri": "/acquisitions/57ebe5adf0a2c90027d2bd44/files/1_1_dicom.zip",
"location": "/flywheel/v0/input/dicom"
}
],
"target": {
"command": [
"bash",
"-c",
"rm -rf output; mkdir -p output; ./run; echo \"Exit was $?\""
],
"env": {
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
},
"dir": "/flywheel/v0"
},
"outputs": [
{
"type": "scitran",
"uri": "/engine?level=acquisition&id=57ebe5adf0a2c90027d2bd44&job=57ebe5adf0a2c90027d2bd48",
"location": "/flywheel/v0/output"
}
]
},
"modified": "2016-09-28T15:45:52.607000+00:00",
"created": "2016-09-28T15:45:49.975000+00:00",
"state": "running",
"config": {},
"id": "57ebe5adf0a2c90027d2bd48"
"jobs": [
{
"origin": {
"type": "system",
"id": null
},
"inputs": {
"dcm2niix": {
"type": "acquisition",
"id": "582cbe5a5740eb00162cf3d2",
"name": "6879_1_2_localizer.dicom.zip"
}
]
},
"attempt": 1,
"name": "dcm2niix",
"tags": [
"dcm2niix"
],
"destination": {
"type": "acquisition",
"id": "582cbe5a5740eb00162cf3d2"
},
"modified": "2016-11-16T20:15:22.742000+00:00",
"created": "2016-11-16T20:15:22.742000+00:00",
"saved_files": [],
"state": "pending",
"config": null,
"id": "582cbe5a5740eb00162cf3d3"
},
{
"origin": {
"type": "system",
"id": null
},
"inputs": {
"dicom": {
"type": "acquisition",
"id": "582cbe5a5740eb00162cf3d2",
"name": "6879_1_2_localizer.dicom.zip"
}
},
"attempt": 1,
"name": "dicom-mr-classifier",
"tags": [
"dicom-mr-classifier"
],
"destination": {
"type": "acquisition",
"id": "582cbe5a5740eb00162cf3d2"
},
"modified": "2016-11-16T20:15:22.756000+00:00",
"created": "2016-11-16T20:15:22.756000+00:00",
"saved_files": [],
"state": "pending",
"config": null,
"id": "582cbe5a5740eb00162cf3d4"
},
{
"origin": {
"type": "system",
"id": null
},
"inputs": {
"dcm2niix": {
"type": "acquisition",
"id": "582cbe5d5740eb00132cf3d6",
"name": "6879_3_1_t1.dicom.zip"
}
},
"attempt": 1,
"name": "dcm2niix",
"tags": [
"dcm2niix"
],
"destination": {
"type": "acquisition",
"id": "582cbe5d5740eb00132cf3d6"
},
"modified": "2016-11-16T20:15:25.899000+00:00",
"created": "2016-11-16T20:15:25.899000+00:00",
"saved_files": [],
"state": "pending",
"config": null,
"id": "582cbe5d5740eb00132cf3d7"
}
],
"containers": {
"582cbe5a5740eb00162cf3d2": {
"created": "2016-11-16T20:15:22.629000+00:00",
"modified": "2016-11-16T20:15:22.629000+00:00",
"label": "6879_1_2_localizer",
"session": "582cbe5a5740eb00162cf3d1",
"_id": "582cbe5a5740eb00162cf3d2",
"public": false
},
"582cbe5d5740eb00132cf3d6": {
"created": "2016-11-16T20:15:25.858000+00:00",
"modified": "2016-11-16T20:15:25.858000+00:00",
"label": "6879_3_1_t1",
"session": "582cbe5a5740eb00162cf3d1",
"_id": "582cbe5d5740eb00132cf3d6",
"public": false
}
}
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"patternProperties": {
"^[a-fA-F0-9]{24}$":{
"properties":{
"jobs":{
"type":"array",
"items":{
"type":"object",
......@@ -27,6 +27,13 @@
"destination", "tags", "state", "attempt"
]
}
},
"containers":{
"patternProperties": {
"^[a-fA-F0-9]{24}$":{
"type": "object"
}
}
}
},
"additionalProperties":false
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment