-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflask_runner.py
More file actions
177 lines (106 loc) · 4.02 KB
/
flask_runner.py
File metadata and controls
177 lines (106 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from flask import Flask, render_template, request, redirect,jsonify
import requests
import bash_in_python as wf_runner
import wf_meta as wf_parser
import wf_uploader as wf_upload
import json
import os
import yaml
app = Flask(__name__)
minio_name = os.environ['MINIO_DOCKER_NAME']
minio_key = os.environ['MINIO_ACCESS_KEY']
minio_secret = os.environ["MINIO_SECRET_KEY"]
@app.route('/', methods=['GET'])
def homepage():
return(str(os.listdir()))
@app.route('/run-wf',methods = ['POST'])
def run_wf():
result = {}
if request.data == b'':
return(jsonify({'error':"Please POST JSON, with workflow, job, and path to directory"}))
try:
given = json.loads(request.data.decode('utf-8'))
except:
return(jsonify({'error':"Please POST JSON, with workflow, job, and path to directory"}))
inputs = ["file",given['workflow'],given['job']]
if given.get('path'):
inputs.append(given.get('path'))
else:
inputs.append('minio')
return(jsonify(wf_runner.workflow_main(inputs)))
@app.route('/post-wf',methods = ['POST'])
def post_wf():
result = {}
files = request.files
i = 0
commandTools = []
for f in files:
if i == 0:
workflow = files[f]
i = 1
else:
commandTools.append(files[f])
wf_dict = yaml.safe_load(workflow)
output_meta = wf_parser.pull_schema_meta(wf_dict,bytes = True)
for output in output_meta:
URL = "http://validator:5000/validatejson"
req = requests.post(url = URL,json = output)
valid = req.json()['valid']
if not valid:
return(jsonify({"error":str(output.get('name')) + " missing required schema properties or invalid",
"upload":False,
"validation_result":req.json()['error']}))
wf_metadata = wf_parser.generate_wf_meta(wf_dict,bytes = True,name=workflow.name)
req = requests.put("https://ors:8080/uid/test/",json = wf_metadata,verify = False)
if req.json().get('created'):
full_id = req.json()['created']['@id']
_,_,base,namespace,name,id = full_id.split('/')
wf_metadata['identifier'] = id
####################
#Post wf to mongo
####################
if wf_upload.upload_cwl(workflow,isWorkflow = True,bytes = True,id = id):
commandlineids = []
for tool in commandTools:
tool_dict = yaml.safe_load(tool)
tool_meta = wf_parser.generate_proccess_meta(tool_dict,bytes = True,name=tool.name)
req = requests.put("https://ors:8080/uid/test/",json = tool_meta,verify = False)
if req.json().get('created'):
full_id = req.json()['created']['@id']
_,_,base,namespace,name,id = full_id.split('/')
commandlineids.append(id)
else:
result = {"error":"Error minting id for commandLineTool: " + str(tool.name)}
return(jsonify(result))
if wf_upload.upload_cwl(tool,isWorkflow = False,bytes = True,id=id):
continue
else:
result = {"error":"Error uploading commandLineTool: " + str(tool.name)}
return(jsonify(result))
else:
result = {"error":"Error uploading workflow"}
return(jsonify(result))
result = {
"upload": True,
"workflow identifier":wf_metadata['id'],
"commandLineTools Ids":commandlineids
}
return(jsonify(result))
@app.route('/post-job',methods = ['POST'])
def post_job():
result = {}
files = request.files
i = 0
jobs = []
for f in files:
jobs.append(files[f])
for job in jobs:
if wf_upload.upload_cwl(job,isJob = True,bytes = True):
continue
else:
result = {"error":"Error uploading commandLineTool: " + str(job.name)}
return(jsonify(result))
result = {"error": "","upload": True}
return(jsonify(result))
if __name__ == "__main__":
app.run(port=5002)