cloudos-cli 2.17.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cloudos_cli/__init__.py +11 -0
- cloudos_cli/__main__.py +1297 -0
- cloudos_cli/_version.py +1 -0
- cloudos_cli/clos.py +726 -0
- cloudos_cli/jobs/__init__.py +8 -0
- cloudos_cli/jobs/job.py +555 -0
- cloudos_cli/queue/__init__.py +8 -0
- cloudos_cli/queue/queue.py +139 -0
- cloudos_cli/utils/__init__.py +9 -0
- cloudos_cli/utils/errors.py +32 -0
- cloudos_cli/utils/requests.py +75 -0
- cloudos_cli-2.17.0.dist-info/LICENSE +674 -0
- cloudos_cli-2.17.0.dist-info/METADATA +1060 -0
- cloudos_cli-2.17.0.dist-info/RECORD +41 -0
- cloudos_cli-2.17.0.dist-info/WHEEL +5 -0
- cloudos_cli-2.17.0.dist-info/entry_points.txt +2 -0
- cloudos_cli-2.17.0.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/functions_for_pytest.py +7 -0
- tests/test_clos/__init__.py +0 -0
- tests/test_clos/test_create_cromwell_header.py +35 -0
- tests/test_clos/test_cromwell_switch.py +77 -0
- tests/test_clos/test_detect_workflow.py +47 -0
- tests/test_clos/test_get_cromwell_status.py +77 -0
- tests/test_clos/test_get_curated_workflow_list.py +72 -0
- tests/test_clos/test_get_job_list.py +79 -0
- tests/test_clos/test_get_job_status.py +75 -0
- tests/test_clos/test_get_project_list.py +74 -0
- tests/test_clos/test_get_user_info.py +68 -0
- tests/test_clos/test_get_workflow_list.py +87 -0
- tests/test_clos/test_is_module.py +48 -0
- tests/test_clos/test_process_job_list.py +74 -0
- tests/test_clos/test_process_project_list.py +36 -0
- tests/test_clos/test_process_workflow_list.py +36 -0
- tests/test_clos/test_wait_job_completion.py +40 -0
- tests/test_clos/test_workflow_import.py +77 -0
- tests/test_jobs/__init__.py +0 -0
- tests/test_jobs/test_convert_nextflow_to_json.py +104 -0
- tests/test_jobs/test_project_id.py +67 -0
- tests/test_jobs/test_send_job.py +84 -0
- tests/test_jobs/test_workflow_id.py +67 -0
cloudos_cli/__main__.py
ADDED
|
@@ -0,0 +1,1297 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
import cloudos_cli.jobs.job as jb
|
|
5
|
+
from cloudos_cli.clos import Cloudos
|
|
6
|
+
from cloudos_cli.queue.queue import Queue
|
|
7
|
+
import json
|
|
8
|
+
import time
|
|
9
|
+
import sys
|
|
10
|
+
import os
|
|
11
|
+
import urllib3
|
|
12
|
+
from ._version import __version__
|
|
13
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
14
|
+
|
|
15
|
+
# GLOBAL VARS
|
|
16
|
+
JOB_COMPLETED = 'completed'
|
|
17
|
+
JOB_FAILED = 'failed'
|
|
18
|
+
JOB_ABORTED = 'aborted'
|
|
19
|
+
JOB_RUNNING = 'running'
|
|
20
|
+
REQUEST_INTERVAL_CROMWELL = 30
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def ssl_selector(disable_ssl_verification, ssl_cert):
|
|
24
|
+
"""Verify value selector.
|
|
25
|
+
|
|
26
|
+
This function stablish the value that will be passed to requests.verify
|
|
27
|
+
variable.
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
disable_ssl_verification : bool
|
|
32
|
+
Whether to disable SSL verification.
|
|
33
|
+
ssl_cert : string
|
|
34
|
+
String indicating the path to the SSL certificate file to use.
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
verify_ssl : [bool | string]
|
|
39
|
+
Either a bool or a path string to be passed to requests.verify to control
|
|
40
|
+
SSL verification.
|
|
41
|
+
"""
|
|
42
|
+
if disable_ssl_verification:
|
|
43
|
+
verify_ssl = False
|
|
44
|
+
print('[WARNING] Disabling SSL verification')
|
|
45
|
+
urllib3.disable_warnings()
|
|
46
|
+
elif ssl_cert is None:
|
|
47
|
+
verify_ssl = True
|
|
48
|
+
elif os.path.isfile(ssl_cert):
|
|
49
|
+
verify_ssl = ssl_cert
|
|
50
|
+
else:
|
|
51
|
+
raise FileNotFoundError(f"The specified file '{ssl_cert}' was not found")
|
|
52
|
+
return verify_ssl
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@click.group()
|
|
56
|
+
@click.version_option(__version__)
|
|
57
|
+
def run_cloudos_cli():
|
|
58
|
+
"""CloudOS python package: a package for interacting with CloudOS."""
|
|
59
|
+
print(run_cloudos_cli.__doc__ + '\n')
|
|
60
|
+
print('Version: ' + __version__ + '\n')
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@run_cloudos_cli.group()
|
|
64
|
+
def job():
|
|
65
|
+
"""CloudOS job functionality: run and check jobs in CloudOS."""
|
|
66
|
+
print(job.__doc__ + '\n')
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@run_cloudos_cli.group()
|
|
70
|
+
def workflow():
|
|
71
|
+
"""CloudOS workflow functionality: list and import workflows."""
|
|
72
|
+
print(workflow.__doc__ + '\n')
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@run_cloudos_cli.group()
|
|
76
|
+
def project():
|
|
77
|
+
"""CloudOS project functionality: list projects in CloudOS."""
|
|
78
|
+
print(project.__doc__ + '\n')
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@run_cloudos_cli.group()
|
|
82
|
+
def cromwell():
|
|
83
|
+
"""Cromwell server functionality: check status, start and stop."""
|
|
84
|
+
print(cromwell.__doc__ + '\n')
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@run_cloudos_cli.group()
|
|
88
|
+
def queue():
|
|
89
|
+
"""CloudOS job queue functionality."""
|
|
90
|
+
print(queue.__doc__ + '\n')
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@job.command('run')
|
|
94
|
+
@click.option('-k',
|
|
95
|
+
'--apikey',
|
|
96
|
+
help='Your CloudOS API key',
|
|
97
|
+
required=True)
|
|
98
|
+
@click.option('-c',
|
|
99
|
+
'--cloudos-url',
|
|
100
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
101
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
102
|
+
default='https://cloudos.lifebit.ai')
|
|
103
|
+
@click.option('--workspace-id',
|
|
104
|
+
help='The specific CloudOS workspace id.',
|
|
105
|
+
required=True)
|
|
106
|
+
@click.option('--project-name',
|
|
107
|
+
help='The name of a CloudOS project.',
|
|
108
|
+
required=True)
|
|
109
|
+
@click.option('--workflow-name',
|
|
110
|
+
help='The name of a CloudOS workflow or pipeline.',
|
|
111
|
+
required=True)
|
|
112
|
+
@click.option('--job-config',
|
|
113
|
+
help=('A config file similar to a nextflow.config file, ' +
|
|
114
|
+
'but only with the parameters to use with your job.'))
|
|
115
|
+
@click.option('-p',
|
|
116
|
+
'--parameter',
|
|
117
|
+
multiple=True,
|
|
118
|
+
help=('A single parameter to pass to the job call. It should be in the ' +
|
|
119
|
+
'following form: parameter_name=parameter_value. E.g.: ' +
|
|
120
|
+
'-p input=s3://path_to_my_file. You can use this option as many ' +
|
|
121
|
+
'times as parameters you want to include.'))
|
|
122
|
+
@click.option('--nextflow-profile',
|
|
123
|
+
help=('A comma separated string indicating the nextflow profile/s ' +
|
|
124
|
+
'to use with your job.'))
|
|
125
|
+
@click.option('--nextflow-version',
|
|
126
|
+
help=('Nextflow version to use when executing the workflow in CloudOS. ' +
|
|
127
|
+
'Please, note that versions above 22.10.8 are only DSL2 compatible. ' +
|
|
128
|
+
'Default=22.10.8.'),
|
|
129
|
+
type=click.Choice(['22.10.8', '24.04.4', 'latest']),
|
|
130
|
+
default='22.10.8')
|
|
131
|
+
@click.option('--git-commit',
|
|
132
|
+
help=('The exact whole 40 character commit hash to run for ' +
|
|
133
|
+
'the selected pipeline. ' +
|
|
134
|
+
'If not specified it defaults to the last commit ' +
|
|
135
|
+
'of the default branch.'))
|
|
136
|
+
@click.option('--git-tag',
|
|
137
|
+
help=('The tag to run for the selected pipeline. ' +
|
|
138
|
+
'If not specified it defaults to the last commit ' +
|
|
139
|
+
'of the default branch.'))
|
|
140
|
+
@click.option('--job-name',
|
|
141
|
+
help='The name of the job. Default=new_job.',
|
|
142
|
+
default='new_job')
|
|
143
|
+
@click.option('--resumable',
|
|
144
|
+
help='Whether to make the job able to be resumed or not.',
|
|
145
|
+
is_flag=True)
|
|
146
|
+
@click.option('--do-not-save-logs',
|
|
147
|
+
help=('Avoids process log saving. If you select this option, your job process ' +
|
|
148
|
+
'logs will not be stored.'),
|
|
149
|
+
is_flag=True)
|
|
150
|
+
@click.option('--spot',
|
|
151
|
+
help=('[Deprecated in 2.11.0] This option has been deprecated and has no effect. ' +
|
|
152
|
+
'Spot instances are no longer available in CloudOS.'),
|
|
153
|
+
is_flag=True)
|
|
154
|
+
@click.option('--batch',
|
|
155
|
+
help=('[Deprecated in 2.7.0] Since v2.7.0, the default executor is AWSbatch ' +
|
|
156
|
+
'so there is no need to use this flag. It is maintained for ' +
|
|
157
|
+
'backwards compatibility.'),
|
|
158
|
+
is_flag=True)
|
|
159
|
+
@click.option('--ignite',
|
|
160
|
+
help=('This flag allows running ignite executor if available. Please, note ' +
|
|
161
|
+
'that ignite executor is being deprecated and may not be available in your ' +
|
|
162
|
+
'CloudOS.'),
|
|
163
|
+
is_flag=True)
|
|
164
|
+
@click.option('--job-queue',
|
|
165
|
+
help='Name of the job queue to use with a batch job.')
|
|
166
|
+
@click.option('--instance-type',
|
|
167
|
+
help=('The type of execution platform compute instance to use. ' +
|
|
168
|
+
'Default=c5.xlarge(aws)|Standard_D4as_v4(azure).'),
|
|
169
|
+
default='NONE_SELECTED')
|
|
170
|
+
@click.option('--instance-disk',
|
|
171
|
+
help='The amount of disk storage to configure. Default=500.',
|
|
172
|
+
type=int,
|
|
173
|
+
default=500)
|
|
174
|
+
@click.option('--storage-mode',
|
|
175
|
+
help=('Either \'lustre\' or \'regular\'. Indicates if the user wants to select ' +
|
|
176
|
+
'regular or lustre storage. Default=regular.'),
|
|
177
|
+
default='regular')
|
|
178
|
+
@click.option('--lustre-size',
|
|
179
|
+
help=('The lustre storage to be used when --storage-mode=lustre, in GB. It should ' +
|
|
180
|
+
'be 1200 or a multiple of it. Default=1200.'),
|
|
181
|
+
type=int,
|
|
182
|
+
default=1200)
|
|
183
|
+
@click.option('--wait-completion',
|
|
184
|
+
help=('Whether to wait to job completion and report final ' +
|
|
185
|
+
'job status.'),
|
|
186
|
+
is_flag=True)
|
|
187
|
+
@click.option('--wait-time',
|
|
188
|
+
help=('Max time to wait (in seconds) to job completion. ' +
|
|
189
|
+
'Default=3600.'),
|
|
190
|
+
default=3600)
|
|
191
|
+
@click.option('--wdl-mainfile',
|
|
192
|
+
help='For WDL workflows, which mainFile (.wdl) is configured to use.',)
|
|
193
|
+
@click.option('--wdl-importsfile',
|
|
194
|
+
help='For WDL workflows, which importsFile (.zip) is configured to use.',)
|
|
195
|
+
@click.option('-t',
|
|
196
|
+
'--cromwell-token',
|
|
197
|
+
help=('Specific Cromwell server authentication token. Currently, not necessary ' +
|
|
198
|
+
'as apikey can be used instead, but maintained for backwards compatibility.'))
|
|
199
|
+
@click.option('--repository-platform',
|
|
200
|
+
help='Name of the repository platform of the workflow. Default=github.',
|
|
201
|
+
default='github')
|
|
202
|
+
@click.option('--execution-platform',
|
|
203
|
+
help='Name of the execution platform implemented in your CloudOS. Default=aws.',
|
|
204
|
+
type=click.Choice(['aws', 'azure', 'hpc']),
|
|
205
|
+
default='aws')
|
|
206
|
+
@click.option('--hpc-id',
|
|
207
|
+
help=('ID of your HPC, only applicable when --execution-platform=hpc. ' +
|
|
208
|
+
'Default=660fae20f93358ad61e0104b'),
|
|
209
|
+
default='660fae20f93358ad61e0104b')
|
|
210
|
+
@click.option('--cost-limit',
|
|
211
|
+
help='Add a cost limit to your job. Default=30.0 (For no cost limit please use -1).',
|
|
212
|
+
type=float,
|
|
213
|
+
default=30.0)
|
|
214
|
+
@click.option('--accelerate-file-staging',
|
|
215
|
+
help='Enables AWS S3 mountpoint for quicker file staging.',
|
|
216
|
+
is_flag=True)
|
|
217
|
+
@click.option('--use-private-docker-repository',
|
|
218
|
+
help=('Allows to use private docker repository for running jobs. The Docker user ' +
|
|
219
|
+
'account has to be already linked to CloudOS.'),
|
|
220
|
+
is_flag=True)
|
|
221
|
+
@click.option('--verbose',
|
|
222
|
+
help='Whether to print information messages or not.',
|
|
223
|
+
is_flag=True)
|
|
224
|
+
@click.option('--request-interval',
|
|
225
|
+
help=('Time interval to request (in seconds) the job status. ' +
|
|
226
|
+
'For large jobs is important to use a high number to ' +
|
|
227
|
+
'make fewer requests so that is not considered spamming by the API. ' +
|
|
228
|
+
'Default=30.'),
|
|
229
|
+
default=30)
|
|
230
|
+
@click.option('--disable-ssl-verification',
|
|
231
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
232
|
+
'not generally recommended for security reasons.'),
|
|
233
|
+
is_flag=True)
|
|
234
|
+
@click.option('--ssl-cert',
|
|
235
|
+
help='Path to your SSL certificate file.')
|
|
236
|
+
def run(apikey,
|
|
237
|
+
cloudos_url,
|
|
238
|
+
workspace_id,
|
|
239
|
+
project_name,
|
|
240
|
+
workflow_name,
|
|
241
|
+
job_config,
|
|
242
|
+
parameter,
|
|
243
|
+
git_commit,
|
|
244
|
+
git_tag,
|
|
245
|
+
job_name,
|
|
246
|
+
resumable,
|
|
247
|
+
do_not_save_logs,
|
|
248
|
+
spot,
|
|
249
|
+
batch,
|
|
250
|
+
ignite,
|
|
251
|
+
job_queue,
|
|
252
|
+
nextflow_profile,
|
|
253
|
+
nextflow_version,
|
|
254
|
+
instance_type,
|
|
255
|
+
instance_disk,
|
|
256
|
+
storage_mode,
|
|
257
|
+
lustre_size,
|
|
258
|
+
wait_completion,
|
|
259
|
+
wait_time,
|
|
260
|
+
wdl_mainfile,
|
|
261
|
+
wdl_importsfile,
|
|
262
|
+
cromwell_token,
|
|
263
|
+
repository_platform,
|
|
264
|
+
execution_platform,
|
|
265
|
+
hpc_id,
|
|
266
|
+
cost_limit,
|
|
267
|
+
accelerate_file_staging,
|
|
268
|
+
use_private_docker_repository,
|
|
269
|
+
verbose,
|
|
270
|
+
request_interval,
|
|
271
|
+
disable_ssl_verification,
|
|
272
|
+
ssl_cert):
|
|
273
|
+
"""Submit a job to CloudOS."""
|
|
274
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
275
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
276
|
+
if spot:
|
|
277
|
+
print('[Message] You have specified spot instances but they are no longer available ' +
|
|
278
|
+
'in CloudOS. Option ignored.')
|
|
279
|
+
if do_not_save_logs:
|
|
280
|
+
save_logs = False
|
|
281
|
+
else:
|
|
282
|
+
save_logs = True
|
|
283
|
+
if instance_type == 'NONE_SELECTED':
|
|
284
|
+
if execution_platform == 'aws':
|
|
285
|
+
instance_type = 'c5.xlarge'
|
|
286
|
+
elif execution_platform == 'azure':
|
|
287
|
+
instance_type = 'Standard_D4as_v4'
|
|
288
|
+
else:
|
|
289
|
+
instance_type = None
|
|
290
|
+
if execution_platform == 'azure' or execution_platform == 'hpc':
|
|
291
|
+
batch = None
|
|
292
|
+
elif ignite:
|
|
293
|
+
batch = None
|
|
294
|
+
print('[Warning] You have specified ignite executor. Please, note that ignite is being ' +
|
|
295
|
+
'removed from CloudOS, so the command may fail. Check ignite availability in your ' +
|
|
296
|
+
'CloudOS')
|
|
297
|
+
else:
|
|
298
|
+
batch = True
|
|
299
|
+
if execution_platform == 'hpc':
|
|
300
|
+
print('\n[Message] HPC execution platform selected')
|
|
301
|
+
if hpc_id is None:
|
|
302
|
+
raise ValueError('Please, specify your HPC ID using --hpc parameter')
|
|
303
|
+
print('[Message] Please, take into account that HPC execution do not support ' +
|
|
304
|
+
'the following parameters and all of them will be ignored:\n' +
|
|
305
|
+
'\t--job-queue\n' +
|
|
306
|
+
'\t--resumable | --do-not-save-logs\n' +
|
|
307
|
+
'\t--instance-type | --instance-disk | --cost-limit\n' +
|
|
308
|
+
'\t--storage-mode | --lustre-size\n' +
|
|
309
|
+
'\t--wdl-mainfile | --wdl-importsfile | --cromwell-token\n')
|
|
310
|
+
wdl_mainfile = None
|
|
311
|
+
wdl_importsfile = None
|
|
312
|
+
storage_mode = 'regular'
|
|
313
|
+
save_logs = False
|
|
314
|
+
if accelerate_file_staging:
|
|
315
|
+
if execution_platform != 'aws':
|
|
316
|
+
print('[Message] You have selected accelerate file staging, but this function is ' +
|
|
317
|
+
'only available when execution platform is AWS. The accelerate file staging ' +
|
|
318
|
+
'will not be applied')
|
|
319
|
+
use_mountpoints = False
|
|
320
|
+
else:
|
|
321
|
+
use_mountpoints = True
|
|
322
|
+
print('[Message] Enabling AWS S3 mountpoint for accelerated file staging. ' +
|
|
323
|
+
'Please, take into consideration the following:\n' +
|
|
324
|
+
'\t- It significantly reduces runtime and compute costs but may increase network costs.\n' +
|
|
325
|
+
'\t- Requires extra memory. Adjust process memory or optimise resource usage if necessary.\n' +
|
|
326
|
+
'\t- This is still a CloudOS BETA feature.\n')
|
|
327
|
+
else:
|
|
328
|
+
use_mountpoints = False
|
|
329
|
+
if verbose:
|
|
330
|
+
print('\t...Detecting workflow type')
|
|
331
|
+
cl = Cloudos(cloudos_url, apikey, cromwell_token)
|
|
332
|
+
workflow_type = cl.detect_workflow(workflow_name, workspace_id, verify_ssl)
|
|
333
|
+
is_module = cl.is_module(workflow_name, workspace_id, verify_ssl)
|
|
334
|
+
if execution_platform == 'hpc' and workflow_type == 'wdl':
|
|
335
|
+
raise ValueError(f'The workflow {workflow_name} is a WDL workflow. ' +
|
|
336
|
+
'WDL is not supported on HPC execution platform.')
|
|
337
|
+
if workflow_type == 'wdl':
|
|
338
|
+
print('[Message] WDL workflow detected')
|
|
339
|
+
if wdl_mainfile is None:
|
|
340
|
+
raise ValueError('Please, specify WDL mainFile using --wdl-mainfile <mainFile>.')
|
|
341
|
+
c_status = cl.get_cromwell_status(workspace_id, verify_ssl)
|
|
342
|
+
c_status_h = json.loads(c_status.content)["status"]
|
|
343
|
+
print(f'\tCurrent Cromwell server status is: {c_status_h}\n')
|
|
344
|
+
if c_status_h == 'Stopped':
|
|
345
|
+
print('\tStarting Cromwell server...\n')
|
|
346
|
+
cl.cromwell_switch(workspace_id, 'restart', verify_ssl)
|
|
347
|
+
elapsed = 0
|
|
348
|
+
while elapsed < 300 and c_status_h != 'Running':
|
|
349
|
+
c_status_old = c_status_h
|
|
350
|
+
time.sleep(REQUEST_INTERVAL_CROMWELL)
|
|
351
|
+
elapsed += REQUEST_INTERVAL_CROMWELL
|
|
352
|
+
c_status = cl.get_cromwell_status(workspace_id, verify_ssl)
|
|
353
|
+
c_status_h = json.loads(c_status.content)["status"]
|
|
354
|
+
if c_status_h != c_status_old:
|
|
355
|
+
print(f'\tCurrent Cromwell server status is: {c_status_h}\n')
|
|
356
|
+
if c_status_h != 'Running':
|
|
357
|
+
raise Exception('Cromwell server did not restarted properly.')
|
|
358
|
+
cromwell_id = json.loads(c_status.content)["_id"]
|
|
359
|
+
print('\t' + ('*' * 80) + '\n' +
|
|
360
|
+
'\t[WARNING] Cromwell server is now running. Please, remember to stop it when ' +
|
|
361
|
+
'your\n' + '\tjob finishes. You can use the following command:\n' +
|
|
362
|
+
'\tcloudos cromwell stop \\\n' +
|
|
363
|
+
'\t\t--cromwell-token $CROMWELL_TOKEN \\\n' +
|
|
364
|
+
f'\t\t--cloudos-url {cloudos_url} \\\n' +
|
|
365
|
+
f'\t\t--workspace-id {workspace_id}\n' +
|
|
366
|
+
'\t' + ('*' * 80) + '\n')
|
|
367
|
+
else:
|
|
368
|
+
cromwell_id = None
|
|
369
|
+
if verbose:
|
|
370
|
+
print('\t...Preparing objects')
|
|
371
|
+
j = jb.Job(cloudos_url, apikey, None, workspace_id, project_name, workflow_name,
|
|
372
|
+
mainfile=wdl_mainfile, importsfile=wdl_importsfile,
|
|
373
|
+
repository_platform=repository_platform, verify=verify_ssl)
|
|
374
|
+
if verbose:
|
|
375
|
+
print('\tThe following Job object was created:')
|
|
376
|
+
print('\t' + str(j))
|
|
377
|
+
print('\t...Sending job to CloudOS\n')
|
|
378
|
+
if is_module:
|
|
379
|
+
if job_queue is not None:
|
|
380
|
+
print(f'[Message] Ignoring job queue "{job_queue}" for ' +
|
|
381
|
+
f'Platform Workflow "{workflow_name}". Platform Workflows ' +
|
|
382
|
+
'use their own predetermined queues.')
|
|
383
|
+
job_queue_id = None
|
|
384
|
+
if nextflow_version != '22.10.8':
|
|
385
|
+
print(f'[Message] The selected worflow \'{workflow_name}\' ' +
|
|
386
|
+
'is a CloudOS module. CloudOS modules only work with ' +
|
|
387
|
+
'Nextflow version 22.10.8. Switching to use 22.10.8')
|
|
388
|
+
nextflow_version = '22.10.8'
|
|
389
|
+
else:
|
|
390
|
+
queue = Queue(cloudos_url=cloudos_url, apikey=apikey, cromwell_token=cromwell_token,
|
|
391
|
+
workspace_id=workspace_id, verify=verify_ssl)
|
|
392
|
+
job_queue_id = queue.fetch_job_queue_id(workflow_type=workflow_type, batch=batch,
|
|
393
|
+
job_queue=job_queue)
|
|
394
|
+
if use_private_docker_repository:
|
|
395
|
+
if is_module:
|
|
396
|
+
print(f'[Message] Workflow "{workflow_name}" is a CloudOS module. ' +
|
|
397
|
+
'Option --use-private-docker-repository will be ignored.')
|
|
398
|
+
docker_login = False
|
|
399
|
+
else:
|
|
400
|
+
me = j.get_user_info(verify=verify_ssl)['dockerRegistriesCredentials']
|
|
401
|
+
if len(me) == 0:
|
|
402
|
+
raise Exception('User private Docker repository has been selected but your user ' +
|
|
403
|
+
'credentials have not been configured yet. Please, link your ' +
|
|
404
|
+
'Docker account to CloudOS before using ' +
|
|
405
|
+
'--use-private-docker-repository option.')
|
|
406
|
+
print('[Message] Use private Docker repository has been selected. A custom job ' +
|
|
407
|
+
'queue to support private Docker containers and/or Lustre FSx will be created for ' +
|
|
408
|
+
'your job. The selected job queue will serve as a template.')
|
|
409
|
+
docker_login = True
|
|
410
|
+
else:
|
|
411
|
+
docker_login = False
|
|
412
|
+
if nextflow_version == 'latest':
|
|
413
|
+
nextflow_version = '24.04.4'
|
|
414
|
+
print('[Message] You have specified Nextflow version \'latest\'. The workflow will use the ' +
|
|
415
|
+
f'latest version available on CloudOS: {nextflow_version}.')
|
|
416
|
+
if nextflow_version != '22.10.8':
|
|
417
|
+
print(f'[Warning] You have specified Nextflow version {nextflow_version}. This version requires the pipeline ' +
|
|
418
|
+
'to be written in DSL2 and does not support DSL1.')
|
|
419
|
+
print('\nExecuting run...')
|
|
420
|
+
if workflow_type == 'nextflow':
|
|
421
|
+
print(f'\tNextflow version: {nextflow_version}')
|
|
422
|
+
j_id = j.send_job(job_config=job_config,
|
|
423
|
+
parameter=parameter,
|
|
424
|
+
git_commit=git_commit,
|
|
425
|
+
git_tag=git_tag,
|
|
426
|
+
job_name=job_name,
|
|
427
|
+
resumable=resumable,
|
|
428
|
+
save_logs=save_logs,
|
|
429
|
+
batch=batch,
|
|
430
|
+
job_queue_id=job_queue_id,
|
|
431
|
+
nextflow_profile=nextflow_profile,
|
|
432
|
+
nextflow_version=nextflow_version,
|
|
433
|
+
instance_type=instance_type,
|
|
434
|
+
instance_disk=instance_disk,
|
|
435
|
+
storage_mode=storage_mode,
|
|
436
|
+
lustre_size=lustre_size,
|
|
437
|
+
execution_platform=execution_platform,
|
|
438
|
+
hpc_id=hpc_id,
|
|
439
|
+
workflow_type=workflow_type,
|
|
440
|
+
cromwell_id=cromwell_id,
|
|
441
|
+
cost_limit=cost_limit,
|
|
442
|
+
use_mountpoints=use_mountpoints,
|
|
443
|
+
docker_login=docker_login,
|
|
444
|
+
verify=verify_ssl)
|
|
445
|
+
print(f'\tYour assigned job id is: {j_id}\n')
|
|
446
|
+
j_url = f'{cloudos_url}/app/jobs/{j_id}'
|
|
447
|
+
if wait_completion:
|
|
448
|
+
print('\tPlease, wait until job completion (max wait time of ' +
|
|
449
|
+
f'{wait_time} seconds).\n')
|
|
450
|
+
j_status = j.wait_job_completion(job_id=j_id,
|
|
451
|
+
wait_time=wait_time,
|
|
452
|
+
request_interval=request_interval,
|
|
453
|
+
verbose=verbose,
|
|
454
|
+
verify=verify_ssl)
|
|
455
|
+
j_name = j_status['name']
|
|
456
|
+
j_final_s = j_status['status']
|
|
457
|
+
if j_final_s == JOB_COMPLETED:
|
|
458
|
+
print(f'\nJob status for job "{j_name}" (ID: {j_id}): {j_final_s}')
|
|
459
|
+
sys.exit(0)
|
|
460
|
+
else:
|
|
461
|
+
print(f'\nJob status for job "{j_name}" (ID: {j_id}): {j_final_s}')
|
|
462
|
+
sys.exit(1)
|
|
463
|
+
else:
|
|
464
|
+
j_status = j.get_job_status(j_id, verify_ssl)
|
|
465
|
+
j_status_h = json.loads(j_status.content)["status"]
|
|
466
|
+
print(f'\tYour current job status is: {j_status_h}')
|
|
467
|
+
print('\tTo further check your job status you can either go to ' +
|
|
468
|
+
f'{j_url} or use the following command:\n' +
|
|
469
|
+
'\tcloudos job status \\\n' +
|
|
470
|
+
'\t\t--apikey $MY_API_KEY \\\n' +
|
|
471
|
+
f'\t\t--cloudos-url {cloudos_url} \\\n' +
|
|
472
|
+
f'\t\t--job-id {j_id}\n')
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
@job.command('run-curated-examples')
|
|
476
|
+
@click.option('-k',
|
|
477
|
+
'--apikey',
|
|
478
|
+
help='Your CloudOS API key',
|
|
479
|
+
required=True)
|
|
480
|
+
@click.option('-c',
|
|
481
|
+
'--cloudos-url',
|
|
482
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
483
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
484
|
+
default='https://cloudos.lifebit.ai')
|
|
485
|
+
@click.option('--workspace-id',
|
|
486
|
+
help='The specific CloudOS workspace id.',
|
|
487
|
+
required=True)
|
|
488
|
+
@click.option('--project-name',
|
|
489
|
+
help='The name of a CloudOS project.',
|
|
490
|
+
required=True)
|
|
491
|
+
@click.option('--resumable',
|
|
492
|
+
help='Whether to make the job able to be resumed or not.',
|
|
493
|
+
is_flag=True)
|
|
494
|
+
@click.option('--do-not-save-logs',
|
|
495
|
+
help=('Avoids process log saving. If you select this option, your job process ' +
|
|
496
|
+
'logs will not be stored.'),
|
|
497
|
+
is_flag=True)
|
|
498
|
+
@click.option('--spot',
|
|
499
|
+
help=('[Deprecated in 2.11.0] This option has been deprecated and has no effect. ' +
|
|
500
|
+
'Spot instances are no longer available in CloudOS.'),
|
|
501
|
+
is_flag=True)
|
|
502
|
+
@click.option('--batch',
|
|
503
|
+
help=('[Deprecated in 2.7.0] Since v2.7.0, the default executor is AWSbatch ' +
|
|
504
|
+
'so there is no need to use this flag. It is maintained for ' +
|
|
505
|
+
'backwards compatibility.'),
|
|
506
|
+
is_flag=True)
|
|
507
|
+
@click.option('--ignite',
|
|
508
|
+
help=('This flag allows running ignite executor if available. Please, note ' +
|
|
509
|
+
'that ignite executor is being deprecated and may not be available in your ' +
|
|
510
|
+
'CloudOS.'),
|
|
511
|
+
is_flag=True)
|
|
512
|
+
@click.option('--instance-type',
|
|
513
|
+
help=('The type of execution platform compute instance to use. ' +
|
|
514
|
+
'Default=c5.xlarge(aws)|Standard_D4as_v4(azure).'),
|
|
515
|
+
default='NONE_SELECTED')
|
|
516
|
+
@click.option('--instance-disk',
|
|
517
|
+
help='The amount of disk storage to configure. Default=500.',
|
|
518
|
+
type=int,
|
|
519
|
+
default=500)
|
|
520
|
+
@click.option('--storage-mode',
|
|
521
|
+
help=('Either \'lustre\' or \'regular\'. Indicates if the user wants to select ' +
|
|
522
|
+
'regular or lustre storage. Default=regular.'),
|
|
523
|
+
default='regular')
|
|
524
|
+
@click.option('--lustre-size',
|
|
525
|
+
help=('The lustre storage to be used when --storage-mode=lustre, in GB. It should ' +
|
|
526
|
+
'be 1200 or a multiple of it. Default=1200.'),
|
|
527
|
+
type=int,
|
|
528
|
+
default=1200)
|
|
529
|
+
@click.option('--execution-platform',
|
|
530
|
+
help='Name of the execution platform implemented in your CloudOS. Default=aws.',
|
|
531
|
+
type=click.Choice(['aws', 'azure']),
|
|
532
|
+
default='aws')
|
|
533
|
+
@click.option('--cost-limit',
|
|
534
|
+
help='Add a cost limit to your job. Default=30.0 (For no cost limit please use -1).',
|
|
535
|
+
type=float,
|
|
536
|
+
default=30.0)
|
|
537
|
+
@click.option('--accelerate-file-staging',
|
|
538
|
+
help='Enables AWS S3 mountpoint for quicker file staging.',
|
|
539
|
+
is_flag=True)
|
|
540
|
+
@click.option('--wait-completion',
|
|
541
|
+
help=('Whether to wait to job completion and report final ' +
|
|
542
|
+
'job status.'),
|
|
543
|
+
is_flag=True)
|
|
544
|
+
@click.option('--wait-time',
|
|
545
|
+
help=('Max time to wait (in seconds) to job completion. ' +
|
|
546
|
+
'Default=3600.'),
|
|
547
|
+
default=3600)
|
|
548
|
+
@click.option('--request-interval',
|
|
549
|
+
help=('Time interval to request (in seconds) the job status. ' +
|
|
550
|
+
'For large jobs is important to use a high number to ' +
|
|
551
|
+
'make fewer requests so that is not considered spamming by the API. ' +
|
|
552
|
+
'Default=30.'),
|
|
553
|
+
default=30)
|
|
554
|
+
@click.option('--verbose',
|
|
555
|
+
help='Whether to print information messages or not.',
|
|
556
|
+
is_flag=True)
|
|
557
|
+
@click.option('--disable-ssl-verification',
|
|
558
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
559
|
+
'not generally recommended for security reasons.'),
|
|
560
|
+
is_flag=True)
|
|
561
|
+
@click.option('--ssl-cert',
|
|
562
|
+
help='Path to your SSL certificate file.')
|
|
563
|
+
def run_curated_examples(apikey,
|
|
564
|
+
cloudos_url,
|
|
565
|
+
workspace_id,
|
|
566
|
+
project_name,
|
|
567
|
+
resumable,
|
|
568
|
+
do_not_save_logs,
|
|
569
|
+
spot,
|
|
570
|
+
batch,
|
|
571
|
+
ignite,
|
|
572
|
+
instance_type,
|
|
573
|
+
instance_disk,
|
|
574
|
+
storage_mode,
|
|
575
|
+
lustre_size,
|
|
576
|
+
execution_platform,
|
|
577
|
+
cost_limit,
|
|
578
|
+
accelerate_file_staging,
|
|
579
|
+
wait_completion,
|
|
580
|
+
wait_time,
|
|
581
|
+
request_interval,
|
|
582
|
+
verbose,
|
|
583
|
+
disable_ssl_verification,
|
|
584
|
+
ssl_cert):
|
|
585
|
+
"""Run all the curated workflows with example parameters.
|
|
586
|
+
|
|
587
|
+
NOTE that currently, only Nextflow workflows are supported.
|
|
588
|
+
"""
|
|
589
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
590
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
591
|
+
cl = Cloudos(cloudos_url, apikey, None)
|
|
592
|
+
curated_workflows = cl.get_curated_workflow_list(workspace_id, verify=verify_ssl)
|
|
593
|
+
job_id_list = []
|
|
594
|
+
runnable_curated_workflows = [
|
|
595
|
+
w for w in curated_workflows if w['workflowType'] == 'nextflow' and len(w['parameters']) > 0
|
|
596
|
+
]
|
|
597
|
+
if spot:
|
|
598
|
+
print('\n[Message] You have specified spot instances but they are no longer available ' +
|
|
599
|
+
'in CloudOS. Option ignored.\n')
|
|
600
|
+
if do_not_save_logs:
|
|
601
|
+
save_logs = False
|
|
602
|
+
else:
|
|
603
|
+
save_logs = True
|
|
604
|
+
if instance_type == 'NONE_SELECTED':
|
|
605
|
+
if execution_platform == 'aws':
|
|
606
|
+
instance_type = 'c5.xlarge'
|
|
607
|
+
if execution_platform == 'azure':
|
|
608
|
+
instance_type = 'Standard_D4as_v4'
|
|
609
|
+
if execution_platform == 'azure':
|
|
610
|
+
batch = None
|
|
611
|
+
elif ignite:
|
|
612
|
+
batch = None
|
|
613
|
+
print('\n[Warning] You have specified ignite executor. Please, note that ignite is being ' +
|
|
614
|
+
'removed from CloudOS, so the command may fail. Check ignite availability in your ' +
|
|
615
|
+
'CloudOS\n')
|
|
616
|
+
else:
|
|
617
|
+
batch = True
|
|
618
|
+
if accelerate_file_staging:
|
|
619
|
+
if execution_platform != 'aws':
|
|
620
|
+
print('[Message] You have selected accelerate file staging, but this function is ' +
|
|
621
|
+
'only available when execution platform is AWS. The accelerate file staging ' +
|
|
622
|
+
'will not be applied')
|
|
623
|
+
use_mountpoints = False
|
|
624
|
+
else:
|
|
625
|
+
use_mountpoints = True
|
|
626
|
+
print('[Message] Enabling AWS S3 mountpoint for accelerated file staging. ' +
|
|
627
|
+
'Please, take into consideration the following:\n' +
|
|
628
|
+
'\t- It significantly reduces runtime and compute costs but may increase network costs.\n' +
|
|
629
|
+
'\t- Requires extra memory. Adjust process memory or optimise resource usage if necessary.\n' +
|
|
630
|
+
'\t- This is still a CloudOS BETA feature.\n')
|
|
631
|
+
else:
|
|
632
|
+
use_mountpoints = False
|
|
633
|
+
for workflow in runnable_curated_workflows:
|
|
634
|
+
workflow_name = workflow['name']
|
|
635
|
+
j = jb.Job(cloudos_url, apikey, None, workspace_id, project_name, workflow_name,
|
|
636
|
+
repository_platform=workflow['repository']['platform'], verify=verify_ssl)
|
|
637
|
+
j_id = j.send_job(example_parameters=workflow['parameters'],
|
|
638
|
+
job_name=f"{workflow['name']}|Example_Run",
|
|
639
|
+
resumable=resumable,
|
|
640
|
+
save_logs=save_logs,
|
|
641
|
+
batch=batch,
|
|
642
|
+
instance_type=instance_type,
|
|
643
|
+
instance_disk=instance_disk,
|
|
644
|
+
storage_mode=storage_mode,
|
|
645
|
+
lustre_size=lustre_size,
|
|
646
|
+
execution_platform=execution_platform,
|
|
647
|
+
workflow_type='nextflow',
|
|
648
|
+
cost_limit=cost_limit,
|
|
649
|
+
use_mountpoints=use_mountpoints,
|
|
650
|
+
verify=verify_ssl)
|
|
651
|
+
print(f'\tYour assigned job id is: {j_id}\n')
|
|
652
|
+
job_id_list.append(j_id)
|
|
653
|
+
print(f'\n\tAll {len(runnable_curated_workflows)} curated job launched successfully!\n')
|
|
654
|
+
if wait_completion:
|
|
655
|
+
print('\tPlease, wait until jobs completion (max wait time of ' +
|
|
656
|
+
f'{wait_time} seconds).\n')
|
|
657
|
+
# Multi-threaded api requests, max_workers is hard-coded to not allow for
|
|
658
|
+
# big numbers that can collapse API server.
|
|
659
|
+
threads = []
|
|
660
|
+
with ThreadPoolExecutor(max_workers=20) as executor:
|
|
661
|
+
for j in job_id_list:
|
|
662
|
+
threads.append(executor.submit(cl.wait_job_completion,
|
|
663
|
+
job_id=j,
|
|
664
|
+
wait_time=wait_time,
|
|
665
|
+
request_interval=request_interval,
|
|
666
|
+
verbose=verbose,
|
|
667
|
+
verify=verify_ssl)
|
|
668
|
+
)
|
|
669
|
+
j_status_all = [task.result() for task in as_completed(threads)]
|
|
670
|
+
# Summary of job status
|
|
671
|
+
print("\n\tCurated example runs final status:\n")
|
|
672
|
+
for j_s in j_status_all:
|
|
673
|
+
j_name = j_s['name']
|
|
674
|
+
j_id = j_s['id']
|
|
675
|
+
j_status = j_s['status']
|
|
676
|
+
print(f'\t\tJob status for job "{j_name}" (ID: {j_id}): {j_status}')
|
|
677
|
+
successful_jobs = [j_s for j_s in j_status_all if j_s['status'] == JOB_COMPLETED]
|
|
678
|
+
failed_jobs = [j_s for j_s in j_status_all if j_s['status'] == JOB_FAILED]
|
|
679
|
+
aborted_jobs = [j_s for j_s in j_status_all if j_s['status'] == JOB_ABORTED]
|
|
680
|
+
running_jobs = [j_s for j_s in j_status_all if j_s['status'] == JOB_RUNNING]
|
|
681
|
+
print(f"""\n\tJob summary:
|
|
682
|
+
Successful jobs.....: {len(successful_jobs)}
|
|
683
|
+
Failed jobs.........: {len(failed_jobs)}
|
|
684
|
+
Jobs still running..: {len(running_jobs)}
|
|
685
|
+
Aborted jobs........: {len(aborted_jobs)}
|
|
686
|
+
-------------------------------
|
|
687
|
+
Total jobs..........: {len(j_status_all)}""")
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
@job.command('status')
|
|
691
|
+
@click.option('-k',
|
|
692
|
+
'--apikey',
|
|
693
|
+
help='Your CloudOS API key',
|
|
694
|
+
required=True)
|
|
695
|
+
@click.option('-c',
|
|
696
|
+
'--cloudos-url',
|
|
697
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
698
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
699
|
+
default='https://cloudos.lifebit.ai')
|
|
700
|
+
@click.option('--job-id',
|
|
701
|
+
help='The job id in CloudOS to search for.',
|
|
702
|
+
required=True)
|
|
703
|
+
@click.option('--verbose',
|
|
704
|
+
help='Whether to print information messages or not.',
|
|
705
|
+
is_flag=True)
|
|
706
|
+
@click.option('--disable-ssl-verification',
|
|
707
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
708
|
+
'not generally recommended for security reasons.'),
|
|
709
|
+
is_flag=True)
|
|
710
|
+
@click.option('--ssl-cert',
|
|
711
|
+
help='Path to your SSL certificate file.')
|
|
712
|
+
def job_status(apikey,
|
|
713
|
+
cloudos_url,
|
|
714
|
+
job_id,
|
|
715
|
+
verbose,
|
|
716
|
+
disable_ssl_verification,
|
|
717
|
+
ssl_cert):
|
|
718
|
+
"""Check job status in CloudOS."""
|
|
719
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
720
|
+
print('Executing status...')
|
|
721
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
722
|
+
if verbose:
|
|
723
|
+
print('\t...Preparing objects')
|
|
724
|
+
cl = Cloudos(cloudos_url, apikey, None)
|
|
725
|
+
if verbose:
|
|
726
|
+
print('\tThe following Cloudos object was created:')
|
|
727
|
+
print('\t' + str(cl) + '\n')
|
|
728
|
+
print(f'\tSearching for job id: {job_id}')
|
|
729
|
+
j_status = cl.get_job_status(job_id, verify_ssl)
|
|
730
|
+
j_status_h = json.loads(j_status.content)["status"]
|
|
731
|
+
print(f'\tYour current job status is: {j_status_h}\n')
|
|
732
|
+
j_url = f'{cloudos_url}/app/jobs/{job_id}'
|
|
733
|
+
print(f'\tTo further check your job status you can either go to {j_url} ' +
|
|
734
|
+
'or repeat the command you just used.')
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
@job.command('list')
|
|
738
|
+
@click.option('-k',
|
|
739
|
+
'--apikey',
|
|
740
|
+
help='Your CloudOS API key',
|
|
741
|
+
required=True)
|
|
742
|
+
@click.option('-c',
|
|
743
|
+
'--cloudos-url',
|
|
744
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
745
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
746
|
+
default='https://cloudos.lifebit.ai')
|
|
747
|
+
@click.option('--workspace-id',
|
|
748
|
+
help='The specific CloudOS workspace id.',
|
|
749
|
+
required=True)
|
|
750
|
+
@click.option('--output-basename',
|
|
751
|
+
help=('Output file base name to save jobs list. ' +
|
|
752
|
+
'Default=joblist'),
|
|
753
|
+
default='joblist',
|
|
754
|
+
required=False)
|
|
755
|
+
@click.option('--output-format',
|
|
756
|
+
help='The desired file format (file extension) for the output. Default=csv.',
|
|
757
|
+
type=click.Choice(['csv', 'json'], case_sensitive=False),
|
|
758
|
+
default='csv')
|
|
759
|
+
@click.option('--all-fields',
|
|
760
|
+
help=('Whether to collect all available fields from jobs or ' +
|
|
761
|
+
'just the preconfigured selected fields. Only applicable ' +
|
|
762
|
+
'when --output-format=csv'),
|
|
763
|
+
is_flag=True)
|
|
764
|
+
@click.option('--last-n-jobs',
|
|
765
|
+
help=("The number of last user's jobs to retrieve. You can use 'all' to " +
|
|
766
|
+
"retrieve all user's jobs. Default=30."),
|
|
767
|
+
default='30')
|
|
768
|
+
@click.option('--page',
|
|
769
|
+
help=('Response page to retrieve. If --last-n-jobs is set, then --page ' +
|
|
770
|
+
'value corresponds to the first page to retrieve. Default=1.'),
|
|
771
|
+
type=int,
|
|
772
|
+
default=1)
|
|
773
|
+
@click.option('--archived',
|
|
774
|
+
help=('When this flag is used, only archived jobs list is collected.'),
|
|
775
|
+
is_flag=True)
|
|
776
|
+
@click.option('--verbose',
|
|
777
|
+
help='Whether to print information messages or not.',
|
|
778
|
+
is_flag=True)
|
|
779
|
+
@click.option('--disable-ssl-verification',
|
|
780
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
781
|
+
'not generally recommended for security reasons.'),
|
|
782
|
+
is_flag=True)
|
|
783
|
+
@click.option('--ssl-cert',
|
|
784
|
+
help='Path to your SSL certificate file.')
|
|
785
|
+
def list_jobs(apikey,
|
|
786
|
+
cloudos_url,
|
|
787
|
+
workspace_id,
|
|
788
|
+
output_basename,
|
|
789
|
+
output_format,
|
|
790
|
+
all_fields,
|
|
791
|
+
last_n_jobs,
|
|
792
|
+
page,
|
|
793
|
+
archived,
|
|
794
|
+
verbose,
|
|
795
|
+
disable_ssl_verification,
|
|
796
|
+
ssl_cert):
|
|
797
|
+
"""Collect all your jobs from a CloudOS workspace in CSV format."""
|
|
798
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
799
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
800
|
+
outfile = output_basename + '.' + output_format
|
|
801
|
+
print('Executing list...')
|
|
802
|
+
if verbose:
|
|
803
|
+
print('\t...Preparing objects')
|
|
804
|
+
cl = Cloudos(cloudos_url, apikey, None)
|
|
805
|
+
if verbose:
|
|
806
|
+
print('\tThe following Cloudos object was created:')
|
|
807
|
+
print('\t' + str(cl) + '\n')
|
|
808
|
+
print('\tSearching for jobs in the following workspace: ' +
|
|
809
|
+
f'{workspace_id}')
|
|
810
|
+
if last_n_jobs != 'all':
|
|
811
|
+
try:
|
|
812
|
+
last_n_jobs = int(last_n_jobs)
|
|
813
|
+
except ValueError:
|
|
814
|
+
print("[ERROR] last-n-jobs value was not valid. Please use a positive int or 'all'")
|
|
815
|
+
raise
|
|
816
|
+
my_jobs_r = cl.get_job_list(workspace_id, last_n_jobs, page, archived, verify_ssl)
|
|
817
|
+
if output_format == 'csv':
|
|
818
|
+
my_jobs = cl.process_job_list(my_jobs_r, all_fields)
|
|
819
|
+
my_jobs.to_csv(outfile, index=False)
|
|
820
|
+
print(f'\tJob list collected with a total of {my_jobs.shape[0]} jobs.')
|
|
821
|
+
elif output_format == 'json':
|
|
822
|
+
with open(outfile, 'w') as o:
|
|
823
|
+
o.write(json.dumps(my_jobs_r))
|
|
824
|
+
print(f'\tJob list collected with a total of {len(my_jobs_r)} jobs.')
|
|
825
|
+
else:
|
|
826
|
+
raise ValueError('Unrecognised output format. Please use one of [csv|json]')
|
|
827
|
+
print(f'\tJob list saved to {outfile}')
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
@workflow.command('list')
|
|
831
|
+
@click.option('-k',
|
|
832
|
+
'--apikey',
|
|
833
|
+
help='Your CloudOS API key',
|
|
834
|
+
required=True)
|
|
835
|
+
@click.option('-c',
|
|
836
|
+
'--cloudos-url',
|
|
837
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
838
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
839
|
+
default='https://cloudos.lifebit.ai')
|
|
840
|
+
@click.option('--workspace-id',
|
|
841
|
+
help='The specific CloudOS workspace id.',
|
|
842
|
+
required=True)
|
|
843
|
+
@click.option('--output-basename',
|
|
844
|
+
help=('Output file base name to save workflow list. ' +
|
|
845
|
+
'Default=workflow_list'),
|
|
846
|
+
default='workflow_list',
|
|
847
|
+
required=False)
|
|
848
|
+
@click.option('--output-format',
|
|
849
|
+
help='The desired file format (file extension) for the output. Default=csv.',
|
|
850
|
+
type=click.Choice(['csv', 'json'], case_sensitive=False),
|
|
851
|
+
default='csv')
|
|
852
|
+
@click.option('--all-fields',
|
|
853
|
+
help=('Whether to collect all available fields from workflows or ' +
|
|
854
|
+
'just the preconfigured selected fields. Only applicable ' +
|
|
855
|
+
'when --output-format=csv'),
|
|
856
|
+
is_flag=True)
|
|
857
|
+
@click.option('--curated',
|
|
858
|
+
help='Whether to collect curated workflows only.',
|
|
859
|
+
is_flag=True)
|
|
860
|
+
@click.option('--verbose',
|
|
861
|
+
help='Whether to print information messages or not.',
|
|
862
|
+
is_flag=True)
|
|
863
|
+
@click.option('--disable-ssl-verification',
|
|
864
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
865
|
+
'not generally recommended for security reasons.'),
|
|
866
|
+
is_flag=True)
|
|
867
|
+
@click.option('--ssl-cert',
|
|
868
|
+
help='Path to your SSL certificate file.')
|
|
869
|
+
def list_workflows(apikey,
|
|
870
|
+
cloudos_url,
|
|
871
|
+
workspace_id,
|
|
872
|
+
output_basename,
|
|
873
|
+
output_format,
|
|
874
|
+
all_fields,
|
|
875
|
+
curated,
|
|
876
|
+
verbose,
|
|
877
|
+
disable_ssl_verification,
|
|
878
|
+
ssl_cert):
|
|
879
|
+
"""Collect all workflows from a CloudOS workspace in CSV format."""
|
|
880
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
881
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
882
|
+
outfile = output_basename + '.' + output_format
|
|
883
|
+
print('Executing list...')
|
|
884
|
+
if verbose:
|
|
885
|
+
print('\t...Preparing objects')
|
|
886
|
+
cl = Cloudos(cloudos_url, apikey, None)
|
|
887
|
+
if verbose:
|
|
888
|
+
print('\tThe following Cloudos object was created:')
|
|
889
|
+
print('\t' + str(cl) + '\n')
|
|
890
|
+
print('\tSearching for workflows in the following workspace: ' +
|
|
891
|
+
f'{workspace_id}')
|
|
892
|
+
if curated:
|
|
893
|
+
my_workflows_r = cl.get_curated_workflow_list(workspace_id, verify=verify_ssl)
|
|
894
|
+
else:
|
|
895
|
+
my_workflows_r = cl.get_workflow_list(workspace_id, verify=verify_ssl)
|
|
896
|
+
if output_format == 'csv':
|
|
897
|
+
my_workflows = cl.process_workflow_list(my_workflows_r, all_fields)
|
|
898
|
+
my_workflows.to_csv(outfile, index=False)
|
|
899
|
+
print(f'\tWorkflow list collected with a total of {my_workflows.shape[0]} workflows.')
|
|
900
|
+
elif output_format == 'json':
|
|
901
|
+
with open(outfile, 'w') as o:
|
|
902
|
+
o.write(json.dumps(my_workflows_r))
|
|
903
|
+
print(f'\tWorkflow list collected with a total of {len(my_workflows_r)} workflows.')
|
|
904
|
+
else:
|
|
905
|
+
raise ValueError('Unrecognised output format. Please use one of [csv|json]')
|
|
906
|
+
print(f'\tWorkflow list saved to {outfile}')
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
@workflow.command('import')
|
|
910
|
+
@click.option('-k',
|
|
911
|
+
'--apikey',
|
|
912
|
+
help='Your CloudOS API key',
|
|
913
|
+
required=True)
|
|
914
|
+
@click.option('-c',
|
|
915
|
+
'--cloudos-url',
|
|
916
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
917
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
918
|
+
default='https://cloudos.lifebit.ai')
|
|
919
|
+
@click.option('--workspace-id',
|
|
920
|
+
help='The specific CloudOS workspace id.',
|
|
921
|
+
required=True)
|
|
922
|
+
@click.option('--workflow-url',
|
|
923
|
+
help=('URL of the workflow to import. Please, note that it should ' +
|
|
924
|
+
'be the URL shown in the browser, and it should come without ' +
|
|
925
|
+
'any of the .git or /browse extensions.'),
|
|
926
|
+
required=True)
|
|
927
|
+
@click.option('--workflow-name',
|
|
928
|
+
help="The name that the workflow will have in CloudOS",
|
|
929
|
+
required=True)
|
|
930
|
+
@click.option('--workflow-docs-link',
|
|
931
|
+
help="Workflow documentation URL.",
|
|
932
|
+
default='')
|
|
933
|
+
@click.option('--repository-project-id',
|
|
934
|
+
type=int,
|
|
935
|
+
help="The ID of your repository project",
|
|
936
|
+
required=True)
|
|
937
|
+
@click.option('--repository-id',
|
|
938
|
+
type=int,
|
|
939
|
+
help="The ID of your repository. Only required for GitHub repositories")
|
|
940
|
+
@click.option('--disable-ssl-verification',
|
|
941
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
942
|
+
'not generally recommended for security reasons.'),
|
|
943
|
+
is_flag=True)
|
|
944
|
+
@click.option('--ssl-cert',
|
|
945
|
+
help='Path to your SSL certificate file.')
|
|
946
|
+
def import_workflows(apikey,
|
|
947
|
+
cloudos_url,
|
|
948
|
+
workspace_id,
|
|
949
|
+
workflow_url,
|
|
950
|
+
workflow_name,
|
|
951
|
+
repository_project_id,
|
|
952
|
+
workflow_docs_link,
|
|
953
|
+
repository_id,
|
|
954
|
+
disable_ssl_verification,
|
|
955
|
+
ssl_cert):
|
|
956
|
+
"""Imports workflows to CloudOS."""
|
|
957
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
958
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
959
|
+
print('Executing workflow import...\n')
|
|
960
|
+
print('\t[Message] Only Nextflow workflows are currently supported.\n')
|
|
961
|
+
cl = Cloudos(cloudos_url, apikey, None)
|
|
962
|
+
workflow_id = cl.workflow_import(workspace_id,
|
|
963
|
+
workflow_url,
|
|
964
|
+
workflow_name,
|
|
965
|
+
repository_project_id,
|
|
966
|
+
workflow_docs_link,
|
|
967
|
+
repository_id,
|
|
968
|
+
verify=verify_ssl)
|
|
969
|
+
print(f'\tWorkflow {workflow_name} was imported successfully with the ' +
|
|
970
|
+
f'following ID: {workflow_id}')
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
@project.command('list')
|
|
974
|
+
@click.option('-k',
|
|
975
|
+
'--apikey',
|
|
976
|
+
help='Your CloudOS API key',
|
|
977
|
+
required=True)
|
|
978
|
+
@click.option('-c',
|
|
979
|
+
'--cloudos-url',
|
|
980
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
981
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
982
|
+
default='https://cloudos.lifebit.ai')
|
|
983
|
+
@click.option('--workspace-id',
|
|
984
|
+
help='The specific CloudOS workspace id.',
|
|
985
|
+
required=True)
|
|
986
|
+
@click.option('--output-basename',
|
|
987
|
+
help=('Output file base name to save project list. ' +
|
|
988
|
+
'Default=project_list'),
|
|
989
|
+
default='project_list',
|
|
990
|
+
required=False)
|
|
991
|
+
@click.option('--output-format',
|
|
992
|
+
help='The desired file format (file extension) for the output. Default=csv.',
|
|
993
|
+
type=click.Choice(['csv', 'json'], case_sensitive=False),
|
|
994
|
+
default='csv')
|
|
995
|
+
@click.option('--all-fields',
|
|
996
|
+
help=('Whether to collect all available fields from projects or ' +
|
|
997
|
+
'just the preconfigured selected fields. Only applicable ' +
|
|
998
|
+
'when --output-format=csv'),
|
|
999
|
+
is_flag=True)
|
|
1000
|
+
@click.option('--verbose',
|
|
1001
|
+
help='Whether to print information messages or not.',
|
|
1002
|
+
is_flag=True)
|
|
1003
|
+
@click.option('--disable-ssl-verification',
|
|
1004
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
1005
|
+
'not generally recommended for security reasons.'),
|
|
1006
|
+
is_flag=True)
|
|
1007
|
+
@click.option('--ssl-cert',
|
|
1008
|
+
help='Path to your SSL certificate file.')
|
|
1009
|
+
def list_projects(apikey,
|
|
1010
|
+
cloudos_url,
|
|
1011
|
+
workspace_id,
|
|
1012
|
+
output_basename,
|
|
1013
|
+
output_format,
|
|
1014
|
+
all_fields,
|
|
1015
|
+
verbose,
|
|
1016
|
+
disable_ssl_verification,
|
|
1017
|
+
ssl_cert):
|
|
1018
|
+
"""Collect all projects from a CloudOS workspace in CSV format."""
|
|
1019
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
1020
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
1021
|
+
outfile = output_basename + '.' + output_format
|
|
1022
|
+
print('Executing list...')
|
|
1023
|
+
if verbose:
|
|
1024
|
+
print('\t...Preparing objects')
|
|
1025
|
+
cl = Cloudos(cloudos_url, apikey, None)
|
|
1026
|
+
if verbose:
|
|
1027
|
+
print('\tThe following Cloudos object was created:')
|
|
1028
|
+
print('\t' + str(cl) + '\n')
|
|
1029
|
+
print('\tSearching for projects in the following workspace: ' +
|
|
1030
|
+
f'{workspace_id}')
|
|
1031
|
+
my_projects_r = cl.get_project_list(workspace_id, verify_ssl)
|
|
1032
|
+
if output_format == 'csv':
|
|
1033
|
+
my_projects = cl.process_project_list(my_projects_r, all_fields)
|
|
1034
|
+
my_projects.to_csv(outfile, index=False)
|
|
1035
|
+
print(f'\tProject list collected with a total of {my_projects.shape[0]} projects.')
|
|
1036
|
+
elif output_format == 'json':
|
|
1037
|
+
with open(outfile, 'w') as o:
|
|
1038
|
+
o.write(my_projects_r.text)
|
|
1039
|
+
content = json.loads(my_projects_r.content)
|
|
1040
|
+
if 'projects' in content:
|
|
1041
|
+
content_l = len(content['projects'])
|
|
1042
|
+
else:
|
|
1043
|
+
content_l = len(content)
|
|
1044
|
+
print('\tProject list collected with a total of ' +
|
|
1045
|
+
f'{content_l} projects.')
|
|
1046
|
+
else:
|
|
1047
|
+
raise ValueError('Unrecognised output format. Please use one of [csv|json]')
|
|
1048
|
+
print(f'\tProject list saved to {outfile}')
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
@cromwell.command('status')
|
|
1052
|
+
@click.version_option()
|
|
1053
|
+
@click.option('-k',
|
|
1054
|
+
'--apikey',
|
|
1055
|
+
help='Your CloudOS API key.')
|
|
1056
|
+
@click.option('-t',
|
|
1057
|
+
'--cromwell-token',
|
|
1058
|
+
help=('Specific Cromwell server authentication token. You can use it instead of ' +
|
|
1059
|
+
'the apikey.'))
|
|
1060
|
+
@click.option('-c',
|
|
1061
|
+
'--cloudos-url',
|
|
1062
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
1063
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
1064
|
+
default='https://cloudos.lifebit.ai')
|
|
1065
|
+
@click.option('--workspace-id',
|
|
1066
|
+
help='The specific CloudOS workspace id.',
|
|
1067
|
+
required=True)
|
|
1068
|
+
@click.option('--verbose',
|
|
1069
|
+
help='Whether to print information messages or not.',
|
|
1070
|
+
is_flag=True)
|
|
1071
|
+
@click.option('--disable-ssl-verification',
|
|
1072
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
1073
|
+
'not generally recommended for security reasons.'),
|
|
1074
|
+
is_flag=True)
|
|
1075
|
+
@click.option('--ssl-cert',
|
|
1076
|
+
help='Path to your SSL certificate file.')
|
|
1077
|
+
def cromwell_status(apikey,
|
|
1078
|
+
cromwell_token,
|
|
1079
|
+
cloudos_url,
|
|
1080
|
+
workspace_id,
|
|
1081
|
+
verbose,
|
|
1082
|
+
disable_ssl_verification,
|
|
1083
|
+
ssl_cert):
|
|
1084
|
+
"""Check Cromwell server status in CloudOS."""
|
|
1085
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
1086
|
+
if apikey is None and cromwell_token is None:
|
|
1087
|
+
raise ValueError("Please, use one of the following tokens: '--apikey', '--cromwell_token'")
|
|
1088
|
+
print('Executing status...')
|
|
1089
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
1090
|
+
if verbose:
|
|
1091
|
+
print('\t...Preparing objects')
|
|
1092
|
+
cl = Cloudos(cloudos_url, apikey, cromwell_token)
|
|
1093
|
+
if verbose:
|
|
1094
|
+
print('\tThe following Cloudos object was created:')
|
|
1095
|
+
print('\t' + str(cl) + '\n')
|
|
1096
|
+
print(f'\tChecking Cromwell status in {workspace_id} workspace')
|
|
1097
|
+
c_status = cl.get_cromwell_status(workspace_id, verify_ssl)
|
|
1098
|
+
c_status_h = json.loads(c_status.content)["status"]
|
|
1099
|
+
print(f'\tCurrent Cromwell server status is: {c_status_h}\n')
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
@cromwell.command('start')
|
|
1103
|
+
@click.version_option()
|
|
1104
|
+
@click.option('-k',
|
|
1105
|
+
'--apikey',
|
|
1106
|
+
help='Your CloudOS API key.')
|
|
1107
|
+
@click.option('-t',
|
|
1108
|
+
'--cromwell-token',
|
|
1109
|
+
help=('Specific Cromwell server authentication token. You can use it instead of ' +
|
|
1110
|
+
'the apikey.'))
|
|
1111
|
+
@click.option('-c',
|
|
1112
|
+
'--cloudos-url',
|
|
1113
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
1114
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
1115
|
+
default='https://cloudos.lifebit.ai')
|
|
1116
|
+
@click.option('--workspace-id',
|
|
1117
|
+
help='The specific CloudOS workspace id.',
|
|
1118
|
+
required=True)
|
|
1119
|
+
@click.option('--wait-time',
|
|
1120
|
+
help=('Max time to wait (in seconds) to Cromwell restart. ' +
|
|
1121
|
+
'Default=300.'),
|
|
1122
|
+
default=300)
|
|
1123
|
+
@click.option('--verbose',
|
|
1124
|
+
help='Whether to print information messages or not.',
|
|
1125
|
+
is_flag=True)
|
|
1126
|
+
@click.option('--disable-ssl-verification',
|
|
1127
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
1128
|
+
'not generally recommended for security reasons.'),
|
|
1129
|
+
is_flag=True)
|
|
1130
|
+
@click.option('--ssl-cert',
|
|
1131
|
+
help='Path to your SSL certificate file.')
|
|
1132
|
+
def cromwell_restart(apikey,
|
|
1133
|
+
cromwell_token,
|
|
1134
|
+
cloudos_url,
|
|
1135
|
+
workspace_id,
|
|
1136
|
+
wait_time,
|
|
1137
|
+
verbose,
|
|
1138
|
+
disable_ssl_verification,
|
|
1139
|
+
ssl_cert):
|
|
1140
|
+
"""Restart Cromwell server in CloudOS."""
|
|
1141
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
1142
|
+
if apikey is None and cromwell_token is None:
|
|
1143
|
+
raise ValueError("Please, use one of the following tokens: '--apikey', '--cromwell_token'")
|
|
1144
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
1145
|
+
action = 'restart'
|
|
1146
|
+
print('Starting Cromwell server...')
|
|
1147
|
+
if verbose:
|
|
1148
|
+
print('\t...Preparing objects')
|
|
1149
|
+
cl = Cloudos(cloudos_url, apikey, cromwell_token)
|
|
1150
|
+
if verbose:
|
|
1151
|
+
print('\tThe following Cloudos object was created:')
|
|
1152
|
+
print('\t' + str(cl) + '\n')
|
|
1153
|
+
print(f'\tStarting Cromwell server in {workspace_id} workspace')
|
|
1154
|
+
cl.cromwell_switch(workspace_id, action, verify_ssl)
|
|
1155
|
+
c_status = cl.get_cromwell_status(workspace_id, verify_ssl)
|
|
1156
|
+
c_status_h = json.loads(c_status.content)["status"]
|
|
1157
|
+
print(f'\tCurrent Cromwell server status is: {c_status_h}\n')
|
|
1158
|
+
elapsed = 0
|
|
1159
|
+
while elapsed < wait_time and c_status_h != 'Running':
|
|
1160
|
+
c_status_old = c_status_h
|
|
1161
|
+
time.sleep(REQUEST_INTERVAL_CROMWELL)
|
|
1162
|
+
elapsed += REQUEST_INTERVAL_CROMWELL
|
|
1163
|
+
c_status = cl.get_cromwell_status(workspace_id, verify_ssl)
|
|
1164
|
+
c_status_h = json.loads(c_status.content)["status"]
|
|
1165
|
+
if c_status_h != c_status_old:
|
|
1166
|
+
print(f'\tCurrent Cromwell server status is: {c_status_h}\n')
|
|
1167
|
+
if c_status_h != 'Running':
|
|
1168
|
+
print(f'\tYour current Cromwell status is: {c_status_h}. The ' +
|
|
1169
|
+
f'selected wait-time of {wait_time} was exceeded. Please, ' +
|
|
1170
|
+
'consider to set a longer wait-time.')
|
|
1171
|
+
print('\tTo further check your Cromwell status you can either go to ' +
|
|
1172
|
+
f'{cloudos_url} or use the following command:\n' +
|
|
1173
|
+
'\tcloudos cromwell status \\\n' +
|
|
1174
|
+
f'\t\t--cloudos-url {cloudos_url} \\\n' +
|
|
1175
|
+
'\t\t--cromwell-token $CROMWELL_TOKEN \\\n' +
|
|
1176
|
+
f'\t\t--workspace-id {workspace_id}')
|
|
1177
|
+
sys.exit(1)
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
@cromwell.command('stop')
|
|
1181
|
+
@click.version_option()
|
|
1182
|
+
@click.option('-k',
|
|
1183
|
+
'--apikey',
|
|
1184
|
+
help='Your CloudOS API key.')
|
|
1185
|
+
@click.option('-t',
|
|
1186
|
+
'--cromwell-token',
|
|
1187
|
+
help=('Specific Cromwell server authentication token. You can use it instead of ' +
|
|
1188
|
+
'the apikey.'))
|
|
1189
|
+
@click.option('-c',
|
|
1190
|
+
'--cloudos-url',
|
|
1191
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
1192
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
1193
|
+
default='https://cloudos.lifebit.ai')
|
|
1194
|
+
@click.option('--workspace-id',
|
|
1195
|
+
help='The specific CloudOS workspace id.',
|
|
1196
|
+
required=True)
|
|
1197
|
+
@click.option('--verbose',
|
|
1198
|
+
help='Whether to print information messages or not.',
|
|
1199
|
+
is_flag=True)
|
|
1200
|
+
@click.option('--disable-ssl-verification',
|
|
1201
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
1202
|
+
'not generally recommended for security reasons.'),
|
|
1203
|
+
is_flag=True)
|
|
1204
|
+
@click.option('--ssl-cert',
|
|
1205
|
+
help='Path to your SSL certificate file.')
|
|
1206
|
+
def cromwell_stop(apikey,
|
|
1207
|
+
cromwell_token,
|
|
1208
|
+
cloudos_url,
|
|
1209
|
+
workspace_id,
|
|
1210
|
+
verbose,
|
|
1211
|
+
disable_ssl_verification,
|
|
1212
|
+
ssl_cert):
|
|
1213
|
+
"""Stop Cromwell server in CloudOS."""
|
|
1214
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
1215
|
+
if apikey is None and cromwell_token is None:
|
|
1216
|
+
raise ValueError("Please, use one of the following tokens: '--apikey', '--cromwell_token'")
|
|
1217
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
1218
|
+
action = 'stop'
|
|
1219
|
+
print('Stopping Cromwell server...')
|
|
1220
|
+
if verbose:
|
|
1221
|
+
print('\t...Preparing objects')
|
|
1222
|
+
cl = Cloudos(cloudos_url, apikey, cromwell_token)
|
|
1223
|
+
if verbose:
|
|
1224
|
+
print('\tThe following Cloudos object was created:')
|
|
1225
|
+
print('\t' + str(cl) + '\n')
|
|
1226
|
+
print(f'\tStopping Cromwell server in {workspace_id} workspace')
|
|
1227
|
+
cl.cromwell_switch(workspace_id, action, verify_ssl)
|
|
1228
|
+
c_status = cl.get_cromwell_status(workspace_id, verify_ssl)
|
|
1229
|
+
c_status_h = json.loads(c_status.content)["status"]
|
|
1230
|
+
print(f'\tCurrent Cromwell server status is: {c_status_h}\n')
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
@queue.command('list')
|
|
1234
|
+
@click.option('-k',
|
|
1235
|
+
'--apikey',
|
|
1236
|
+
help='Your CloudOS API key',
|
|
1237
|
+
required=True)
|
|
1238
|
+
@click.option('-c',
|
|
1239
|
+
'--cloudos-url',
|
|
1240
|
+
help=('The CloudOS url you are trying to access to. ' +
|
|
1241
|
+
'Default=https://cloudos.lifebit.ai.'),
|
|
1242
|
+
default='https://cloudos.lifebit.ai')
|
|
1243
|
+
@click.option('--workspace-id',
|
|
1244
|
+
help='The specific CloudOS workspace id.',
|
|
1245
|
+
required=True)
|
|
1246
|
+
@click.option('--output-basename',
|
|
1247
|
+
help=('Output file base name to save job queue list. ' +
|
|
1248
|
+
'Default=job_queue_list'),
|
|
1249
|
+
default='job_queue_list',
|
|
1250
|
+
required=False)
|
|
1251
|
+
@click.option('--output-format',
|
|
1252
|
+
help='The desired file format (file extension) for the output. Default=csv.',
|
|
1253
|
+
type=click.Choice(['csv', 'json'], case_sensitive=False),
|
|
1254
|
+
default='csv')
|
|
1255
|
+
@click.option('--all-fields',
|
|
1256
|
+
help=('Whether to collect all available fields from workflows or ' +
|
|
1257
|
+
'just the preconfigured selected fields. Only applicable ' +
|
|
1258
|
+
'when --output-format=csv'),
|
|
1259
|
+
is_flag=True)
|
|
1260
|
+
@click.option('--disable-ssl-verification',
|
|
1261
|
+
help=('Disable SSL certificate verification. Please, remember that this option is ' +
|
|
1262
|
+
'not generally recommended for security reasons.'),
|
|
1263
|
+
is_flag=True)
|
|
1264
|
+
@click.option('--ssl-cert',
|
|
1265
|
+
help='Path to your SSL certificate file.')
|
|
1266
|
+
def list_queues(apikey,
|
|
1267
|
+
cloudos_url,
|
|
1268
|
+
workspace_id,
|
|
1269
|
+
output_basename,
|
|
1270
|
+
output_format,
|
|
1271
|
+
all_fields,
|
|
1272
|
+
disable_ssl_verification,
|
|
1273
|
+
ssl_cert):
|
|
1274
|
+
"""Collect all available job queues from a CloudOS workspace."""
|
|
1275
|
+
cloudos_url = cloudos_url.rstrip('/')
|
|
1276
|
+
verify_ssl = ssl_selector(disable_ssl_verification, ssl_cert)
|
|
1277
|
+
outfile = output_basename + '.' + output_format
|
|
1278
|
+
print('Executing list...')
|
|
1279
|
+
j_queue = Queue(cloudos_url, apikey, None, workspace_id, verify=verify_ssl)
|
|
1280
|
+
my_queues = j_queue.get_job_queues()
|
|
1281
|
+
if len(my_queues) == 0:
|
|
1282
|
+
raise ValueError('No AWS batch queues found. Please, make sure that your CloudOS supports AWS bath queues')
|
|
1283
|
+
if output_format == 'csv':
|
|
1284
|
+
queues_processed = j_queue.process_queue_list(my_queues, all_fields)
|
|
1285
|
+
queues_processed.to_csv(outfile, index=False)
|
|
1286
|
+
print(f'\tJob queue list collected with a total of {queues_processed.shape[0]} queues.')
|
|
1287
|
+
elif output_format == 'json':
|
|
1288
|
+
with open(outfile, 'w') as o:
|
|
1289
|
+
o.write(json.dumps(my_queues))
|
|
1290
|
+
print(f'\tJob queue list collected with a total of {len(my_queues)} queues.')
|
|
1291
|
+
else:
|
|
1292
|
+
raise ValueError('Unrecognised output format. Please use one of [csv|json]')
|
|
1293
|
+
print(f'\tJob queue list saved to {outfile}')
|
|
1294
|
+
|
|
1295
|
+
|
|
1296
|
+
if __name__ == "__main__":
|
|
1297
|
+
run_cloudos_cli()
|