Skip to content

Commit

Permalink
Validate job on batch propose
Browse files Browse the repository at this point in the history
  • Loading branch information
hkethi002 committed Feb 12, 2018
1 parent 456fa3e commit 10b1fa0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
10 changes: 10 additions & 0 deletions api/jobs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,16 @@ def post_with_jobs(self):
payload = self.request.json
jobs_ = payload.get('jobs', [])

uid = None
if not self.superuser_request:
uid = self.uid

for job_number, job_ in enumerate(jobs_):
try:
Queue.validate_job(job_, self.origin, create_job=False, perm_check_uid=uid)
except InputValidationException as e:
raise InputValidationException("Job {}: {}".format(job_number, str(e)))

batch_proposal = {
'proposal': {
'preconstructed_jobs': jobs_
Expand Down
16 changes: 12 additions & 4 deletions api/jobs/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ def retry(job, force=False):

return new_id


@staticmethod
def enqueue_job(job_map, origin, perm_check_uid=None):
def validate_job(job_map, origin, create_job=False, perm_check_uid=None):
"""
Using a payload for a proposed job, creates and returns (but does not insert)
Using a payload for a proposed job, creates and returns(if create_job is True) (but does not insert)
a Job object. This preperation includes:
- confirms gear exists
- validates config against gear manifest
Expand Down Expand Up @@ -251,8 +250,17 @@ def enqueue_job(job_map, origin, perm_check_uid=None):

if gear_name not in tags:
tags.append(gear_name)
if create_job:
job = Job(str(gear['_id']), inputs, destination=destination, tags=tags, config_=config_, now=now_flag, attempt=attempt_n, previous_job_id=previous_job_id, origin=origin, batch=batch)
return job
return True

job = Job(str(gear['_id']), inputs, destination=destination, tags=tags, config_=config_, now=now_flag, attempt=attempt_n, previous_job_id=previous_job_id, origin=origin, batch=batch)
@staticmethod
def enqueue_job(job_map, origin, perm_check_uid=None):
"""
Validates, Creates, Inserts, and Returns job
"""
job = Queue.validate_job(job_map, origin, create_job=True, perm_check_uid=perm_check_uid)
job.insert()
return job

Expand Down
24 changes: 24 additions & 0 deletions tests/integration_tests/python/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ def test_batch(data_builder, as_user, as_admin, as_root):
assert r.ok
analysis_batch_id = r.json()['_id']

# try to create a batch with invalid preconstructed jobs
r = as_admin.post('/batch/jobs', json={
'jobs': [
{
'gear_id': gear,
'inputs': {
'dicom': {
'type': 'acquisition',
'id': acquisition,
'name': 'test.zip'
}
},
'config': { 'two-digit multiple of ten': 20 },
'destination': {
'type': 'acquisition',
'id': acquisition
},
'tags': [ 'test-tag' ]
}
]
})
assert r.status_code == 400
assert "Job 0" in r.json().get('message')

# create a batch with preconstructed jobs
r = as_admin.post('/batch/jobs', json={
'jobs': [
Expand Down

0 comments on commit 10b1fa0

Please sign in to comment.