Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
489cfcd9
Commit
489cfcd9
authored
8 years ago
by
Nathaniel Kofalt
Browse files
Options
Downloads
Patches
Plain Diff
Add /gears and /gears/x
parent
16d33124
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/api.py
+5
-1
5 additions, 1 deletion
api/api.py
api/jobs/gears.py
+23
-6
23 additions, 6 deletions
api/jobs/gears.py
api/jobs/handlers.py
+109
-0
109 additions, 0 deletions
api/jobs/handlers.py
with
137 additions
and
7 deletions
api/api.py
+
5
−
1
View file @
489cfcd9
...
...
@@ -9,7 +9,7 @@ import webapp2_extras.routes
from
.
import
base
from
.jobs.jobs
import
Job
from
.jobs.handlers
import
JobsHandler
,
JobHandler
from
.jobs.handlers
import
JobsHandler
,
JobHandler
,
GearsHandler
,
GearHandler
from
.dao.containerutil
import
FileReference
,
ContainerReference
from
.
import
encoder
from
.
import
root
...
...
@@ -210,6 +210,10 @@ routes = [
webapp2
.
Route
(
r
'
/add
'
,
JobsHandler
,
handler_method
=
'
add
'
,
methods
=
[
'
POST
'
]),
webapp2
.
Route
(
r
'
/<:[^/]+>
'
,
JobHandler
,
name
=
'
job
'
),
]),
webapp2
.
Route
(
r
'
/api/gears
'
,
GearsHandler
),
webapp2_extras
.
routes
.
PathPrefixRoute
(
r
'
/api/gears
'
,
[
webapp2
.
Route
(
r
'
/<:[^/]+>
'
,
GearHandler
,
name
=
'
job
'
),
]),
webapp2
.
Route
(
r
'
/api/groups
'
,
grouphandler
.
GroupHandler
,
handler_method
=
'
get_all
'
,
methods
=
[
'
GET
'
]),
webapp2
.
Route
(
r
'
/api/groups
'
,
grouphandler
.
GroupHandler
,
methods
=
[
'
POST
'
]),
webapp2
.
Route
(
_format
(
r
'
/api/groups/<_id:{group_id_re}>
'
),
grouphandler
.
GroupHandler
,
name
=
'
group_details
'
),
...
...
This diff is collapsed.
Click to expand it.
api/jobs/gears.py
+
23
−
6
View file @
489cfcd9
...
...
@@ -6,27 +6,44 @@ from .. import config
log
=
config
.
log
# For now, gears are in a singleton, prefixed by a key
SINGLETON_KEY
=
'
gear_list
'
def
get_gears
():
def
get_gears
(
fields
=
None
):
"""
Fetch the install-global gears from the database
"""
gear_doc
=
config
.
db
.
singletons
.
find_one
({
'
_id
'
:
'
gears
'
})
return
gear_doc
[
'
gear_list
'
]
projection
=
{
}
if
fields
is
None
:
fields
=
[
]
projection
=
{
SINGLETON_KEY
:
1
}
else
:
fields
.
append
(
'
name
'
)
query
=
{
'
_id
'
:
'
gears
'
}
for
f
in
fields
:
projection
[
SINGLETON_KEY
+
'
.
'
+
f
]
=
1
gear_doc
=
config
.
db
.
singletons
.
find_one
(
query
,
projection
)
# print gear_doc
return
gear_doc
[
SINGLETON_KEY
]
def
get_gear_by_name
(
name
):
# Find a gear from the list by name
gear_doc
=
config
.
db
.
singletons
.
find_one
(
{
'
_id
'
:
'
gears
'
},
{
'
gear_list
'
:
{
'
$elemMatch
'
:
{
{
SINGLETON_KEY
:
{
'
$elemMatch
'
:
{
'
name
'
:
name
}}
})
if
gear_doc
is
None
:
if
gear_doc
is
None
or
gear_doc
.
get
(
SINGLETON_KEY
)
is
None
:
raise
Exception
(
'
Unknown gear
'
+
name
)
# Mongo returns the full document: { '_id' : 'gears', 'gear_list' : [ { .. } ] }, so strip that out
return
gear_doc
[
'
gear_list
'
][
0
]
return
gear_doc
[
SINGLETON_KEY
][
0
]
This diff is collapsed.
Click to expand it.
api/jobs/handlers.py
+
109
−
0
View file @
489cfcd9
...
...
@@ -7,12 +7,121 @@ from ..dao.containerutil import create_filereference_from_dictionary, create_con
from
..
import
base
from
..
import
config
from
.gears
import
get_gears
,
get_gear_by_name
from
.jobs
import
Job
from
.queue
import
Queue
log
=
config
.
log
class
GearsHandler
(
base
.
RequestHandler
):
"""
Provide /gears API routes.
"""
def
get
(
self
):
"""
.. http:get:: /api/gears
List all gears.
:query fields: filter fields returned. Defaults to [
'
name
'
]. Pass
'
all
'
for everything.
:type fields: string
:statuscode 200: no error
**Example request**:
.. sourcecode:: http
GET /api/gears 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
[
{
"
name
"
:
"
dicom_mr_classifier
"
},
{
"
name
"
:
"
dcm_convert
"
},
{
"
name
"
:
"
qa-report-fmri
"
}
]
"""
if
self
.
public_request
:
self
.
abort
(
403
,
'
Request requires login
'
)
fields
=
self
.
request
.
GET
.
getall
(
'
fields
'
)
if
'
all
'
in
fields
:
fields
=
None
return
get_gears
(
fields
)
class
GearHandler
(
base
.
RequestHandler
):
"""
Provide /gears/x API routes.
"""
def
get
(
self
,
_id
):
"""
.. http:get:: /api/gears/(gid)
Detail a gear.
:statuscode 200: no error
**Example request**:
.. sourcecode:: http
GET /api/gears/dcm_convert 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
{
"
name
"
:
"
dcm_convert
"
"
manifest
"
: {
"
config
"
: {},
"
inputs
"
: {
"
dicom
"
: {
"
base
"
:
"
file
"
,
"
type
"
: {
"
enum
"
: [
"
dicom
"
]
}
}
},
},
}
"""
if
self
.
public_request
:
self
.
abort
(
403
,
'
Request requires login
'
)
return
get_gear_by_name
(
_id
)
class
JobsHandler
(
base
.
RequestHandler
):
"""
Provide /jobs API routes.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment