Skip to content
Snippets Groups Projects
Commit 451dfc12 authored by Kevin S. Hahn's avatar Kevin S. Hahn
Browse files

create jobs based on available compatible app

parent c7eae249
No related branches found
No related tags found
No related merge requests found
...@@ -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 any special values in the app description # XXX: outputs can specify 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=''):
......
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