Skip to content

Commit

Permalink
Merge e00e6b2 into d614bca
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego committed Feb 14, 2020
2 parents d614bca + e00e6b2 commit 513eef5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 31 deletions.
59 changes: 59 additions & 0 deletions reana_client/cli/utils.py
Expand Up @@ -160,3 +160,62 @@ def handle_parse_result(self, ctx, opts, args):

return super(NotRequiredIf, self).handle_parse_result(
ctx, opts, args)


def output_user_friendly_logs(workflow_logs, steps):
"""Output workflow logs in an user-friendly manner.
:param workflow_logs: Dictionary representing the workflow logs as they
are returned from the REST API.
:param steps: List of steps to show logs for.
"""
def _leading_mark(indent=1):
return '{}>'.format('='*indent)
# Colors matching the status colors of REANA-UI
status_to_color_mapping = {
'created': 'magenta',
'running': 'bright_blue',
'finished': 'green',
'failed': 'red',
'stopped': 'yellow',
'deleted': 'black',
'queued': 'bright_white',
}

# REANA Workflow Engine logs
if workflow_logs.get('workflow_logs', None):
click.secho('{} workflow engine logs'.format(_leading_mark()).upper())
click.echo(workflow_logs['workflow_logs'])

returned_step_names = \
set(workflow_logs['job_logs'][item]['job_name']
for item in workflow_logs['job_logs'].keys())
if steps:
missing_steps = set(steps).difference(returned_step_names)
if missing_steps:
click.echo(
click.style('The logs of step(s) {} were not found, '
'check for spelling mistakes in the step '
'names.'
.format(','.join(missing_steps)),
fg='red'))
# Job logs
if workflow_logs['job_logs']:
click.echo('\n')
click.secho('{} job logs'.format(_leading_mark()).upper())
for job_id, logs_info in workflow_logs['job_logs'].items():
if logs_info:
click.secho('{0} Step {1} (ID {2})'.format(
_leading_mark(indent=2), logs_info['job_name'], job_id),
fg=status_to_color_mapping[logs_info['status']], bold=True)
del(logs_info['job_name'])
for key, value in logs_info.items():
click.secho(
'{mark} {key}: {value}'.format(
mark=_leading_mark(indent=3),
key=key.upper().replace('_', ' '),
value=value))
if workflow_logs.get('engine_specific', None):
click.echo('\n')
click.secho('{} engine internal logs'.format(_leading_mark()).upper())
click.secho(workflow_logs['engine_specific'])
34 changes: 3 additions & 31 deletions reana_client/cli/workflow.py
Expand Up @@ -682,37 +682,9 @@ def workflow_logs(ctx, workflow, access_token, json_format,
if json_format:
click.echo(json.dumps(workflow_logs, indent=2))
sys.exit(0)

if workflow_logs.get('workflow_logs', None):
click.secho('workflow engine logs'.upper(), fg='green')
click.echo(workflow_logs['workflow_logs'])

first = True
returned_step_names = \
set(workflow_logs['job_logs'][item]['job_name']
for item in workflow_logs['job_logs'].keys())
if steps:
missing_steps = set(steps).difference(returned_step_names)
if missing_steps:
click.echo(
click.style('The logs of step(s) {} were not found, '
'check for spelling mistakes in the step '
'names.'
.format(','.join(missing_steps)),
fg='red'))
for job_id, job_logs in workflow_logs['job_logs'].items():
if job_logs:
if first:
click.echo('\n')
click.secho('job logs'.upper(), fg='green')
first = False
click.secho('job id: {}'.format(job_id), fg='green')
for key, value in job_logs.items():
click.echo('{}: {}'.format(key.upper(), value))
if workflow_logs.get('engine_specific', None):
click.echo('\n')
click.secho('engine internal logs'.upper(), fg='green')
click.secho(workflow_logs['engine_specific'])
else:
from reana_client.cli.utils import output_user_friendly_logs
output_user_friendly_logs(workflow_logs, steps)
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
Expand Down

0 comments on commit 513eef5

Please sign in to comment.