/
config.py
198 lines (164 loc) · 5.84 KB
/
config.py
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""
The orchestrator config file has three sections: queues, trs, and wes.
This provides functions to save and get values into these three sections in the file.
"""
import logging
import os
from synorchestrator.util import get_yaml, save_yaml, heredoc
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def _default_config():
"""
Create default app config, if not existing.
"""
config = {
'queues': {
'queue_1': {
'trs_id': None,
'version_id': None,
'wes_default': 'local',
'wes_opts': ['local'],
'workflow_attachments': [
'file://tests/testdata/md5sum.input',
'file://tests/testdata/dockstore-tool-md5sum.cwl'],
'workflow_id': None,
'workflow_type': 'CWL',
'workflow_url': 'file://tests/testdata/md5sum.cwl'}},
'toolregistries': {
'dockstore': {
'auth': None,
'auth_type': None,
'host': 'dockstore.org:8443',
'proto': 'https'}},
'workflowservices': {
'local': {
'auth': None,
'auth_type': None,
'host': '0.0.0.0:8080',
'proto': 'http'}}}
save_yaml(config_path, config)
config_path = os.path.join(os.path.dirname(__file__), 'config.yaml')
if not os.path.exists(config_path):
_default_config()
def queue_config():
return get_yaml(config_path)['queues']
def trs_config():
return get_yaml(config_path)['toolregistries']
def wes_config():
return get_yaml(config_path)['workflowservices']
def add_queue(queue_id,
wf_type,
trs_id='dockstore',
wf_id=None,
version_id='local',
wf_url=None,
wf_attachments=None,
wes_default='local',
wes_opts=None,
target_queue=None):
"""
Register a workflow evaluation queue to the orchestrator's
scope of work.
"""
if not wf_id and not wf_url:
raise ValueError(
"One of either 'wf_id' or 'wf_url' must be specified.")
wes_opts = [wes_default] if wes_opts is None else wes_opts
config = {'workflow_type': wf_type,
'trs_id': trs_id,
'workflow_id': wf_id,
'version_id': version_id,
'workflow_url': wf_url,
'workflow_attachments': wf_attachments,
'wes_default': wes_default,
'wes_opts': wes_opts,
'target_queue': target_queue}
set_yaml('queues', queue_id, config)
def add_toolregistry(service, auth, auth_type, host, proto):
"""
Register a Tool Registry Service endpoint to the orchestrator's
search space for workflows.
:param trs_id: string ID of TRS endpoint (e.g., 'dockstore')
"""
config = {'auth': auth,
'auth_type': auth,
'host': host,
'proto': proto}
set_yaml('toolregistries', service, config)
def add_workflowservice(service, host, auth=None, auth_type=None, proto='https'):
"""
Register a Workflow Execution Service endpoint to the
orchestrator's available environment options.
:param wes_id: string ID of WES endpoint (e.g., 'local')
"""
config = {'auth': auth,
'auth_type': auth_type,
'host': host,
'proto': proto}
set_yaml('workflowservices', service, config)
def add_wes_opt(queue_ids, wes_id, make_default=False):
"""
Add a WES endpoint to the execution options of the specified
workflow queues.
"""
if not isinstance(queue_ids, list):
queue_ids = [queue_ids]
for queue_id in queue_ids:
wf_config = queue_config()[queue_id]
wf_config['wes_opts'].append(wes_id)
if make_default:
wf_config['wes_default'] = wes_id
set_yaml('queues', queue_id, wf_config)
def set_yaml(section, service, var2add):
orchestrator_config = get_yaml(config_path)
orchestrator_config.setdefault(section, {})[service] = var2add
save_yaml(config_path, orchestrator_config)
def show():
"""
Show current application configuration.
"""
orchestrator_config = get_yaml(config_path)
queues = '\n'.join(
('{}: {} ({})\n'
' > workflow URL: {}\n'
' > workflow type: {}\n'
' > from TRS: {}\n'
' > WES options: {}').format(
k,
orchestrator_config['queues'][k]['workflow_id'],
orchestrator_config['queues'][k]['version_id'],
orchestrator_config['queues'][k]['workflow_url'],
orchestrator_config['queues'][k]['workflow_type'],
orchestrator_config['queues'][k]['trs_id'],
orchestrator_config['queues'][k]['wes_opts']
)
for k in orchestrator_config['queues']
)
trs = '\n'.join('{}: {}'.format(
k,
orchestrator_config['toolregistries'][k]['host'])
for k in orchestrator_config['toolregistries']
)
wes = '\n'.join('{}: {}'.format(
k,
orchestrator_config['workflowservices'][k]['host'])
for k in orchestrator_config['workflowservices']
)
display = heredoc('''
Orchestrator options:
Workflow Evaluation Queues
(queue ID: workflow ID [version])
---------------------------------------------------------------------------
{queues}
Tool Registries
(TRS ID: host address)
---------------------------------------------------------------------------
{trs}
Workflow Services
(WES ID: host address)
---------------------------------------------------------------------------
{wes}
''', {'queues': queues,
'trs': trs,
'wes': wes})
print(display)