Skip to content

Commit

Permalink
Add RAML for container based routes
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonlw committed Oct 10, 2016
1 parent a49aaa3 commit 450b27f
Show file tree
Hide file tree
Showing 35 changed files with 550 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ bootstrap.json
.cache
/.coverage*
coverage.xml
node_modules/
2 changes: 1 addition & 1 deletion api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _format(route):
webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>'), containerhandler.ContainerHandler, name='cont_list', handler_method='get_all', methods=['GET']),
webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>'), containerhandler.ContainerHandler, methods=['POST']),
webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>'), containerhandler.ContainerHandler, name='cont_details', methods=['GET','PUT','DELETE']),
webapp2.Route(_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/jobs'), containerhandler.ContainerHandler, name='cont_jobs', handler_method='get_jobs', methods=['GET']),
webapp2.Route(_format(r'/api/sessions/<cid:{cid_re}>/jobs'), containerhandler.ContainerHandler, name='cont_jobs', handler_method='get_jobs', methods=['GET']),

webapp2.Route(_format(r'/api/<cont_name:groups>/<cid:{group_id_re}>/<list_name:roles>'), listhandler.ListHandler, name='group_roles_post'),
webapp2.Route(_format(r'/api/<cont_name:groups>/<cid:{group_id_re}>/<list_name:roles>/<site:{site_id_re}>/<_id:{user_id_re}>'), listhandler.ListHandler, name='group_roles', methods=['GET', 'PUT', 'DELETE']),
Expand Down
2 changes: 2 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def apply_env_variables(config):
])
expected_input_schemas = set([
'acquisition.json',
'acquisition-update.json',
'analysis.json',
'avatars.json',
'collection.json',
Expand All @@ -130,6 +131,7 @@ def apply_env_variables(config):
'packfile.json',
'permission.json',
'project.json',
'project-update.json',
'session.json',
'session-update.json',
'subject.json',
Expand Down
59 changes: 3 additions & 56 deletions api/handlers/containerhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,63 +172,10 @@ def _filter_permissions(self, result, uid, site):
if user_perm.get('access') != 'admin':
result['permissions'] = [user_perm] if user_perm else []

def get_jobs(self, cont_name, cid):
"""
.. http:get:: /api/(cont_name)/(cid)/jobs
Return any jobs that mention this container as an input.
:query states: filter results by job state
:type states: string
:query tags: filter results by job tags
:type cid: string
:statuscode 200: no error
**Example request**:
.. sourcecode:: http
GET /api/sessions/3/jobs?states=pending&states=failed&tags=a&tags=b HTTP/1.1
Host: demo.flywheel.io
Accept: */*
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
Vary: Accept-Encoding
Content-Type: application/json; charset=utf-8
[
{
"_id": "57336257ea360500272c2f11",
"algorithm_id": "dicom_mr_classifier",
"state": "pending",
"tags": [
"a"
]
//...
},
{
"_id": "57336257ea360500272c2f12",
"algorithm_id": "dcm_convert",
"state": "failed",
"tags": [
"b"
]
// ...
}
]
"""

self.config = self.container_handler_configurations[cont_name]
def get_jobs(self, cid):
# Only enabled for sessions container type per url rule in api.py
self.config = self.container_handler_configurations["sessions"]
self.storage = self.config['storage']
if cont_name != 'sessions':
self.abort(400, 'Can only request jobs at the session level.')

cont = self._get_container(cid, projection={'permissions': 0}, get_children=True)
permchecker = self._get_permchecker(cont)
permchecker(noop)('GET', cid)
Expand Down
2 changes: 1 addition & 1 deletion bin/install-dev-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ fi
# Install testing dependencies
echo "Installing testing dependencies"
pip install -r "test/integration_tests/requirements-integration-test.txt"
npm install -g test/integration_tests
npm install test/integration_tests
2 changes: 2 additions & 0 deletions raml/api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ resourceTypes:
/groups: !include resources/groups.raml
/collections: !include resources/collections.raml
/sessions: !include resources/sessions.raml
/acquisitions: !include resources/acquisitions.raml
/projects: !include resources/projects.raml
3 changes: 3 additions & 0 deletions raml/examples/input/acquisition-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label": "example-acquisition-new-label"
}
5 changes: 5 additions & 0 deletions raml/examples/input/acquisition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"label": "example-acquisition",
"session": "57e45328466d8e000e33a85b",
"public": false
}
1 change: 1 addition & 0 deletions raml/examples/input/project-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"label":"test2-project-new-label"}
1 change: 1 addition & 0 deletions raml/examples/input/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"group":"scitran","label":"test2"}
40 changes: 40 additions & 0 deletions raml/examples/output/acquisition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"files": [
{
"origin": {
"method": "importer",
"type": "device",
"id": "importer_Admin_Import",
"name": "Admin Import"
},
"mimetype": "application/zip",
"measurements": [],
"hash": "v0-sha384-dd3c97bfe0ad1fcba75ae6718c6e81038c59af4f447f5db194d52732efa4f955b28455db02eb64cad3e4e55f11e3679f",
"name": "4784_1_1_localizer_dicom.zip",
"tags": [],
"created": "2016-09-21T14:56:09.943000+00:00",
"modified": "2016-09-21T14:56:09.943000+00:00",
"instrument": null,
"metadata": {},
"type": "dicom",
"size": 989933
}
],
"created": "2016-09-21T14:56:10.026000+00:00",
"timestamp": "2016-09-21T19:24:45.539570+00:00",
"modified": "2016-09-21T14:56:10.026000+00:00",
"label": "4784_1_1_localizer",
"session": "57e29f8afab726000f7ec6b1",
"collections": [
"57e2a026675ca0000f0eeb0c"
],
"_id": "57e29f8afab726000f7ec6b2",
"public": false,
"permissions": [
{
"access": "admin",
"_id": "coltonlw@flywheel.io",
"site": "local"
}
]
}
67 changes: 42 additions & 25 deletions raml/examples/output/job-next.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
{
"inputs": [
{
"input": "dicom",
"type": "acquisition",
"id": "57e45279a74e91000ed6898f",
"name": "4784_1_1_localizer_dicom.zip"
}
],
"attempt": 1,
"name": "dcm_convert",
"tags": [
"ad-hoc",
"dcm_convert"
],
"destination": {
"type": "acquisition",
"id": "573c9e6a844eac7fc01747cd"
},
"modified": "2016-08-11T13:02:09.055000+00:00",
"created": "2016-08-11T13:02:09.055000+00:00",
"state": "pending",
"_id": "57ac77515e325c0018cd17cf",
"config":{
"speed":3
}
"inputs": [{
"input": "dicom",
"type": "acquisition",
"id": "57e45279a74e91000ed6898f",
"name": "4784_1_1_localizer_dicom.zip"
}],
"attempt": 1,
"name": "dicom-mr-classifier",
"tags": ["dicom-mr-classifier"],
"destination": {
"type": "acquisition",
"id": "57e45279a74e91000ed6898f"
},
"request": {
"inputs": [{
"vu": "vu0:sha384:tXvdI2pspng-YH6lwa2UcLsww0yR6LfEKbLm89eIqEGicLRHW9d1V8bs7gXHTlZ3",
"type": "http",
"location": "/",
"uri": "https://storage.googleapis.com/flywheel/gears/v1/scitran/dicom-mr-classifier/dicom-mr-classifier_latest_20160803T220847.856417Z.tar.gz"
}, {
"type": "scitran",
"uri": "/acquisitions/57e45279a74e91000ed6898f/files/4784_1_1_localizer_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=57e45279a74e91000ed6898f&job=57e45279a74e91000ed68991",
"location": "/flywheel/v0/output"
}]
},
"modified": "2016-09-28T16:11:36.260000+00:00",
"created": "2016-09-22T21:51:53.174000+00:00",
"state": "running",
"_id": "57e45279a74e91000ed68991",
"config": null
}
60 changes: 60 additions & 0 deletions raml/examples/output/project-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[{
"group": "scitran",
"created": "2016-09-22T21:51:53.151000+00:00",
"modified": "2016-09-22T21:51:53.151000+00:00",
"label": "Neuroscience",
"_id": "57e452791cff88b85f9f9c97",
"public": false,
"permissions": [{
"access": "admin",
"_id": "coltonlw@flywheel.io",
"site": "local"
}]
}, {
"group": "scitran",
"created": "2016-09-22T21:52:27.576000+00:00",
"modified": "2016-09-22T21:52:27.576000+00:00",
"label": "Psychology",
"_id": "57e4529b1cff88b85f9f9c98",
"public": false,
"permissions": [{
"access": "admin",
"_id": "coltonlw@flywheel.io",
"site": "local"
}]
}, {
"group": "scitran",
"created": "2016-09-22T21:52:52.539000+00:00",
"modified": "2016-09-22T21:52:52.539000+00:00",
"label": "Testdata",
"_id": "57e452b41cff88b85f9f9c99",
"public": false,
"permissions": [{
"access": "admin",
"_id": "coltonlw@flywheel.io",
"site": "local"
}]
}, {
"group": "test-group",
"created": "2016-09-22T21:54:47.925000+00:00",
"modified": "2016-09-22T21:54:47.925000+00:00",
"label": "test-project",
"_id": "57e45327466d8e000e33a859",
"public": false,
"permissions": [{
"access": "admin",
"_id": "coltonlw@flywheel.io",
"site": "local"
}]
}, {
"group": "scitran",
"created": "2016-09-29T18:53:06.199000+00:00",
"modified": "2016-09-29T18:53:06.199000+00:00",
"label": "test2",
"_id": "57ed6312466d8e01c91ee427",
"permissions": [{
"access": "admin",
"_id": "coltonlw@flywheel.io",
"site": "local"
}]
}]
13 changes: 13 additions & 0 deletions raml/examples/output/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"group": "scitran",
"created": "2016-09-22T21:51:53.151000+00:00",
"modified": "2016-09-22T21:51:53.151000+00:00",
"label": "Neuroscience",
"_id": "57e452791cff88b85f9f9c97",
"public": false,
"permissions": [{
"access": "admin",
"_id": "coltonlw@flywheel.io",
"site": "local"
}]
}
60 changes: 60 additions & 0 deletions raml/examples/output/session-jobs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"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"
}
]
}
1 change: 0 additions & 1 deletion raml/resourceTypes/container-item.raml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
description: Entity representing a <<resourcePathName|!singularize>>
get:
description: Get a single <<resourcePathName|!singularize>>
responses:
Expand Down

0 comments on commit 450b27f

Please sign in to comment.