-
Notifications
You must be signed in to change notification settings - Fork 24
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
Scottx611x/td api #1646
Scottx611x/td api #1646
Changes from 9 commits
d7283b8
c09101a
c38f042
59bb514
facf9cb
1222f9c
87101a8
41a51c8
1fbca66
28279fb
d73351b
be166d8
ab0ac77
363c8f6
3c39ee5
6287456
bcce1d9
daca73f
aff4cf6
d1d36fa
8a8dbae
28deb1d
6419461
2e080fb
c8d0d16
c3b3ba8
f5b1de1
bc77da6
27a82db
8eb8879
d3edcfc
e6b954e
e90af1f
15d2f18
f4590cb
8971349
2aacd03
51d955c
5d1f4c8
c979136
ea8cdec
07251e7
bf02ed2
f1ae2d7
8336ef5
6f28f41
23d37a1
f177930
fa9f485
9e1c4a8
3242119
2647818
3b6ad6b
1623937
4f8cfd7
a7c4b75
c3fca54
48707a3
cfd104b
db33295
6cdccda
d4fd011
006e551
0c727cc
913455e
2de1b66
87023b0
0af9971
d6e1b7a
421abdd
8fce240
bcae244
b6e20c8
a7ff7b1
b34d0b6
84676cf
b858c70
9b018e0
a8c7f9d
69649f7
a2cdebd
36c820a
06d8332
2baf249
15ea435
5fd9852
8f82bbd
a3ca888
1de07b3
118f62a
cb65e95
b3bac64
90c3d56
2875042
7d511c8
8929648
5491437
0263c69
9c0fbba
dbc0f4a
1449939
5650d80
3da2ff7
fde1752
58107fd
3093562
b0421f7
94ea941
afff031
cbbfbb9
c73105e
cfbce11
bdfa736
3291651
dc9bef1
1996b8f
a09ee70
852f5d9
549862a
7c7d30c
da1f038
e3e644c
7738c53
7c5cd7e
7bc45f1
106d43b
dd7ffa9
cfaad38
740f2ee
a6e3ecb
f9c206b
40f181e
b903e46
4db9a18
3037a04
efa40da
8436ee4
3433517
3aef070
ae9f73b
3eabca3
2e3b0eb
a4737c4
3772af3
85de57a
bcf09b0
b31256b
e0e3fd9
8c8818c
204ced5
cbc2c2b
f52ef0e
8264aca
acdfe17
75d039c
e5d883c
9035f0d
36194b4
b211363
f01770d
020ab4c
0f2f533
4be4659
8cd7d1b
ee5f751
77ae8eb
6ba02ad
673827a
9fa0a9c
356da7e
6ffb5b6
4ebcf91
15ae348
ff2f90f
67db7f9
43d1932
cbe6d0f
9ed6fa6
4c32710
288114d
b84846c
3c1ad77
069813b
39b31dc
2d9f960
dbf6bd1
ced8135
b6d7da9
0d652f2
6bf9171
24b75cf
2906380
0bb914e
150ee06
e7e1d86
8caef8b
00b8c02
10ab388
98e853a
5683d1c
ffbb95a
655e186
13d7544
daeda15
ec4d9e8
b34d0ff
1e68ebe
cd5f6a1
e42a70c
606b684
1ae885a
ca47321
dd8624f
711b4c3
a309026
97992e6
47857b4
b6842e6
f7d1c6b
baa1448
115867d
f9fbcb2
70c902d
7bdf956
b3f42ef
de9cde5
ceea62a
bef5a2f
4ec44f3
fa065ed
2a6e5b4
379b72d
fab910b
c470b49
197af3f
98821e7
c182855
8be855c
c7a195b
960338c
6e027d8
3c006ea
e1d4f79
cb0d526
7bce4a6
69d5c65
524734d
2c82cde
b837dee
cdc401e
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 |
---|---|---|
|
@@ -3,12 +3,10 @@ | |
|
||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from bioblend.galaxy.client import ConnectionError | ||
|
||
from core.models import WorkflowEngine | ||
from tool_manager.models import ToolDefinition | ||
from ...utils import (ANNOTATION_ERROR_MESSAGE, | ||
create_tool_definition, | ||
get_workflow_list, | ||
validate_tool_annotation, | ||
validate_workflow_step_annotation) | ||
|
||
|
@@ -27,138 +25,108 @@ def handle(self, **options): | |
Workflows. | ||
""" | ||
sys.stdout.write("Generating ToolDefinitions\n") | ||
workflow_engines = WorkflowEngine.objects.all() | ||
sys.stdout.write("{} workflow engines found.\n".format( | ||
workflow_engines.count()) | ||
) | ||
|
||
for engine in workflow_engines: | ||
sys.stdout.write( | ||
"Generating ToolDefinitions from workflow engine {}\n" | ||
.format(engine.name) | ||
) | ||
workflow_list = get_workflow_list() | ||
|
||
# Validate workflow annotation data, and try to create a | ||
# ToolDefinition if validation passes. | ||
|
||
galaxy_connection = engine.instance.galaxy_connection() | ||
for workflow in workflow_list: | ||
workflow["tool_type"] = ToolDefinition.WORKFLOW | ||
try: | ||
workflow_list = galaxy_connection.workflows.get_workflows() | ||
except ConnectionError as e: | ||
workflow["annotation"] = json.loads( | ||
workflow["annotation"] | ||
) | ||
except ValueError as e: | ||
raise CommandError( | ||
"Unable to retrieve workflows from '{}'. " | ||
"Skipping ToolDefinition generation: {}".format( | ||
engine.instance.base_url, e) | ||
"Workflow: {}'s annotation is not " | ||
"valid JSON: {}".format(workflow["name"], e) | ||
) | ||
|
||
# Validate workflow annotation data, and try to create a | ||
# ToolDefinition if validation passes. | ||
# Include `parameters` and `output_files` as keys in our | ||
# workflow annotation | ||
workflow["annotation"]["parameters"] = [] | ||
workflow["annotation"]["output_files"] = [] | ||
|
||
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. It might make more sense to get the list of all the workflows from all the engines first to avoid an extra indentation level. It might also be helpful to factor out this functionality into a separate re-useable utility function. |
||
for workflow in workflow_list: | ||
workflow_data = galaxy_connection.workflows.show_workflow( | ||
workflow["id"] | ||
) | ||
workflow_data["tool_type"] = ToolDefinition.WORKFLOW | ||
try: | ||
workflow_data["annotation"] = json.loads( | ||
workflow_data["annotation"] | ||
) | ||
except ValueError as e: | ||
raise CommandError( | ||
"Workflow: {}'s annotation is not " | ||
"valid JSON: {}".format(workflow_data["name"], e) | ||
) | ||
|
||
# Include `parameters` and `output_files` as keys in our | ||
# workflow annotation | ||
workflow_data["annotation"]["parameters"] = [] | ||
workflow_data["annotation"]["output_files"] = [] | ||
# Iterate through the workflow's step's annotations and | ||
# append to the `parameters` and `output_files` lists from | ||
# above so they are included in the validation of this | ||
# workflow's annotation data | ||
for step_index in workflow["steps"]: | ||
step = workflow["steps"][step_index] | ||
|
||
# Iterate through the workflow's step's annotations and | ||
# append to the `parameters` and `output_files` lists from | ||
# above so they are included in the validation of this | ||
# workflow's annotation data | ||
for step_index in workflow_data["steps"]: | ||
step = workflow_data["steps"][step_index] | ||
# Check if any annotation provided, and try to convert | ||
# to python dict if so | ||
if step["annotation"]: | ||
try: | ||
step_annotation = json.loads(step["annotation"]) | ||
except ValueError as e: | ||
raise CommandError( | ||
"Workflow: {}'s Step: {}'s annotation data" | ||
" is not valid JSON: {}".format( | ||
workflow_data["name"], step_index, e | ||
) | ||
if step["annotation"]: | ||
try: | ||
step_annotation = json.loads(step["annotation"]) | ||
except ValueError as e: | ||
raise CommandError( | ||
"Workflow: {}'s Step: {}'s annotation data" | ||
" is not valid JSON: {}".format( | ||
workflow["name"], | ||
step_index, | ||
e | ||
) | ||
try: | ||
validate_workflow_step_annotation( | ||
step_annotation | ||
) | ||
try: | ||
validate_workflow_step_annotation( | ||
step_annotation | ||
) | ||
except RuntimeError as e: | ||
raise CommandError( | ||
"{} {}".format(ANNOTATION_ERROR_MESSAGE, e) | ||
) | ||
except RuntimeError as e: | ||
try: | ||
parameters = step_annotation["parameters"] | ||
except KeyError: | ||
# `parameters` aren't required for each workflow step | ||
pass | ||
|
||
for parameter in parameters: | ||
# Check User-defined parameters in | ||
# annotation data against the available | ||
# parameters of the Workflow step's | ||
# `tool_inputs` | ||
if parameter["name"] not in step["tool_inputs"]: | ||
raise CommandError( | ||
"{} {}".format(ANNOTATION_ERROR_MESSAGE, e) | ||
"{} is not a valid parameter for {}". | ||
format( | ||
parameter["name"], | ||
step["tool_id"] | ||
) | ||
try: | ||
parameters = step_annotation["parameters"] | ||
except KeyError: | ||
# Since we've already validated the Workflow | ||
# step's annotation, and a Step Annotation | ||
# doesn't necessarily need to have | ||
# `parameters` we can pass here without | ||
# raising an exception | ||
pass | ||
else: | ||
for parameter in parameters: | ||
# Check User-defined parameters in | ||
# annotation data against the available | ||
# parameters of the Workflow step's | ||
# `tool_inputs` | ||
if (not parameter["name"] in | ||
step["tool_inputs"]): | ||
raise RuntimeError( | ||
"{} is not a valid parameter for {}". | ||
format( | ||
parameter["name"], | ||
step["tool_id"] | ||
) | ||
) | ||
else: | ||
parameter["galaxy_workflow_step"] = int( | ||
step_index | ||
) | ||
workflow_data["annotation"]["parameters"]\ | ||
.append(parameter) | ||
try: | ||
output_files = step_annotation["output_files"] | ||
except KeyError: | ||
# Since we've already validated the Workflow | ||
# step's annotation, and a Step Annotation | ||
# doesn't necessarily need to have | ||
# `output_files` we can pass here without | ||
# raising an exception | ||
pass | ||
) | ||
else: | ||
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. Not needed. Removing will help reduce indentation levels. |
||
for output_file in output_files: | ||
workflow_data["annotation"]["output_files"]\ | ||
.append(output_file) | ||
try: | ||
validate_tool_annotation(workflow_data) | ||
except RuntimeError as e: | ||
raise CommandError(e) | ||
except Exception as e: | ||
raise CommandError( | ||
"Something unexpected happened: {}".format(e) | ||
) | ||
try: | ||
create_tool_definition(workflow_data) | ||
except Exception as e: | ||
raise CommandError( | ||
"Creation of ToolDefinition failed. Database " | ||
"rolled back to its state before this " | ||
"ToolDefinition's attempted creation: {}".format(e) | ||
) | ||
else: | ||
sys.stdout.write( | ||
"\nGenerated ToolDefinition for: {}\n".format( | ||
workflow_data["name"] | ||
parameter["galaxy_workflow_step"] = int( | ||
step_index | ||
) | ||
workflow["annotation"]["parameters"]\ | ||
.append(parameter) | ||
try: | ||
output_files = step_annotation["output_files"] | ||
except KeyError: | ||
# `ouput_files` aren't required for each workflow step | ||
pass | ||
|
||
for output_file in output_files: | ||
workflow["annotation"]["output_files"].append( | ||
output_file | ||
) | ||
) | ||
try: | ||
validate_tool_annotation(workflow) | ||
except RuntimeError as e: | ||
raise CommandError(e) | ||
except Exception as e: | ||
raise CommandError( | ||
"Something unexpected happened: {}".format(e) | ||
) | ||
try: | ||
create_tool_definition(workflow) | ||
except Exception as e: | ||
raise CommandError( | ||
"Creation of ToolDefinition failed. Database " | ||
"rolled back to its state before this " | ||
"ToolDefinition's attempted creation: {}".format(e) | ||
) | ||
|
||
sys.stdout.write("\nGenerated ToolDefinition for: {}\n".format( | ||
workflow["name"] | ||
)) |
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.
get_workflow_list()
can raise RuntimeError exceptions that should be handled