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
451dfc12
Commit
451dfc12
authored
9 years ago
by
Kevin S. Hahn
Browse files
Options
Downloads
Patches
Plain Diff
create jobs based on available compatible app
parent
c7eae249
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
util.py
+69
-70
69 additions, 70 deletions
util.py
with
69 additions
and
70 deletions
util.py
+
69
−
70
View file @
451dfc12
...
@@ -4,10 +4,12 @@ import logging
...
@@ -4,10 +4,12 @@ import logging
log
=
logging
.
getLogger
(
'
scitran.api
'
)
log
=
logging
.
getLogger
(
'
scitran.api
'
)
import
os
import
os
import
json
import
bson
import
bson
import
copy
import
copy
import
shutil
import
shutil
import
difflib
import
difflib
import
tarfile
import
datetime
import
datetime
import
mimetypes
import
mimetypes
import
tempdir
as
tempfile
import
tempdir
as
tempfile
...
@@ -151,81 +153,78 @@ def _update_db(db, dataset):
...
@@ -151,81 +153,78 @@ def _update_db(db, dataset):
# TODO: create job should be use-able from bootstrap.py with only database information
# TODO: create job should be use-able from bootstrap.py with only database information
def
create_job
(
dbc
,
dataset
):
def
create_job
(
dbc
,
dataset
):
db
=
dbc
.
database
db
=
dbc
.
database
type_
=
dataset
.
nims_file_type
type_
=
dataset
.
nims_file_type
kinds_
=
dataset
.
nims_file_kinds
kinds_
=
dataset
.
nims_file_kinds
state_
=
dataset
.
nims_file_state
state_
=
dataset
.
nims_file_state
app
=
None
app
=
None
# TODO: check if there are 'default apps' set for this project/session/acquisition
# TODO: check if there are 'default apps' set for this project/session/acquisition
acquisition
=
db
.
acquisitions
.
find_one
({
'
uid
'
:
dataset
.
nims_acquisition_id
})
acquisition
=
db
.
acquisitions
.
find_one
({
'
uid
'
:
dataset
.
nims_acquisition_id
})
session
=
db
.
sessions
.
find_one
({
'
_id
'
:
bson
.
ObjectId
(
acquisition
.
get
(
'
session
'
))})
session
=
db
.
sessions
.
find_one
({
'
_id
'
:
bson
.
ObjectId
(
acquisition
.
get
(
'
session
'
))})
project
=
db
.
projects
.
find_one
({
'
_id
'
:
bson
.
ObjectId
(
session
.
get
(
'
project
'
))})
project
=
db
.
projects
.
find_one
({
'
_id
'
:
bson
.
ObjectId
(
session
.
get
(
'
project
'
))})
aid
=
acquisition
.
get
(
'
_id
'
)
aid
=
acquisition
.
get
(
'
_id
'
)
# job descriptions have a few special cases
# XXX: if an input kinds = None, then that job is meant to work on any file kinds
# XXX: outputs can specify to __INHERIT__ a value from the parent input file, for ex: kinds
app
=
db
.
apps
.
find_one
({
# XXX: if an input kinds = None, then that job is meant to work on any file kinds
'
$or
'
:
[
# otherwise, kinds will restrict the app to work on specific kinds only
{
'
inputs
'
:
{
'
$elemMatch
'
:
{
'
type
'
:
type_
,
'
state
'
:
state_
,
'
kinds
'
:
kinds_
}},
'
default
'
:
True
},
app
=
db
.
apps
.
find_one
({
{
'
inputs
'
:
{
'
$elemMatch
'
:
{
'
type
'
:
type_
,
'
state
'
:
state_
,
'
kinds
'
:
None
}},
'
default
'
:
True
},
'
$or
'
:
[
],
{
'
inputs
'
:
{
'
$elemMatch
'
:
{
'
type
'
:
type_
,
'
state
'
:
state_
,
'
kinds
'
:
kinds_
}},
'
default
'
:
True
},
})
{
'
inputs
'
:
{
'
$elemMatch
'
:
{
'
type
'
:
type_
,
'
state
'
:
state_
,
'
kinds
'
:
None
}},
'
default
'
:
True
},
# TODO: this has to move...
],
# force acquisition dicom file to be marked as 'optional = True'
})
db
.
acquisitions
.
find_and_modify
(
# TODO: this has to move...
{
'
uid
'
:
dataset
.
nims_acquisition_id
,
'
files.type
'
:
'
dicom
'
},
# force acquisition dicom file to be marked as 'optional = True'
{
'
$set
'
:
{
'
files.$.optional
'
:
True
}},
db
.
acquisitions
.
find_and_modify
(
)
{
'
uid
'
:
dataset
.
nims_acquisition_id
,
'
files.type
'
:
'
dicom
'
},
{
'
$set
'
:
{
'
files.$.optional
'
:
True
}},
)
if
not
app
:
if
not
app
:
log
.
info
(
'
no app for type=%s, state=%s, kinds=%s, default=True. no job created.
'
%
(
type_
,
state_
,
kinds_
))
log
.
info
(
'
no app for type=%s, state=%s, kinds=%s, default=True. no job created.
'
%
(
type_
,
state_
,
kinds_
))
else
:
else
:
# replace
an
y
speci
al values in the app description
# XXX: outputs c
an speci
fy to __INHERIT__ a value from the parent input file, for ex: kinds
for
output
in
app
[
'
outputs
'
]:
for
output
in
app
[
'
outputs
'
]:
if
output
[
'
kinds
'
]
==
'
__INHERIT__
'
:
if
output
[
'
kinds
'
]
==
'
__INHERIT__
'
:
output
[
'
kinds
'
]
=
kinds_
output
[
'
kinds
'
]
=
kinds_
# TODO: job description needs more metadata to be searchable in a useful way
# TODO: job description needs more metadata to be searchable in a useful way
output_url
=
'
%s/%s/%s
'
%
(
'
acquisitions
'
,
aid
,
'
file
'
)
output_url
=
'
%s/%s/%s
'
%
(
'
acquisitions
'
,
aid
,
'
file
'
)
job
=
db
.
jobs
.
find_and_modify
(
job
=
db
.
jobs
.
find_and_modify
(
{
{
'
_id
'
:
db
.
jobs
.
count
()
+
1
,
'
_id
'
:
db
.
jobs
.
count
()
+
1
,
},
{
'
_id
'
:
db
.
jobs
.
count
()
+
1
,
'
group
'
:
project
.
get
(
'
group_id
'
),
'
project
'
:
{
'
_id
'
:
project
.
get
(
'
_id
'
),
'
name
'
:
project
.
get
(
'
name
'
),
},
},
{
'
exam
'
:
session
.
get
(
'
exam
'
),
'
_id
'
:
db
.
jobs
.
count
()
+
1
,
'
app
'
:
{
'
group
'
:
project
.
get
(
'
group_id
'
),
'
_id
'
:
app
[
'
_id
'
],
'
project
'
:
{
'
type
'
:
'
docker
'
,
'
_id
'
:
project
.
get
(
'
_id
'
),
'
name
'
:
project
.
get
(
'
name
'
),
},
'
exam
'
:
session
.
get
(
'
exam
'
),
'
app
'
:
{
'
_id
'
:
app
[
'
_id
'
],
'
type
'
:
'
docker
'
,
},
'
inputs
'
:
[
{
'
filename
'
:
dataset
.
nims_file_name
+
dataset
.
nims_file_ext
,
'
url
'
:
'
%s/%s/%s
'
%
(
'
acquisitions
'
,
aid
,
'
file
'
),
'
payload
'
:
{
'
type
'
:
dataset
.
nims_file_type
,
'
state
'
:
dataset
.
nims_file_state
,
'
kinds
'
:
dataset
.
nims_file_kinds
,
},
}
],
'
outputs
'
:
[{
'
url
'
:
output_url
,
'
payload
'
:
i
}
for
i
in
app
[
'
outputs
'
]],
'
status
'
:
'
pending
'
,
'
activity
'
:
None
,
'
added
'
:
datetime
.
datetime
.
now
(),
'
timestamp
'
:
datetime
.
datetime
.
now
(),
},
},
upsert
=
True
,
'
inputs
'
:
[
new
=
True
,
{
)
'
filename
'
:
dataset
.
nims_file_name
+
dataset
.
nims_file_ext
,
log
.
info
(
'
created job %d, group: %s, project %s
'
%
(
job
[
'
_id
'
],
job
[
'
group
'
],
job
[
'
project
'
]))
'
url
'
:
'
%s/%s/%s
'
%
(
'
acquisitions
'
,
aid
,
'
file
'
),
'
payload
'
:
{
'
type
'
:
dataset
.
nims_file_type
,
'
state
'
:
dataset
.
nims_file_state
,
'
kinds
'
:
dataset
.
nims_file_kinds
,
},
}
],
'
outputs
'
:
[{
'
url
'
:
output_url
,
'
payload
'
:
i
}
for
i
in
app
[
'
outputs
'
]],
'
status
'
:
'
pending
'
,
'
activity
'
:
None
,
'
added
'
:
datetime
.
datetime
.
now
(),
'
timestamp
'
:
datetime
.
datetime
.
now
(),
},
upsert
=
True
,
new
=
True
,
)
log
.
info
(
'
created job %d, group: %s, project %s
'
%
(
job
[
'
_id
'
],
job
[
'
group
'
],
job
[
'
project
'
]))
def
_entity_metadata
(
dataset
,
properties
,
metadata
=
{},
parent_key
=
''
):
def
_entity_metadata
(
dataset
,
properties
,
metadata
=
{},
parent_key
=
''
):
...
...
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