-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom rule config (+use gear_id) #961
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,10 @@ | |
from __future__ import absolute_import | ||
|
||
import bson.objectid | ||
import copy | ||
import datetime | ||
from jsonschema import Draft4Validator, ValidationError | ||
import gears as gear_tools | ||
import pymongo | ||
|
||
from .. import config | ||
from .jobs import Job | ||
|
@@ -39,17 +39,10 @@ def get_gears(): | |
return map(lambda x: x['original'], cursor) | ||
|
||
def get_gear(_id): | ||
return config.db.gears.find_one({'_id': bson.ObjectId(_id)}) | ||
|
||
def get_gear_by_name(name): | ||
|
||
# Find a gear from the list by name | ||
gear_doc = list(config.db.gears.find({'gear.name': name}).sort('created', pymongo.DESCENDING)) | ||
|
||
if len(gear_doc) == 0 : | ||
raise APINotFoundException('Unknown gear ' + name) | ||
|
||
return gear_doc[0] | ||
gear = config.db.gears.find_one({'_id': bson.ObjectId(_id)}) | ||
if gear is None: | ||
raise APINotFoundException('Cannot find gear {}'.format(_id)) | ||
return gear | ||
|
||
def get_invocation_schema(gear): | ||
return gear_tools.derive_invocation_schema(gear['gear']) | ||
|
@@ -104,13 +97,13 @@ def suggest_for_files(gear, files): | |
return suggested_files | ||
|
||
def validate_gear_config(gear, config_): | ||
if len(gear.get('manifest', {}).get('config', {})) > 0: | ||
invocation = gear_tools.derive_invocation_schema(gear['manifest']) | ||
if len(gear.get('gear', {}).get('config', {})) > 0: | ||
invocation = gear_tools.derive_invocation_schema(gear['gear']) | ||
ci = gear_tools.isolate_config_invocation(invocation) | ||
validator = Draft4Validator(ci) | ||
|
||
try: | ||
validator.validate(config_) | ||
validator.validate(fill_gear_default_values(gear, config_)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaults will be filled when the job is spawned, so I would think we wouldn't fill them here. What is the expected behavior if a gear is updated and the update has a new default that the rule didn't explicitly set? If we fill defaults here, it won't use the updated default. It is possible they wouldn't want to use an updated default without any user action. If I missed a discussion on this, let me know. @kofalt @ambrussimon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that it's a job rule, I would expect valid defaults to be used, rather than invalid ones from a different gear document. Really the core issue here is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I would either not call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, nice catch, that was the original intent... I totally agree, fixing right away. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, but I was asking if we wanted defaults persisted to the database for rule config if the user didn't explicitly send them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nagem I thought it would be best not to store the default config on the rule, and have new jobs simply use potentially updated/new defaults, filled at spawn time. I gathered that's the most useful/expected behavior for now ~ in line with how it works currently. Proper gear versioning is partially in conflict with the "auto-update" feature... At least that's what I thought during implementation. I guess auto-selecting the latest gear on the UI in a dropdown wouldn't be too complicated, either. Anyhow, gear versioning or not, I think not storing the defaults is better. Assuming gears have sane defaults for every version, it just working out of the box after an update (at least if no custom config was set!) seems nice, and that's exactly what Thad wants to hold on to. If the user wants to hardcode the defaults, they are still free to, using the new rule config... |
||
except ValidationError as err: | ||
key = None | ||
if len(err.relative_path) > 0: | ||
|
@@ -128,8 +121,7 @@ def fill_gear_default_values(gear, config_): | |
Given a gear and a config map, fill any missing keys using defaults from the gear's config | ||
""" | ||
|
||
if config_ is None: | ||
config_ = {} | ||
config_ = copy.deepcopy(config_) or {} | ||
|
||
for k,v in gear['gear'].get('config', {}).iteritems(): | ||
if 'default' in v: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[ | ||
{ | ||
"alg" : "dicom_mr_classifier", | ||
"gear_id": "580925ce9e512c57dc8a103c", | ||
"all" : [ | ||
[ | ||
"file.type", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice catch